To clear event(s) of another thread

Discussions and support about ChibiOS/RT, the free embedded RTOS.
Post Reply
xiaomin
Posts: 6
Joined: Mon Jul 24, 2017 1:43 pm
Has thanked: 1 time

To clear event(s) of another thread

Post by xiaomin »

chibi RT provides API to clear event in current task with chEvtGetAndClearEvents(eventmask_t). Now what I need is to clear event(s) of another thread. Suppose I know the thread reference, it seems I can just lock and directly manipulate thd->epending &= ~event. But is it safe? Shall I check thread priority? Shall I check whether the other thread is already in ready to run list? Is there any other protection I should add?
User avatar
Giovanni
Site Admin
Posts: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: To clear event(s) of another thread

Post by Giovanni »

Hi,

It would be safe if done in a critical zone, so use chSysLock/Unlock.

Giovanni
faisal
Posts: 382
Joined: Wed Jul 19, 2017 12:44 am
Has thanked: 45 times
Been thanked: 62 times

Re: To clear event(s) of another thread

Post by faisal »

Giovanni wrote:Hi,

It would be safe if done in a critical zone, so use chSysLock/Unlock.

Giovanni


Wouldn't one also need to preform a reschedule before exiting the critical zone?
User avatar
Giovanni
Site Admin
Posts: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: To clear event(s) of another thread

Post by Giovanni »

Clearing events would not wake up a thread so rescheduling is not required. It only has to be performed after that the state of the ready list has changed, usually after calling chSchReadyI().

Giovanni
Post Reply