EventFlags
EventFlags class hierarchy
The EventFlags class provides a mechanism for setting and waiting for specific conditions. It provides a generic way of notifying other threads about conditions or events. You can think of each instance of the EventFlags class as an event channel. There are 31 different flags available for each event.
EventFlags class reference
Public Member Functions | |
EventFlags () | |
Create and initialize an EventFlags object. More... | |
EventFlags (const char *name) | |
Create and initialize an EventFlags object. More... | |
uint32_t | set (uint32_t flags) |
Set the specified event flags. More... | |
uint32_t | clear (uint32_t flags=0x7fffffff) |
Clear the specified event flags. More... | |
uint32_t | get () const |
Get the currently set event flags. More... | |
uint32_t | wait_all (uint32_t flags=0, uint32_t millisec=osWaitForever, bool clear=true) |
Wait for all of the specified event flags to become signaled. More... | |
uint32_t | wait_any (uint32_t flags=0, uint32_t millisec=osWaitForever, bool clear=true) |
Wait for any of the specified event flags to become signaled. More... | |
~EventFlags () | |
EventFlags destructor. More... |
EventFlags example
#include "mbed.h"
#define SAMPLE_FLAG1 (1UL << 0)
#define SAMPLE_FLAG2 (1UL << 9)
EventFlags event_flags;
void worker_thread_fun()
{
printf("Waiting for any flag from 0x%08lx.\r\n", SAMPLE_FLAG1 | SAMPLE_FLAG2);
uint32_t flags_read = 0;
while (true) {
flags_read = event_flags.wait_any(SAMPLE_FLAG1 | SAMPLE_FLAG2);
printf("Got: 0x%08lx\r\n", flags_read);
}
}
int main()
{
Thread worker_thread;
worker_thread.start(mbed::callback(worker_thread_fun));
while (true) {
ThisThread::sleep_for(1000);
event_flags.set(SAMPLE_FLAG1);
ThisThread::sleep_for(500);
event_flags.set(SAMPLE_FLAG2);
}
}