µOS++ IIIe Reference 7.0.0
The third edition of µOS++, a POSIX inspired open source framework, written in C++
Loading...
Searching...
No Matches
os::rtos::internal::event_flags Class Reference

Internal event flags implementation. More...

#include <os-flags.h>

Public Member Functions

Constructors & Destructor
 event_flags ()=default
 Construct an internal event flags object instance.
 
 ~event_flags ()=default
 Destruct the internal event flags object instance.
 
Public Member Functions
result_t raise (flags::mask_t mask, flags::mask_t *oflags)
 Raise event flags.
 
bool check_raised (flags::mask_t mask, flags::mask_t *oflags, flags::mode_t mode)
 Check if expected flags are raised.
 
flags::mask_t get (flags::mask_t mask, flags::mode_t mode)
 Get (and possibly clear) event flags.
 
result_t clear (flags::mask_t mask, flags::mask_t *oflags)
 Clear event flags.
 
flags::mask_t mask (void)
 Get the flags mask.
 

Detailed Description

Definition at line 46 of file os-flags.h.

Constructor & Destructor Documentation

◆ event_flags()

os::rtos::internal::event_flags::event_flags ( )
default

◆ ~event_flags()

os::rtos::internal::event_flags::~event_flags ( )
default

Member Function Documentation

◆ check_raised()

bool os::rtos::internal::event_flags::check_raised ( flags::mask_t  mask,
flags::mask_t oflags,
flags::mode_t  mode 
)
Parameters
[in]maskThe expected flags (OR-ed bit-mask); if flags::any, any flag raised will do it.
[out]oflagsPointer where to store the current flags; may be nullptr.
[in]modeMode bits to select if either all or any flags in the mask are expected, and if the flags should be cleared.
Return values
trueThe expected flags are raised.
falseThe expected flags are not raised.

Definition at line 63 of file os-flags.cpp.

65 {
66 if (mask == flags::any)
67 {
68 // Any flag will do it.
69 if (flags_mask_ != 0)
70 {
71 if (oflags != nullptr)
72 {
73 *oflags = flags_mask_;
74 }
75
76 if (mode & flags::mode::clear)
77 {
78 // Clear them all.
79 flags_mask_ = 0;
80 }
81 return true;
82 }
83 }
84 else if (((((mode & flags::mode::all) != 0))
85 && ((flags_mask_ & mask) == mask))
86 || (((mode & flags::mode::any) != 0)
87 && ((flags_mask_ & mask) != 0)))
88 {
89 if (oflags != nullptr)
90 {
91 *oflags = (flags_mask_ & mask);
92 }
93
94 if (mode & flags::mode::clear)
95 {
96#pragma GCC diagnostic push
97#if defined(__clang__)
98#pragma clang diagnostic ignored "-Wdeprecated-volatile"
99#elif defined(__GNUC__)
100#pragma GCC diagnostic ignored "-Wvolatile"
101#endif
102 // Clear desired flags.
103 flags_mask_ &= ~mask;
104#pragma GCC diagnostic pop
105 }
106 return true;
107 }
108
109 return false;
110 }
flags::mask_t mask(void)
Get the flags mask.
Definition os-flags.h:189
@ all
Return when all flags are set.
Definition os-decls.h:295
@ clear
Ask for flags to be cleared after read.
Definition os-decls.h:305
@ any
Return when at least one flag is set.
Definition os-decls.h:300
@ any
Special mask to represent any flag.
Definition os-decls.h:317

References os::rtos::flags::mode::all, os::rtos::flags::mode::any, os::rtos::flags::any, os::rtos::flags::mode::clear, and mask().

◆ clear()

result_t os::rtos::internal::event_flags::clear ( flags::mask_t  mask,
flags::mask_t oflags 
)
Parameters
[in]maskThe OR-ed flags to clear.
[out]oflagsOptional pointer where to store the previous value of the flags; may be nullptr.
Return values
result::okThe flags were cleared.
EINVALThe mask is zero.

Definition at line 149 of file os-flags.cpp.

