1 #ifndef CYGONCE_KERNEL_FLAG_HXX
2 #define CYGONCE_KERNEL_FLAG_HXX
4 //==========================================================================
8 // Flag object class declarations
10 //==========================================================================
11 //####ECOSGPLCOPYRIGHTBEGIN####
12 // -------------------------------------------
13 // This file is part of eCos, the Embedded Configurable Operating System.
14 // Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
16 // eCos is free software; you can redistribute it and/or modify it under
17 // the terms of the GNU General Public License as published by the Free
18 // Software Foundation; either version 2 or (at your option) any later version.
20 // eCos is distributed in the hope that it will be useful, but WITHOUT ANY
21 // WARRANTY; without even the implied warranty of MERCHANTABILITY or
22 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
25 // You should have received a copy of the GNU General Public License along
26 // with eCos; if not, write to the Free Software Foundation, Inc.,
27 // 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
29 // As a special exception, if other files instantiate templates or use macros
30 // or inline functions from this file, or you compile this file and link it
31 // with other works to produce a work based on this file, this file does not
32 // by itself cause the resulting work to be covered by the GNU General Public
33 // License. However the source code for this file must still be made available
34 // in accordance with section (3) of the GNU General Public License.
36 // This exception does not invalidate any other reasons why a work based on
37 // this file might be covered by the GNU General Public License.
39 // Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
40 // at http://sources.redhat.com/ecos/ecos-license/
41 // -------------------------------------------
42 //####ECOSGPLCOPYRIGHTEND####
43 //==========================================================================
44 //#####DESCRIPTIONBEGIN####
49 // Purpose: Define Flag class interfaces
50 // Description: The classes defined here provide the APIs for flags.
51 // Usage: #include <cyg/kernel/flag.hxx>
54 //####DESCRIPTIONEND####
56 //==========================================================================
58 #include <cyg/kernel/ktypes.h>
59 #include <cyg/infra/cyg_ass.h> // assertion macros
60 #include <cyg/kernel/thread.hxx> // Cyg_Thread
62 #include <cyg/kernel/thread.inl> // queue implementation
63 // -------------------------------------------------------------------------
65 // Flag object. This class implements a queue of threads waiting for a
66 // boolean expression of the flag value (an integer) to become true; all
67 // relevant threads are awoken, not just the first. A variant on this is
68 // the single-bit flag, which is implemented by means of default arguments.
70 #ifdef CYGIMP_FLAGS_16BIT
71 typedef cyg_uint16 Cyg_FlagValue;
72 #define CYG_FLAGS_SIZE 16
74 #ifdef CYGIMP_FLAGS_32BIT
75 typedef cyg_uint32 Cyg_FlagValue;
76 #define CYG_FLAGS_SIZE 32
78 #ifdef CYGIMP_FLAGS_64BIT
79 typedef cyg_uint64 Cyg_FlagValue;
80 #define CYG_FLAGS_SIZE 64
83 #ifndef CYG_FLAGS_SIZE
84 typedef cyg_uint32 Cyg_FlagValue;
85 #define CYG_FLAGS_SIZE 32
98 Cyg_FlagValue allmask; // these are separate words to
99 Cyg_FlagValue anymask; // save time in wakeup.
100 Cyg_FlagValue value_out; // return the value that satisfied
103 FlagWaitInfo() { value_out = 0; }
106 Cyg_ThreadQueue queue; // Queue of waiting threads
110 CYGDBG_DEFINE_CHECK_THIS
112 Cyg_Flag( Cyg_FlagValue init = 0 ); // Constructor
113 ~Cyg_Flag(); // Destructor
116 setbits( Cyg_FlagValue arg = ~0 ); // -OR- the arg in
117 // not inlined; this function awakens affected threads.
120 maskbits( Cyg_FlagValue arg = 0 ); // -AND- it in
121 // this is not inlined because it needs to lock the scheduler;
122 // it only really does value &= arg; nobody can be awoken in consequence.
124 typedef cyg_uint8 WaitMode;
125 // These values are chosen to map directly to uITRON for emulation
127 static const WaitMode AND = 0; // all specified bits must be set
128 static const WaitMode OR = 2; // any specified bit must be set
129 static const WaitMode CLR = 1; // clear value when satisfied
130 static const WaitMode MASK= 3; // might be useful
132 // Wait for a match on our pattern, according to the flags given.
133 // Return the matching value, or zero if interrupted.
135 wait( Cyg_FlagValue pattern, WaitMode mode );
137 // Wait for a match on our pattern, with an absolute timeout.
138 // Return the matching value, or zero if timed out/interrupted.
139 // (zero cannot match any pattern).
140 #ifdef CYGFUN_KERNEL_THREADS_TIMER
142 wait( Cyg_FlagValue pattern, WaitMode mode,
143 cyg_tick_count abs_timeout );
145 // Test for a match on our pattern, according to the flags given.
146 // Return the matching value if success, else zero.
148 poll( Cyg_FlagValue pattern, WaitMode mode );
151 peek() // Get current value
153 return value; // NOT atomic wrt threads
157 waiting() // Any threads waiting?
159 return !queue.empty();
165 // -------------------------------------------------------------------------
166 #endif // ifndef CYGONCE_KERNEL_FLAG_HXX