µ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::event_flags Class Reference

Synchronised event flags. More...

#include <cmsis-plus/rtos/os.h>

+ Inheritance diagram for os::rtos::event_flags:

Classes

class  attributes
 Event flags attributes. More...
 

Public Member Functions

Constructors & Destructor
 event_flags (const attributes &attr=initializer)
 Construct an event flags object instance.
 
 event_flags (const char *name, const attributes &attr=initializer)
 Construct a named event flags object instance.
 
 ~event_flags ()
 Destruct the event flags object instance.
 
Operators
bool operator== (const event_flags &rhs) const
 Compare event flags.
 
Public Member Functions
result_t wait (flags::mask_t mask, flags::mask_t *oflags, flags::mode_t mode=flags::mode::all|flags::mode::clear)
 Wait for event flags.
 
result_t try_wait (flags::mask_t mask, flags::mask_t *oflags=nullptr, flags::mode_t mode=flags::mode::all|flags::mode::clear)
 Try to wait for event flags.
 
result_t timed_wait (flags::mask_t mask, clock::duration_t timeout, flags::mask_t *oflags=nullptr, flags::mode_t mode=flags::mode::all|flags::mode::clear)
 Timed wait for event flags.
 
result_t raise (flags::mask_t mask, flags::mask_t *oflags=nullptr)
 Raise event flags.
 
result_t clear (flags::mask_t mask, flags::mask_t *oflags=nullptr)
 Clear event flags.
 
flags::mask_t get (flags::mask_t mask, flags::mode_t mode=flags::mode::clear)
 Get (and possibly clear) event flags.
 
bool waiting (void)
 Check if there are threads waiting.
 
Public Member Functions
const char * name (void) const
 Get object name.
 

Static Public Member Functions

Operators
static void * operator new (std::size_t bytes)
 Allocate space for a new object instance using the RTOS system allocator.
 
static void * operator new (std::size_t bytes, void *ptr)
 Emplace a new object instance.
 
static void * operator new[] (std::size_t bytes)
 Allocate space for an array of new object instances using the RTOS system allocator.
 
static void * operator new[] (std::size_t bytes, void *ptr)
 Emplace an array of new object instances.
 
static void operator delete (void *ptr, std::size_t bytes)
 Deallocate the dynamically allocated object instance. using the RTOS system allocator.
 
static void operator delete[] (void *ptr, std::size_t bytes)
 Deallocate the dynamically allocated array of object. instances using the RTOS system allocator.
 

Static Public Attributes

static const attributes initializer
 Default event flags initialiser.
 

Detailed Description

Synchronised set of flags that can be used to notify events between threads or between ISRs and threads.

Example
void
consumer(void)
{
// Do something
for (; some_condition();)
{
ev.wait(0x3)
// ...
// Both flags were raised
}
// Do something else.
}
void
producer1(void)
{
// Do something
ev.raise(0x1);
// ...
// Do something else.
}
void
producer2(void)
{
// Do something
ev.raise(0x2);
// ...
// Do something else.
}
Synchronised event flags.
Definition os-evflags.h:57
result_t wait(flags::mask_t mask, flags::mask_t *oflags, flags::mode_t mode=flags::mode::all|flags::mode::clear)
Wait for event flags.
result_t raise(flags::mask_t mask, flags::mask_t *oflags=nullptr)
Raise event flags.
POSIX compatibility
No POSIX similar functionality identified.

Definition at line 56 of file os-evflags.h.

Constructor & Destructor Documentation

◆ event_flags() [1/2]

os::rtos::event_flags::event_flags ( const attributes attr = initializer)
Parameters
[in]attrReference to attributes.

This constructor shall initialise an event flags object with attributes referenced by attr. If the attributes specified by attr are modified later, the event flags attributes shall not be affected. Upon successful initialisation, the state of the event flags object shall become initialised, with all flags cleared.

Only the event flags object itself may be used for performing synchronisation. It is not allowed to make copies of event flags objects.

In cases where default event flags attributes are appropriate, the variable event_flags::initializer can be used to initialise event flags. The effect shall be equivalent to creating an event flags object with the default constructor.

