Page 1 of 1

Multiple events management

Posted: Mon Apr 08, 2019 6:35 pm
by bitto
Hello,
I just want to make sure I got it right with events.

I have the following code:

Code: Select all

static void sendNlsPktHandler(eventid_t id);
static void sendNhsPktHandler(eventid_t id);

static THD_FUNCTION(serialThread, param) {

  (void) param;
 
  static const evhandler_t evhndl[] = {
    sendNlsPktHandler,
    sendNhsPktHandler,
  };

  event_listener_t  el_nls;
  event_listener_t  el_nhs;
 
  chRegSetThreadName("SERIAL");

  chEvtRegister(&dispatcher_event_nls, &el_nls, 0);
  chEvtRegister(&dispatcher_event_nhs, &el_nhs, 1);

    while(TRUE) {
      chEvtDispatch(evhndl, chEvtWaitOneTimeout(ALL_EVENTS, TIME_MS2I(500)));
    }
}


Basically the above thread waits for two different events broadcast from other threads and processes them with two handlers.

My question is the following: is it right that, should the two events be broadcast at the same time, the two event handlers will be called one after the other? IOW, if, for example, both handlers access the same UART to send some data, canI avoid protecting such access with a mutex in order not to mess the two transmissions?

Thanks in advance.
Alberto

Re: Multiple events management

Posted: Mon Apr 08, 2019 6:41 pm
by Giovanni
Hi,

The two handlers would be called in sequence and in the context of the same thread. There is no need of mutex unless also other threads can access the same UART and, note, there are uartAcquireBus() and uartReleaseBus() for that.

Events handling is synchronous, sequential and not concurrent.

Giovanni

Re: Multiple events management

Posted: Mon Apr 08, 2019 7:31 pm
by bitto
Thanks a lot.

I think I may start getting a grip on events.

Alberto