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