If the attr attributes are modified after the event_flags creation, the event_flags attributes shall not be affected.

Warning
Cannot be invoked from Interrupt Service Routines.

Definition at line 128 of file os-evflags.cpp.

129 : event_flags{ nullptr, attr }
130 {
131 }
event_flags(const attributes &attr=initializer)
Construct an event flags object instance.

◆ event_flags() [2/2]

os::rtos::event_flags::event_flags ( const char *  name,
const attributes attr = initializer 
)
Parameters
[in]namePointer to name.
[in]attrReference to attributes.

This constructor shall initialise a named event flags object with attributes referenced by attr. If the attributes specified by attr are modified later, the event flags attributes shall not be affected. Upon successful initialisation, the state of the event flags object shall become initialised, with all flags cleared.

Only the event flags object itself may be used for performing synchronisation. It is not allowed to make copies of event flags objects.

In cases where default event flags attributes are appropriate, the variable event_flags::initializer can be used to initialise event flags. The effect shall be equivalent to creating an event flags object with the default constructor.

If the attr attributes are modified after the event_flags creation, the event_flags attributes shall not be affected.

Warning
Cannot be invoked from Interrupt Service Routines.

Definition at line 163 of file os-evflags.cpp.

165 {
166#if defined(OS_TRACE_RTOS_EVFLAGS)
167 trace::printf ("%s() @%p %s\n", __func__, this, this->name ());
168#endif
169
170 // Don't call this from interrupt handlers.
172
173#if !defined(OS_USE_RTOS_PORT_EVENT_FLAGS)
174 clock_ = attr.clock != nullptr ? attr.clock : &sysclock;
175#endif
176
177#if defined(OS_USE_RTOS_PORT_EVENT_FLAGS)
178
179 port::event_flags::create (this);
180
181#else
182
183#endif
184 }
object_named_system()
Construct a named system object instance.
Definition os-decls.h:760
const char * name(void) const
Get object name.
Definition os-decls.h:753
int printf(const char *format,...)
Write a formatted string to the trace device.
Definition trace.cpp:59
clock_systick sysclock
The system clock object instance.
bool in_handler_mode(void)
Check if the CPU is in handler mode.
Definition os-sched.h:1101
#define os_assert_throw(__e, __er)
Assert or throw a system error exception.
Definition os-decls.h:1122

References os::rtos::internal::attributes_clocked::clock, os::rtos::interrupts::in_handler_mode(), os_assert_throw, os::trace::printf(), and os::rtos::sysclock.

◆ ~event_flags()

os::rtos::event_flags::~event_flags ( )

This destructor shall destroy the event flags object; the object becomes, in effect, uninitialised. An implementation may cause the destructor to set the object to an invalid value.

It shall be safe to destroy an initialised event flags object upon which no threads are currently blocked. Attempting to destroy an event flags object upon which other threads are currently blocked results in undefined behaviour.

Warning
Cannot be invoked from Interrupt Service Routines.

Definition at line 201 of file os-evflags.cpp.

202 {
203#if defined(OS_TRACE_RTOS_EVFLAGS)
204 trace::printf ("%s() @%p %s\n", __func__, this, name ());
205#endif
206
207#if defined(OS_USE_RTOS_PORT_EVENT_FLAGS)
208
209 port::event_flags::destroy (this);
210
211#else
212
213 // There must be no threads waiting for these flags.
214 assert (list_.empty ());
215
216#endif
217 }

References os::rtos::internal::object_named::name(), and os::trace::printf().

Member Function Documentation

◆ clear()

result_t os::rtos::event_flags::clear ( flags::mask_t  mask,
flags::mask_t oflags = nullptr 
)
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.
Note
Can be invoked from Interrupt Service Routines.

Definition at line 575 of file os-evflags.cpp.

