|
0
|
1 #ifndef CYGONCE_KERNEL_FLAG_HXX |
|
|
2 #define CYGONCE_KERNEL_FLAG_HXX |
|
|
3 |
|
|
4 //========================================================================== |
|
|
5 // |
|
2
|
6 // flag.hxx |
|
0
|
7 // |
|
2
|
8 // Flag object class declarations |
|
0
|
9 // |
|
|
10 //========================================================================== |
|
|
11 //####COPYRIGHTBEGIN#### |
|
|
12 // |
|
|
13 // ------------------------------------------- |
|
|
14 // The contents of this file are subject to the Cygnus eCos Public License |
|
|
15 // Version 1.0 (the "License"); you may not use this file except in |
|
|
16 // compliance with the License. You may obtain a copy of the License at |
|
|
17 // http://sourceware.cygnus.com/ecos |
|
|
18 // |
|
|
19 // Software distributed under the License is distributed on an "AS IS" |
|
|
20 // basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the |
|
|
21 // License for the specific language governing rights and limitations under |
|
|
22 // the License. |
|
|
23 // |
|
|
24 // The Original Code is eCos - Embedded Cygnus Operating System, released |
|
|
25 // September 30, 1998. |
|
|
26 // |
|
|
27 // The Initial Developer of the Original Code is Cygnus. Portions created |
|
2
|
28 // by Cygnus are Copyright (C) 1998,1999 Cygnus Solutions. All Rights Reserved. |
|
0
|
29 // ------------------------------------------- |
|
|
30 // |
|
|
31 //####COPYRIGHTEND#### |
|
|
32 //========================================================================== |
|
|
33 //#####DESCRIPTIONBEGIN#### |
|
|
34 // |
|
2
|
35 // Author(s): hmt |
|
|
36 // Contributors: hmt |
|
|
37 // Date: 1998-02-10 |
|
|
38 // Purpose: Define Flag class interfaces |
|
|
39 // Description: The classes defined here provide the APIs for flags. |
|
|
40 // Usage: #include <cyg/kernel/flag.hxx> |
|
|
41 // |
|
0
|
42 // |
|
|
43 //####DESCRIPTIONEND#### |
|
|
44 // |
|
|
45 //========================================================================== |
|
|
46 |
|
|
47 #include <cyg/kernel/ktypes.h> |
|
|
48 #include <cyg/infra/cyg_ass.h> // assertion macros |
|
|
49 #include <cyg/kernel/thread.hxx> // Cyg_Thread |
|
|
50 |
|
|
51 // ------------------------------------------------------------------------- |
|
|
52 |
|
|
53 // Flag object. This class implements a queue of threads waiting for a |
|
|
54 // boolean expression of the flag value (an integer) to become true; all |
|
|
55 // relevant threads are awoken, not just the first. A variant on this is |
|
|
56 // the single-bit flag, which is implemented by means of default arguments. |
|
|
57 |
|
|
58 #ifdef CYGIMP_FLAGS_16BIT |
|
|
59 typedef cyg_uint16 Cyg_FlagValue; |
|
|
60 #define CYG_FLAGS_SIZE 16 |
|
|
61 #endif |
|
|
62 #ifdef CYGIMP_FLAGS_32BIT |
|
|
63 typedef cyg_uint32 Cyg_FlagValue; |
|
|
64 #define CYG_FLAGS_SIZE 32 |
|
|
65 #endif |
|
|
66 #ifdef CYGIMP_FLAGS_64BIT |
|
|
67 typedef cyg_uint64 Cyg_FlagValue; |
|
|
68 #define CYG_FLAGS_SIZE 64 |
|
|
69 #endif |
|
|
70 |
|
|
71 #ifndef CYG_FLAGS_SIZE |
|
|
72 typedef cyg_uint32 Cyg_FlagValue; |
|
|
73 #define CYG_FLAGS_SIZE 32 |
|
|
74 #endif |
|
|
75 |
|
|
76 |
|
|
77 |
|
|
78 class Cyg_Flag |
|
|
79 { |
|
|
80 private: |
|
|
81 Cyg_FlagValue value; |
|
|
82 |
|
|
83 class FlagWaitInfo |
|
|
84 { |
|
|
85 public: |
|
2
|
86 Cyg_FlagValue allmask; // these are separate words to |
|
|
87 Cyg_FlagValue anymask; // save time in wakeup. |
|
|
88 Cyg_FlagValue value_out; // return the value that satisfied |
|
|
89 cyg_bool do_clear; |
|
0
|
90 |
|
|
91 FlagWaitInfo() { value_out = 0; } |
|
|
92 }; |
|
|
93 |
|
|
94 Cyg_ThreadQueue queue; // Queue of waiting threads |
|
|
95 |
|
|
96 public: |
|
|
97 |
|
|
98 CYGDBG_DEFINE_CHECK_THIS |
|
|
99 |
|
|
100 Cyg_Flag( Cyg_FlagValue init = 0 ); // Constructor |
|
|
101 ~Cyg_Flag(); // Destructor |
|
|
102 |
|
|
103 void |
|
|
104 setbits( Cyg_FlagValue arg = ~0 ); // -OR- the arg in |
|
|
105 // not inlined; this function awakens affected threads. |
|
|
106 |
|
|
107 void |
|
|
108 maskbits( Cyg_FlagValue arg = 0 ); // -AND- it in |
|
|
109 // this is not inlined because it needs to lock the scheduler; |
|
|
110 // it only really does value &= arg; nobody can be awoken in consequence. |
|
|
111 |
|
|
112 typedef cyg_uint8 WaitMode; |
|
|
113 // These values are chosen to map directly to uITRON for emulation |
|
|
114 // purposes: |
|
|
115 static const WaitMode AND = 0; // all specified bits must be set |
|
|
116 static const WaitMode OR = 2; // any specified bit must be set |
|
|
117 static const WaitMode CLR = 1; // clear value when satisfied |
|
|
118 static const WaitMode MASK= 3; // might be useful |
|
|
119 |
|
|
120 // Wait for a match on our pattern, according to the flags given. |
|
|
121 // Return the matching value, or zero if interrupted. |
|
|
122 Cyg_FlagValue |
|
|
123 wait( Cyg_FlagValue pattern, WaitMode mode ); |
|
|
124 |
|
|
125 // Wait for a match on our pattern, with an absolute timeout. |
|
|
126 // Return the matching value, or zero if timed out/interrupted. |
|
|
127 // (zero cannot match any pattern). |
|
|
128 #ifdef CYGFUN_KERNEL_THREADS_TIMER |
|
|
129 Cyg_FlagValue |
|
|
130 wait( Cyg_FlagValue pattern, WaitMode mode, |
|
|
131 cyg_tick_count abs_timeout ); |
|
|
132 #endif |
|
|
133 // Test for a match on our pattern, according to the flags given. |
|
|
134 // Return the matching value if success, else zero. |
|
|
135 Cyg_FlagValue |
|
|
136 poll( Cyg_FlagValue pattern, WaitMode mode ); |
|
|
137 |
|
|
138 inline Cyg_FlagValue |
|
|
139 peek() // Get current value |
|
|
140 { |
|
|
141 return value; // NOT atomic wrt threads |
|
|
142 } |
|
|
143 |
|
|
144 inline cyg_bool |
|
|
145 waiting() // Any threads waiting? |
|
|
146 { |
|
|
147 return !queue.empty(); |
|
|
148 } |
|
|
149 }; |
|
|
150 |
|
|
151 |
|
|
152 |
|
|
153 // ------------------------------------------------------------------------- |
|
|
154 #endif // ifndef CYGONCE_KERNEL_FLAG_HXX |
|
|
155 // EOF flag.hxx |