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