576 {
577#if defined(OS_TRACE_RTOS_EVFLAGS)
578 trace::printf ("%s(0x%X) @%p %s <0x%X \n", __func__, mask, this, name (),
579 event_flags_.mask ());
580#endif
581
582#if defined(OS_USE_RTOS_PORT_EVENT_FLAGS)
583
584 os_assert_err (mask != 0, EINVAL);
585
586 return port::event_flags::clear (this, mask, oflags);
587
588#else
589
590 result_t res = event_flags_.clear (mask, oflags);
591
592#if defined(OS_TRACE_RTOS_EVFLAGS)
593 trace::printf ("%s(0x%X) @%p %s >0x%X\n", __func__, mask, this, name (),
594 event_flags_.mask ());
595#endif
596
597 return res;
598
599#endif
600 }
uint32_t result_t
Type of values returned by RTOS functions.
Definition os-decls.h:95
#define os_assert_err(__e, __er)
Assert or return an error.
Definition os-decls.h:1101

References os::rtos::internal::object_named::name(), os_assert_err, and os::trace::printf().

◆ get()

flags::mask_t os::rtos::event_flags::get ( flags::mask_t  mask,
flags::mode_t  mode = flags::mode::clear 
)
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.

Select the requested event flags and return them. If requested, clear the selected bits in the event flags.

If the mask is flags::any, return the status of all event flags, without any masking or subsequent clearing.

Note
Can be invoked from Interrupt Service Routines.

Definition at line 614 of file os-evflags.cpp.

615 {
616#if defined(OS_TRACE_RTOS_EVFLAGS)
617 trace::printf ("%s(0x%X) @%p %s \n", __func__, mask, this, name ());
618#endif
619
620#if defined(OS_USE_RTOS_PORT_EVENT_FLAGS)
621
622 return port::event_flags::get (this, mask, mode);
623
624#else
625
626 flags::mask_t ret = event_flags_.get (mask, mode);
627
628#if defined(OS_TRACE_RTOS_EVFLAGS)
629 trace::printf ("%s(0x%X)=0x%X @%p %s \n", __func__, mask,
630 event_flags_.mask (), this, name ());
631#endif
632 // Return the selected flags.
633 return ret;
634
635#endif
636 }
uint32_t mask_t
Type of variables holding flags masks.
Definition os-decls.h:266

References os::rtos::internal::object_named::name(), and os::trace::printf().

◆ name()

const char * os::rtos::internal::object_named::name ( void  ) const
inlineinherited
Parameters
None.
Returns
A null terminated string.

All objects return a non-null string; anonymous objects return "-".

Note
Can be invoked from Interrupt Service Routines.

Definition at line 753 of file os-decls.h.

754 {
755 return name_;
756 }

Referenced by os::memory::lifo::lifo(), os::memory::malloc_memory_resource::malloc_memory_resource(), os::rtos::message_queue_typed< T, Allocator >::message_queue_typed(), os::memory::block_pool::~block_pool(), ~event_flags(), os::memory::first_fit_top::~first_fit_top(), os::memory::lifo::~lifo(), os::memory::malloc_memory_resource::~malloc_memory_resource(), os::rtos::memory_pool::~memory_pool(), os::rtos::message_queue::~message_queue(), os::rtos::mutex::~mutex(), os::rtos::semaphore::~semaphore(), os::rtos::thread::~thread(), os::rtos::timer::~timer(), os::rtos::memory_pool::alloc(), os::rtos::thread::cancel(), clear(), os::rtos::mutex::consistent(), os::rtos::thread::detach(), os::memory::new_delete_memory_resource::do_allocate(), os::memory::block_pool::do_allocate(), os::memory::first_fit_top::do_allocate(), os::memory::lifo::do_allocate(), os::memory::malloc_memory_resource::do_allocate(), os::rtos::thread::flags_raise(), os::rtos::memory_pool::free(), get(), os::rtos::thread::interrupt(), os::rtos::thread::join(), os::rtos::thread::kill(), os::rtos::internal::terminated_threads_list::link(), os::rtos::mutex::lock(), os::rtos::memory::memory_resource::out_of_memory_handler(), os::rtos::semaphore::post(), os::rtos::mutex::prio_ceiling(), os::rtos::mutex::prio_ceiling(), os::rtos::thread::priority(), os::rtos::thread::priority_inherited(), raise(), os::rtos::message_queue::receive(), os::rtos::memory_pool::reset(), os::rtos::message_queue::reset(), os::rtos::mutex::reset(), os::rtos::semaphore::reset(), os::rtos::thread::resume(), os::rtos::message_queue::send(), os::rtos::clock::sleep_for(), os::rtos::timer::start(), os::rtos::timer::stop(), os::rtos::memory_pool::timed_alloc(), os::rtos::mutex::timed_lock(), os::rtos::message_queue::timed_receive(), os::rtos::message_queue::timed_send(), os::rtos::semaphore::timed_wait(), timed_wait(), os::rtos::memory::memory_resource::trace_print_statistics(), os::rtos::memory_pool::try_alloc(), os::rtos::mutex::try_lock(), os::rtos::message_queue::try_receive(), os::rtos::message_queue::try_send(), try_wait(), os::rtos::semaphore::try_wait(), os::rtos::internal::ready_threads_list::unlink_head(), os::rtos::mutex::unlock(), wait(), os::rtos::semaphore::wait(), and waiting().

