annotate packages/kernel/current/include/flag.hxx @ 208:e0c0827131d1 ecos

Merge from eCos master repository on 2002-05-20-20:11:54-BST
author jlarmour
date Mon, 20 May 2002 22:19:26 +0000
parents bf00f99aec69
children d2c90368aeef
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
1 #ifndef CYGONCE_KERNEL_FLAG_HXX
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
2 #define CYGONCE_KERNEL_FLAG_HXX
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
3
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
4 //==========================================================================
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
5 //
2
443894e2e912 Block commit of eCos version 1.2.1
jlarmour
parents: 0
diff changeset
6 // flag.hxx
0
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
7 //
2
443894e2e912 Block commit of eCos version 1.2.1
jlarmour
parents: 0
diff changeset
8 // Flag object class declarations
0
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
9 //
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
10 //==========================================================================
208
e0c0827131d1 Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents: 66
diff changeset
11 //####ECOSGPLCOPYRIGHTBEGIN####
e0c0827131d1 Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents: 66
diff changeset
12 // -------------------------------------------
e0c0827131d1 Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents: 66
diff changeset
13 // This file is part of eCos, the Embedded Configurable Operating System.
e0c0827131d1 Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents: 66
diff changeset
14 // Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
e0c0827131d1 Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents: 66
diff changeset
15 //
e0c0827131d1 Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents: 66
diff changeset
16 // eCos is free software; you can redistribute it and/or modify it under
e0c0827131d1 Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents: 66
diff changeset
17 // the terms of the GNU General Public License as published by the Free
e0c0827131d1 Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents: 66
diff changeset
18 // Software Foundation; either version 2 or (at your option) any later version.
e0c0827131d1 Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents: 66
diff changeset
19 //
e0c0827131d1 Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents: 66
diff changeset
20 // eCos is distributed in the hope that it will be useful, but WITHOUT ANY
e0c0827131d1 Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents: 66
diff changeset
21 // WARRANTY; without even the implied warranty of MERCHANTABILITY or
e0c0827131d1 Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents: 66
diff changeset
22 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
e0c0827131d1 Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents: 66
diff changeset
23 // for more details.
e0c0827131d1 Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents: 66
diff changeset
24 //
e0c0827131d1 Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents: 66
diff changeset
25 // You should have received a copy of the GNU General Public License along
e0c0827131d1 Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents: 66
diff changeset
26 // with eCos; if not, write to the Free Software Foundation, Inc.,
e0c0827131d1 Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents: 66
diff changeset
27 // 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
e0c0827131d1 Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents: 66
diff changeset
28 //
e0c0827131d1 Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents: 66
diff changeset
29 // As a special exception, if other files instantiate templates or use macros
e0c0827131d1 Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents: 66
diff changeset
30 // or inline functions from this file, or you compile this file and link it
e0c0827131d1 Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents: 66
diff changeset
31 // with other works to produce a work based on this file, this file does not
e0c0827131d1 Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents: 66
diff changeset
32 // by itself cause the resulting work to be covered by the GNU General Public
e0c0827131d1 Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents: 66
diff changeset
33 // License. However the source code for this file must still be made available
e0c0827131d1 Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents: 66
diff changeset
34 // in accordance with section (3) of the GNU General Public License.
e0c0827131d1 Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents: 66
diff changeset
35 //
e0c0827131d1 Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents: 66
diff changeset
36 // This exception does not invalidate any other reasons why a work based on
e0c0827131d1 Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents: 66
diff changeset
37 // this file might be covered by the GNU General Public License.
e0c0827131d1 Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents: 66
diff changeset
38 //
e0c0827131d1 Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents: 66
diff changeset
39 // Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
e0c0827131d1 Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents: 66
diff changeset
40 // at http://sources.redhat.com/ecos/ecos-license
e0c0827131d1 Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents: 66
diff changeset
41 // -------------------------------------------
e0c0827131d1 Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents: 66
diff changeset
42 //####ECOSGPLCOPYRIGHTEND####
0
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
43 //==========================================================================
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
44 //#####DESCRIPTIONBEGIN####
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
45 //
2
443894e2e912 Block commit of eCos version 1.2.1
jlarmour
parents: 0
diff changeset
46 // Author(s): hmt
443894e2e912 Block commit of eCos version 1.2.1
jlarmour
parents: 0
diff changeset
47 // Contributors: hmt
443894e2e912 Block commit of eCos version 1.2.1
jlarmour
parents: 0
diff changeset
48 // Date: 1998-02-10
443894e2e912 Block commit of eCos version 1.2.1
jlarmour
parents: 0
diff changeset
49 // Purpose: Define Flag class interfaces
443894e2e912 Block commit of eCos version 1.2.1
jlarmour
parents: 0
diff changeset
50 // Description: The classes defined here provide the APIs for flags.
443894e2e912 Block commit of eCos version 1.2.1
jlarmour
parents: 0
diff changeset
51 // Usage: #include <cyg/kernel/flag.hxx>
443894e2e912 Block commit of eCos version 1.2.1
jlarmour
parents: 0
diff changeset
52 //
0
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
53 //
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
54 //####DESCRIPTIONEND####
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
55 //
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
56 //==========================================================================
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
57
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
58 #include <cyg/kernel/ktypes.h>
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
59 #include <cyg/infra/cyg_ass.h> // assertion macros
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
60 #include <cyg/kernel/thread.hxx> // Cyg_Thread
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
61
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
62 // -------------------------------------------------------------------------
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
63
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
64 // Flag object. This class implements a queue of threads waiting for a
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
65 // boolean expression of the flag value (an integer) to become true; all
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
66 // relevant threads are awoken, not just the first. A variant on this is
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
67 // the single-bit flag, which is implemented by means of default arguments.
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
68
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
69 #ifdef CYGIMP_FLAGS_16BIT
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
70 typedef cyg_uint16 Cyg_FlagValue;
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
71 #define CYG_FLAGS_SIZE 16
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
72 #endif
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
73 #ifdef CYGIMP_FLAGS_32BIT
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
74 typedef cyg_uint32 Cyg_FlagValue;
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
75 #define CYG_FLAGS_SIZE 32
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
76 #endif
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
77 #ifdef CYGIMP_FLAGS_64BIT
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
78 typedef cyg_uint64 Cyg_FlagValue;
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
79 #define CYG_FLAGS_SIZE 64
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
80 #endif
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
81
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
82 #ifndef CYG_FLAGS_SIZE
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
83 typedef cyg_uint32 Cyg_FlagValue;
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
84 #define CYG_FLAGS_SIZE 32
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
85 #endif
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
86
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
87
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
88
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
89 class Cyg_Flag
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
90 {
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
91 private:
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
92 Cyg_FlagValue value;
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
93
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
94 class FlagWaitInfo
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
95 {
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
96 public:
2
443894e2e912 Block commit of eCos version 1.2.1
jlarmour
parents: 0
diff changeset
97 Cyg_FlagValue allmask; // these are separate words to
443894e2e912 Block commit of eCos version 1.2.1
jlarmour
parents: 0
diff changeset
98 Cyg_FlagValue anymask; // save time in wakeup.
443894e2e912 Block commit of eCos version 1.2.1
jlarmour
parents: 0
diff changeset
99 Cyg_FlagValue value_out; // return the value that satisfied
443894e2e912 Block commit of eCos version 1.2.1
jlarmour
parents: 0
diff changeset
100 cyg_bool do_clear;
0
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
101
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
102 FlagWaitInfo() { value_out = 0; }
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
103 };
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
104
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
105 Cyg_ThreadQueue queue; // Queue of waiting threads
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
106
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
107 public:
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
108
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
109 CYGDBG_DEFINE_CHECK_THIS
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
110
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
111 Cyg_Flag( Cyg_FlagValue init = 0 ); // Constructor
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
112 ~Cyg_Flag(); // Destructor
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
113
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
114 void
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
115 setbits( Cyg_FlagValue arg = ~0 ); // -OR- the arg in
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
116 // not inlined; this function awakens affected threads.
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
117
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
118 void
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
119 maskbits( Cyg_FlagValue arg = 0 ); // -AND- it in
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
120 // this is not inlined because it needs to lock the scheduler;
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
121 // it only really does value &= arg; nobody can be awoken in consequence.
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
122
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
123 typedef cyg_uint8 WaitMode;
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
124 // These values are chosen to map directly to uITRON for emulation
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
125 // purposes:
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
126 static const WaitMode AND = 0; // all specified bits must be set
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
127 static const WaitMode OR = 2; // any specified bit must be set
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
128 static const WaitMode CLR = 1; // clear value when satisfied
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
129 static const WaitMode MASK= 3; // might be useful
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
130
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
131 // Wait for a match on our pattern, according to the flags given.
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
132 // Return the matching value, or zero if interrupted.
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
133 Cyg_FlagValue
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
134 wait( Cyg_FlagValue pattern, WaitMode mode );
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
135
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
136 // Wait for a match on our pattern, with an absolute timeout.
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
137 // Return the matching value, or zero if timed out/interrupted.
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
138 // (zero cannot match any pattern).
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
139 #ifdef CYGFUN_KERNEL_THREADS_TIMER
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
140 Cyg_FlagValue
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
141 wait( Cyg_FlagValue pattern, WaitMode mode,
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
142 cyg_tick_count abs_timeout );
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
143 #endif
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
144 // Test for a match on our pattern, according to the flags given.
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
145 // Return the matching value if success, else zero.
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
146 Cyg_FlagValue
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
147 poll( Cyg_FlagValue pattern, WaitMode mode );
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
148
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
149 inline Cyg_FlagValue
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
150 peek() // Get current value
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
151 {
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
152 return value; // NOT atomic wrt threads
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
153 }
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
154
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
155 inline cyg_bool
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
156 waiting() // Any threads waiting?
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
157 {
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
158 return !queue.empty();
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
159 }
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
160 };
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
161
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
162
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
163
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
164 // -------------------------------------------------------------------------
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
165 #endif // ifndef CYGONCE_KERNEL_FLAG_HXX
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
166 // EOF flag.hxx