From d26355fbb41cdc0cb6a5af17901cd7e95a58bd8a Mon Sep 17 00:00:00 2001 From: Martine Lenders Date: Fri, 21 Feb 2020 15:50:30 +0100 Subject: [PATCH] sock_async_event: fix race-condition If a new event is fired during the execution of the event callback, `event->type` might change. However as `event->type` is set to 0 after the execution of the callback, that leads to it being 0 on the next round of the event handler's execution, leading in the event getting lost. --- sys/net/sock/async/event/sock_async_event.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/sys/net/sock/async/event/sock_async_event.c b/sys/net/sock/async/event/sock_async_event.c index e7b3666b0f..f2e7d6673d 100644 --- a/sys/net/sock/async/event/sock_async_event.c +++ b/sys/net/sock/async/event/sock_async_event.c @@ -13,14 +13,20 @@ * @author Martine Lenders */ +#include "irq.h" #include "net/sock/async/event.h" static void _event_handler(event_t *ev) { sock_event_t *event = (sock_event_t *)ev; + unsigned state = irq_disable(); + sock_async_flags_t _type = event->type; - event->cb.generic(event->sock, event->type); event->type = 0; + irq_restore(state); + if (_type) { + event->cb.generic(event->sock, _type); + } } static inline void _cb(void *sock, sock_async_flags_t type,