◆ operator delete()

void os::rtos::internal::object_named_system::operator delete ( void *  ptr,
std::size_t  bytes 
)
inlinestaticinherited
Parameters
ptrPointer to object.
bytesNumber of bytes to deallocate.
Returns
Nothing.

The deallocation function (3.7.4.2) called by a delete-expression to render the value of ptr invalid.

ptr shall be a null pointer or its value shall be a value returned by an earlier call to the (possibly replaced) operator new() which has not been invalidated by an intervening call to operator delete(void*).

If ptr is null, does nothing. Otherwise, reclaims the storage allocated by the earlier call to operator new.

The storage is deallocated using the RTOS system allocator.

Warning
Cannot be invoked from Interrupt Service Routines.

Definition at line 120 of file os-inlines.h.

121 {
122 assert (!interrupts::in_handler_mode ());
123
124 rtos::memory::allocator<char> ().deallocate (static_cast<char*> (ptr),
125 bytes);
126 }

References os::rtos::memory::allocator_stateless_default_resource< T >::deallocate(), and os::rtos::interrupts::in_handler_mode().

◆ operator delete[]()

void os::rtos::internal::object_named_system::operator delete[] ( void *  ptr,
std::size_t  bytes 
)
inlinestaticinherited
Parameters
ptrPointer to array of objects.
bytesNumber of bytes to deallocate.
Returns
Nothing.

The deallocation function (3.7.4.2) called by the array form of a delete-expression to render the value of ptr invalid.

If ptr is null, does nothing. Otherwise, reclaims the storage allocated by the earlier call to operator new.

The storage is deallocated using the RTOS system allocator.

Warning
Cannot be invoked from Interrupt Service Routines.

Definition at line 141 of file os-inlines.h.

142 {
143 // Forward array deallocation to single element deallocation.
144 operator delete (ptr, bytes);
145 }

◆ operator new() [1/2]

void * os::rtos::internal::object_named_system::operator new ( std::size_t  bytes)
inlinestaticinherited
Parameters
bytesNumber of bytes to allocate.
Returns
Pointer to allocated object.

The allocation function (3.7.4.1) called by a new-expression (5.3.4) to allocate a storage of size bytes suitably aligned to represent any object of that size. Return a non-null pointer to suitably aligned storage (3.7.4).

The storage is allocated using the RTOS system allocator.

Warning
Cannot be invoked from Interrupt Service Routines.

Definition at line 43 of file os-inlines.h.

44 {
45 assert (!interrupts::in_handler_mode ());
46
47 return rtos::memory::allocator<char> ().allocate (bytes);
48 }

References os::rtos::memory::allocator_stateless_default_resource< T >::allocate(), and os::rtos::interrupts::in_handler_mode().

◆ operator new() [2/2]

void * os::rtos::internal::object_named_system::operator new ( std::size_t  bytes,
void *  ptr 
)
inlinestaticinherited
Parameters
bytesNumber of bytes to emplace.
ptrPointer to location to emplace the object.
Returns
Pointer to emplaced object.

The allocation function (3.7.4.1) called by a placement new-expression to allocate a storage of size bytes suitably aligned to represent any object of that size. Return a non-null pointer to suitably aligned storage (3.7.4).