150 {
151 os_assert_err (mask != 0, EINVAL);
152
153 {
154 // ----- Enter critical section -------------------------------------
155 interrupts::critical_section ics;
156
157 if (oflags != nullptr)
158 {
159 *oflags = flags_mask_;
160 }
161
162#pragma GCC diagnostic push
163#if defined(__clang__)
164#pragma clang diagnostic ignored "-Wdeprecated-volatile"
165#elif defined(__GNUC__)
166#pragma GCC diagnostic ignored "-Wvolatile"
167#endif
168 // Clear the selected bits; leave the rest untouched.
169 flags_mask_ &= ~mask;
170#pragma GCC diagnostic pop
171
172 // ----- Exit critical section --------------------------------------
173 }
174
175 return result::ok;
176 }
@ ok
Function completed; no errors or events occurred.
Definition os-decls.h:179
#define os_assert_err(__e, __er)
Assert or return an error.
Definition os-decls.h:1101

References mask(), os::rtos::result::ok, and os_assert_err.

◆ get()

flags::mask_t os::rtos::internal::event_flags::get ( flags::mask_t  mask,
flags::mode_t  mode 
)
Parameters
[in]maskThe OR-ed flags to get/clear; can be flags::any.
[in]modeMode bits to select if the flags should be cleared (the other bits are ignored).
Returns
The selected bits from the flags mask.

Definition at line 113 of file os-flags.cpp.

114 {
115 flags::mask_t ret;
116 {
117 // ----- Enter critical section -------------------------------------
118 interrupts::critical_section ics;
119
120 if (mask == 0)
121 {
122 // Return the entire mask.
123 ret = flags_mask_;
124 }
125 else
126 {
127 ret = flags_mask_ & mask;
128 if ((mode & flags::mode::clear) != 0)
129 {
130#pragma GCC diagnostic push
131#if defined(__clang__)
132#pragma clang diagnostic ignored "-Wdeprecated-volatile"
133#elif defined(__GNUC__)
134#pragma GCC diagnostic ignored "-Wvolatile"
135#endif
136 // Clear the selected bits; leave the rest untouched.
137 flags_mask_ &= ~mask;
138#pragma GCC diagnostic pop
139 }
140 }
141 // ----- Exit critical section --------------------------------------
142 }
143
144 // Return the selected bits.
145 return ret;
146 }
uint32_t mask_t
Type of variables holding flags masks.
Definition os-decls.h:266

References os::rtos::flags::mode::clear, and mask().

◆ mask()

flags::mask_t os::rtos::internal::event_flags::mask ( void  )
inline
Returns
The internal bit-mask.

Definition at line 189 of file os-flags.h.

190 {
191 return flags_mask_;
192 }

Referenced by check_raised(), clear(), get(), and raise().

◆ raise()

result_t os::rtos::internal::event_flags::raise ( flags::mask_t  mask,
flags::mask_t oflags 
)
Parameters
[in]maskThe OR-ed flags to raise.
[out]oflagsOptional pointer where to store the new value of the flags; may be nullptr.
Return values
result::okThe flags were raised.
EINVALThe mask is zero.
ENOTRECOVERABLERaise failed.

Definition at line 33 of file os-flags.cpp.

34 {
35 os_assert_err (mask != 0, EINVAL);
36
37 assert (port::interrupts::is_priority_valid ());
38
39 {
40 // ----- Enter critical section -------------------------------------
41 interrupts::critical_section ics;
42
43 if (oflags != nullptr)
44 {
45 *oflags = flags_mask_;
46 }
47
48#pragma GCC diagnostic push
49#if defined(__clang__)
50#pragma clang diagnostic ignored "-Wdeprecated-volatile"
51#elif defined(__GNUC__)
52#pragma GCC diagnostic ignored "-Wvolatile"
53#endif
54 flags_mask_ |= mask;
55#pragma GCC diagnostic pop
56
57 // ----- Exit critical section --------------------------------------
58 }
59 return result::ok;
60 }

References mask(), os::rtos::result::ok, and os_assert_err.


The documentation for this class was generated from the following files: