From 49e725625ae9a08f7b2953aeb7e6714f8cc9b4b2 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Fri, 14 Sep 2018 07:51:31 -0600 Subject: [PATCH] libs/libc/wqueue/work_usrthread.c: Eliminate a race condition noted by Xiang Xiao. --- libs/libc/wqueue/work_usrthread.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/libs/libc/wqueue/work_usrthread.c b/libs/libc/wqueue/work_usrthread.c index 8918ccc9ac6..e28a4a20cad 100644 --- a/libs/libc/wqueue/work_usrthread.c +++ b/libs/libc/wqueue/work_usrthread.c @@ -255,6 +255,14 @@ void work_process(FAR struct usr_wqueue_s *wqueue) } } + /* Unlock the work queue before waiting. In order to assure that these + * operations are atomic with respect to other user tasks, we disable + * pre-emption here. Pre-emption will be re-enabled while we sleep. + */ + + sched_lock(); + work_unlock(); + if (next == WORK_DELAY_MAX) { sigset_t set; @@ -276,7 +284,7 @@ void work_process(FAR struct usr_wqueue_s *wqueue) usleep(next * USEC_PER_TICK); } - work_unlock(); + sched_unlock(); } /****************************************************************************