The storage is allocated using the RTOS system allocator.

Warning
Cannot be invoked from Interrupt Service Routines.

Definition at line 80 of file os-inlines.h.

81 {
82 return ptr;
83 }

◆ operator new[]() [1/2]

void * os::rtos::internal::object_named_system::operator new[] ( std::size_t  bytes)
inlinestaticinherited
Parameters
bytesNumber of bytes to allocate.
Returns
Pointer to allocated array.

The allocation function (3.7.4.1) called by the array form of a new-expression (5.3.4) to allocate a storage of size bytes suitably aligned to represent any array object of that size or smaller.

The storage is allocated using the RTOS system allocator.

Warning
Cannot be invoked from Interrupt Service Routines.

Definition at line 61 of file os-inlines.h.

62 {
63 // Forward array allocation to single element allocation.
64 return operator new (bytes);
65 }

◆ operator new[]() [2/2]

void * os::rtos::internal::object_named_system::operator new[] ( std::size_t  bytes,
void *  ptr 
)
inlinestaticinherited
Parameters
bytesNumber of bytes to emplace.
ptrPointer to location to emplace the object.
Returns
Pointer to emplaced array.

The allocation function (3.7.4.1) called by the array form of a placement new-expression to allocate a storage of size bytes suitably aligned to represent any array object of that size or smaller.

The storage is allocated using the RTOS system allocator.

Warning
Cannot be invoked from Interrupt Service Routines.

Definition at line 97 of file os-inlines.h.

98 {
99 // Forward array allocation to single element allocation.
100 return operator new (bytes, ptr);
101 }

◆ operator==()

bool os::rtos::event_flags::operator== ( const event_flags rhs) const
Return values
trueThe given event flags object is the same as this event flags.
falseThe event flags are different.

◆ raise()

result_t os::rtos::event_flags::raise ( flags::mask_t  mask,
flags::mask_t oflags = nullptr 
)
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.

Set more bits in the thread current signal mask. Use OR at bit-mask level. Wake-up all waiting threads, if any.

Note
Can be invoked from Interrupt Service Routines.

Definition at line 540 of file os-evflags.cpp.

541 {
542#if defined(OS_TRACE_RTOS_EVFLAGS)
543 trace::printf ("%s(0x%X) @%p %s <0x%X \n", __func__, mask, this, name (),
544 event_flags_.mask ());
545#endif
546
547#if defined(OS_USE_RTOS_PORT_EVENT_FLAGS)
548
549 os_assert_err (mask != 0, EINVAL);
550
551 return port::event_flags::raise (this, mask, oflags);
552
553#else
554
555 result_t res = event_flags_.raise (mask, oflags);
556
557 // Wake-up all threads, if any.
558 // Need not be inside the critical section,
559 // the list is protected by inner `resume_one()`.
560 list_.resume_all ();
561
562#if defined(OS_TRACE_RTOS_EVFLAGS)
563 trace::printf ("%s(0x%X) @%p %s >0x%X\n", __func__, mask, this, name (),
564 event_flags_.mask ());
565#endif
566 return res;
567
568#endif
569 }

References os::rtos::internal::object_named::name(), os_assert_err, and os::trace::printf().

◆ timed_wait()

result_t os::rtos::event_flags::timed_wait ( flags::mask_t  mask,
clock::duration_t  timeout,
flags::mask_t oflags = nullptr,
flags::mode_t  mode = flags::mode::all | flags::mode::clear 
)
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.
[in]timeoutTimeout to wait.
Return values
result::okAll expected flags are raised.
EPERMCannot be invoked from an Interrupt Service Routines.
ETIMEDOUTThe expected condition did not occur during the entire timeout duration.
EINVALThe mask is outside of the permitted range.
EINTRThe operation was interrupted.
ENOTRECOVERABLEWait failed.

If the flags::mode::all bit is set, the function expects all requested flags to be raised; otherwise, if the flags::mode::any bit is set, the function expects any single flag to be raised.

If the expected event flags are raised, the function returns instantly.

Otherwise suspend the execution of the current thread until all/any specified event flags are raised.

When the parameter mask is 0, the current thread is suspended until any event flag is raised. In this case, if any event flags are already raised, the function returns instantly.

