I have several ChibiOS/RT threads running. They each have their own Mailbox where they receive commands and status updates from other parts of the system. So they usually sleep until they get woken up by a new entry in their Mailbox. The code looks like this:
Code: Select all
while (true)
{
msg_t msg;
if (chMBFetchTimeout(&fan_handler_mb, &msg, TIME_INFINITE) == MSG_OK)
{
// handle message
Now I have certain global state changes that each thread needs to be aware of and must handle immediately. I thought about using Events for this and have each thread register to listen for the Event. So the threads would have to call "chEvtWaitAny(ALL_EVENTS)" to get the Events.
But is it possible to have a thread sleep until either a new message is in the Mailbox or a new is Event received?
To me it looks like I just can wait for a new entry in the Mailbox or an Event, but not both at the same time. Or would just registering for an Event already wake up the thread, even if it is currently sleeping in "chMBFetchTimeout()"?
Thanks.