Capturing events/signals in delegate/worker threads

This forum is dedicated to feedback, discussions about ongoing or future developments, ideas and suggestions regarding the ChibiOS projects are welcome. This forum is NOT for support.
faisal
Posts: 374
Joined: Wed Jul 19, 2017 12:44 am
Has thanked: 44 times
Been thanked: 60 times

Capturing events/signals in delegate/worker threads

Postby faisal » Thu Jan 06, 2022 4:34 pm

An API to configure a delegate thread to capture a signal/event and call a callback function would be useful.

User avatar
Giovanni
Site Admin
Posts: 14444
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1074 times
Been thanked: 921 times
Contact:

Re: Capturing events/signals in delegate/worker threads

Postby Giovanni » Thu Jan 06, 2022 5:13 pm

Hi,

You mean while doing chDelegateDispatch() ?

Giovanni

faisal
Posts: 374
Joined: Wed Jul 19, 2017 12:44 am
Has thanked: 44 times
Been thanked: 60 times

Re: Capturing events/signals in delegate/worker threads

Postby faisal » Thu Jan 06, 2022 5:59 pm

Something like:

Code: Select all

/* from client - the eventual handler for the event */
void callback_on_event (void) {
  /* This gets called by the delegate/worker thread
    * once the event is generated by other_module_generate_event()
    */
}

void setup_callback_on_event() {
  thread_t * thd;
  event_id id;
  chDelegate_allocate_thread_signal (&thd, &id, callback_on_event);
  other_module_use_this_thread_signal(thd, id);
}

/* in other module which generates the event */
void other_module_use_this_thread_signal(thread_t * thd, eventid_t id) {
  stored_thd = thd;
  stored_id = id;
}

void other_module_generate_event (void) {
  chEvtSignal(stored_thd, EVENT_MASK(stored_id))
}



You would need something to allocate event ids, and register a callback for each ID. chEvtDispatch() can be used to process the incoming events. Just need an API to populate the eventhandler_t[], and return back an allocated eventid and thread_t - which the client can then go and give to event sources.


Return to “Development and Feedback”

Who is online

Users browsing this forum: No registered users and 18 guests