The wait shall be terminated when the specified timeout expires.

The timeout shall expire after the number of time units (that is when the value of that clock equals or exceeds (now()+duration). The resolution of the timeout shall be the resolution of the clock on which it is based (the SysTick clock for CMSIS).

Under no circumstance shall the operation fail with a timeout if the event flags are already raised. The validity of the timeout need not be checked if the expected flags are already raised and the call can return immediately.

The clock used for timeouts can be specified via the clock attribute. By default, the clock derived from the scheduler timer is used, and the durations are expressed in ticks.

If the flags::mode::clear bit is set, the event flags that are returned are automatically cleared.

Warning
Cannot be invoked from Interrupt Service Routines.

Definition at line 425 of file os-evflags.cpp.

427 {
428#if defined(OS_TRACE_RTOS_EVFLAGS)
429 trace::printf ("%s(0x%X,%u,%u) @%p %s <0x%X\n", __func__, mask, timeout,
430 mode, this, name (), event_flags_.mask ());
431#endif
432
433 // Don't call this from interrupt handlers.
435 // Don't call this from critical regions.
437
438#if defined(OS_USE_RTOS_PORT_EVENT_FLAGS)
439
440 return port::event_flags::timed_wait (this, mask, timeout, oflags, mode);
441
442#else
443
444 // Extra test before entering the loop, with its inherent weight.
445 // Trade size for speed.
446 {
447 // ----- Enter critical section ---------------------------------------
448 interrupts::critical_section ics;
449
450 if (event_flags_.check_raised (mask, oflags, mode))
451 {
452#if defined(OS_TRACE_RTOS_EVFLAGS)
453 trace::printf ("%s(0x%X,%u,%u) @%p %s >0x%X\n", __func__, mask,
454 timeout, mode, this, name (), event_flags_.mask ());
455#endif
456 return result::ok;
457 }
458 // ----- Exit critical section ----------------------------------------
459 }
460
461 thread& crt_thread = this_thread::thread ();
462
463 // Prepare a list node pointing to the current thread.
464 // Do not worry for being on stack, it is temporarily linked to the
465 // list and guaranteed to be removed before this function returns.
466 internal::waiting_thread_node node{ crt_thread };
467
468 internal::clock_timestamps_list& clock_list = clock_->steady_list ();
469 clock::timestamp_t timeout_timestamp = clock_->steady_now () + timeout;
470
471 // Prepare a timeout node pointing to the current thread.
472 internal::timeout_thread_node timeout_node{ timeout_timestamp,
473 crt_thread };
474
475 for (;;)
476 {
477 {
478 // ----- Enter critical section -----------------------------------
479 interrupts::critical_section ics;
480
481 if (event_flags_.check_raised (mask, oflags, mode))
482 {
483#if defined(OS_TRACE_RTOS_EVFLAGS)
484 trace::printf ("%s(0x%X,%u,%u) @%p %s >0x%X\n", __func__, mask,
485 timeout, mode, this, name (),
486 event_flags_.mask ());
487#endif
488 return result::ok;
489 }
490
491 // Add this thread to the event flags waiting list,
492 // and the clock timeout list.
493 scheduler::internal_link_node (list_, node, clock_list,
494 timeout_node);
495 // state::suspended set in above link().
496 // ----- Exit critical section ------------------------------------
497 }
498
500
501 // Remove the thread from the event flags waiting list,
502 // if not already removed by raise() and from the clock
503 // timeout list, if not already removed by the timer.
504 scheduler::internal_unlink_node (node, timeout_node);
505
506 if (crt_thread.interrupted ())
507 {
508#if defined(OS_TRACE_RTOS_EVFLAGS)
509 trace::printf ("%s(0x%X,%u,%u) EINTR @%p %s 0x%X \n", __func__,
510 mask, timeout, mode, this, name ());
511#endif
512 return EINTR;
513 }
514
515 if (clock_->steady_now () >= timeout_timestamp)
516 {
517#if defined(OS_TRACE_RTOS_EVFLAGS)
518 trace::printf ("%s(0x%X,%u,%u) ETIMEDOUT @%p %s 0x%X \n",
519 __func__, mask, timeout, mode, this, name ());
520#endif
521 return ETIMEDOUT;
522 }
523 }
524
525 /* NOTREACHED */
526 return ENOTRECOVERABLE;
527
528#endif
529 }
Standard thread.
port::clock::timestamp_t timestamp_t
Type of variables holding clock time stamps.
Definition os-clocks.h:88
@ ok
Function completed; no errors or events occurred.
Definition os-decls.h:179
bool locked(void)
Check if the scheduler is locked.
Definition os-sched.h:858
thread & thread(void)
Get the current running thread.

References os::rtos::interrupts::in_handler_mode(), os::rtos::thread::interrupted(), os::rtos::scheduler::locked(), os::rtos::internal::object_named::name(), os::rtos::result::ok, os_assert_throw, os::trace::printf(), os::rtos::port::scheduler::reschedule(), and os::rtos::this_thread::thread().

◆ try_wait()

result_t os::rtos::event_flags::try_wait ( flags::mask_t  mask,
flags::mask_t oflags = nullptr,
flags::mode_t  mode = flags::mode::all | flags::mode::clear 
)
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
result::okAll expected flags were raised.
EINVALThe mask is outside of the permitted range.
EWOULDBLOCKThe expected condition did not occur.
ENOTRECOVERABLEWait failed.

If the flags::mode::all bit is set, the function expects all requested flags to be raised; otherwise, if the flags::mode::any bit is set, the function expects any single flag to be raised.

The function does not blocks, if the expected event flags are not raised, but returns EGAIN.

Note
Can be invoked from Interrupt Service Routines.

Definition at line 343 of file os-evflags.cpp.

345 {
346#if defined(OS_TRACE_RTOS_EVFLAGS)
347 trace::printf ("%s(0x%X,%u) @%p %s <0x%X\n", __func__, mask, mode, this,
348 name (), event_flags_.mask ());
349#endif
350
351#if defined(OS_USE_RTOS_PORT_EVENT_FLAGS)
352
353 return port::event_flags::try_wait (this, mask, oflags, mode);
354
355#else
356
357 // Don't call this from high priority interrupts.
358 assert (port::interrupts::is_priority_valid ());
359
360 {
361 // ----- Enter critical section ---------------------------------------
362 interrupts::critical_section ics;
363
364 if (event_flags_.check_raised (mask, oflags, mode))
365 {
366#if defined(OS_TRACE_RTOS_EVFLAGS)
367 trace::printf ("%s(0x%X,%u) @%p %s >0x%X\n", __func__, mask, mode,
368 this, name (), event_flags_.mask ());
369#endif
370 return result::ok;
371 }
372 else
373 {
374#if defined(OS_TRACE_RTOS_EVFLAGS)
375 trace::printf ("%s(0x%X,%u) EWOULDBLOCK @%p %s \n", __func__, mask,
376 mode, this, name ());
377#endif
378 return EWOULDBLOCK;
379 }
380 // ----- Exit critical section ----------------------------------------
381 }
382
383#endif
384 }

References os::rtos::internal::object_named::name(), os::rtos::result::ok, and os::trace::printf().

◆ wait()

result_t os::rtos::event_flags::wait ( flags::mask_t  mask,
flags::mask_t oflags,
flags::mode_t  mode = flags::mode::all | flags::mode::clear 
)
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
result::okAll expected flags were raised.
EPERMCannot be invoked from an Interrupt Service Routines.
EINVALThe mask is outside of the permitted range.
EINTRThe operation was interrupted.
ENOTRECOVERABLEWait failed.

If the flags::mode::all bit is set, the function expects all requested flags to be raised; otherwise, if the flags::mode::any bit is set, the function expects any single flag to be raised.

If the expected event flags are raised, the function returns instantly.

Otherwise suspend the execution of the current thread until all/any specified event flags are raised.

When the parameter mask is 0, the current thread is suspended until any event flag is raised. In this case, if any event flags are already raised, the function returns instantly.

If the flags::mode::clear bit is set, the event flags that are returned are automatically cleared.

Warning
Cannot be invoked from Interrupt Service Routines.

Definition at line 241 of file os-evflags.cpp.

243 {
244#if defined(OS_TRACE_RTOS_EVFLAGS)
245 trace::printf ("%s(0x%X,%u) @%p %s <0x%X\n", __func__, mask, mode, this,
246 name (), event_flags_.mask ());
247#endif
248
249 // Don't call this from interrupt handlers.
251 // Don't call this from critical regions.
253
254#if defined(OS_USE_RTOS_PORT_EVENT_FLAGS)
255
256 return port::event_flags::wait (this, mask, oflags, mode);
257
258#else
259
260 {
261 // ----- Enter critical section ---------------------------------------
262 interrupts::critical_section ics;
263
264 if (event_flags_.check_raised (mask, oflags, mode))
265 {
266#if defined(OS_TRACE_RTOS_EVFLAGS)
267 trace::printf ("%s(0x%X,%u) @%p %s >0x%X\n", __func__, mask, mode,
268 this, name (), event_flags_.mask ());
269#endif
270 return result::ok;
271 }
272 // ----- Exit critical section ----------------------------------------
273 }
274
275 thread& crt_thread = this_thread::thread ();
276
277 // Prepare a list node pointing to the current thread.
278 // Do not worry for being on stack, it is temporarily linked to the
279 // list and guaranteed to be removed before this function returns.
280 internal::waiting_thread_node node{ crt_thread };
281
282 for (;;)
283 {
284 {
285 // ----- Enter critical section -----------------------------------
286 interrupts::critical_section ics;
287
288 if (event_flags_.check_raised (mask, oflags, mode))
289 {
290#if defined(OS_TRACE_RTOS_EVFLAGS)
291 trace::printf ("%s(0x%X,%u) @%p %s >0x%X\n", __func__, mask,
292 mode, this, name (), event_flags_.mask ());
293#endif
294 return result::ok;
295 }
296
297 // Add this thread to the event flags waiting list.
298 scheduler::internal_link_node (list_, node);
299 // state::suspended set in above link().
300 // ----- Exit critical section ------------------------------------
301 }
302
304
305 {
306 // ----- Enter critical section -----------------------------------
307 interrupts::critical_section ics;
308
309 // Remove the thread from the event flags waiting list,
310 // if not already removed by raise().
311 scheduler::internal_unlink_node (node);
312 // ----- Exit critical section ------------------------------------
313 }
314
315 if (crt_thread.interrupted ())
316 {
317#if defined(OS_TRACE_RTOS_EVFLAGS)
318 trace::printf ("%s(0x%X,%u) EINTR @%p %s\n", __func__, mask,
319 mode, this, name ());
320#endif
321 return EINTR;
322 }
323 }
324
325 /* NOTREACHED */
326 return ENOTRECOVERABLE;
327
328#endif
329 }

References os::rtos::interrupts::in_handler_mode(), os::rtos::thread::interrupted(), os::rtos::scheduler::locked(), os::rtos::internal::object_named::name(), os::rtos::result::ok, os_assert_throw, os::trace::printf(), os::rtos::port::scheduler::reschedule(), and os::rtos::this_thread::thread().

◆ waiting()

bool os::rtos::event_flags::waiting ( void  )
Parameters
None.
Return values
trueThere are threads waiting.
falseThere are no threads waiting.
Note
Can be invoked from Interrupt Service Routines.

Definition at line 642 of file os-evflags.cpp.

643 {
644#if defined(OS_TRACE_RTOS_EVFLAGS)
645 trace::printf ("%s() @%p %s\n", __func__, this, name ());
646#endif
647
648#if defined(OS_USE_RTOS_PORT_EVENT_FLAGS)
649
650 return port::event_flags::waiting (this);
651
652#else
653
654 // Don't call this from high priority interrupts.
655 assert (port::interrupts::is_priority_valid ());
656
657 {
658 // ----- Enter critical section ---------------------------------------
659 interrupts::critical_section ics;
660
661 return !list_.empty ();
662 // ----- Exit critical section ----------------------------------------
663 }
664
665#endif
666 }

References os::rtos::internal::object_named::name(), and os::trace::printf().


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