diff --git a/sched/wqueue/kwork_queue.c b/sched/wqueue/kwork_queue.c index 1ced5c797e2..401ccba2649 100644 --- a/sched/wqueue/kwork_queue.c +++ b/sched/wqueue/kwork_queue.c @@ -140,6 +140,7 @@ int work_queue_wq(FAR struct kwork_wqueue_s *wqueue, FAR void *arg, clock_t delay) { irqstate_t flags; + int ret = OK; if (wqueue == NULL || work == NULL || worker == NULL) { @@ -151,6 +152,7 @@ int work_queue_wq(FAR struct kwork_wqueue_s *wqueue, */ flags = spin_lock_irqsave(&wqueue->lock); + sched_lock(); /* Remove the entry from the timer and work queue. */ @@ -170,8 +172,7 @@ int work_queue_wq(FAR struct kwork_wqueue_s *wqueue, if (work_is_canceling(wqueue->worker, wqueue->nthreads, work)) { - spin_unlock_irqrestore(&wqueue->lock, flags); - return 0; + goto out; } /* Initialize the work structure. */ @@ -184,18 +185,17 @@ int work_queue_wq(FAR struct kwork_wqueue_s *wqueue, if (!delay) { - sched_lock(); queue_work(wqueue, work); - spin_unlock_irqrestore(&wqueue->lock, flags); - sched_unlock(); } else { wd_start(&work->u.timer, delay, work_timer_expiry, (wdparm_t)work); - spin_unlock_irqrestore(&wqueue->lock, flags); } - return 0; +out: + spin_unlock_irqrestore(&wqueue->lock, flags); + sched_unlock(); + return ret; } int work_queue(int qid, FAR struct work_s *work, worker_t worker, diff --git a/sched/wqueue/kwork_thread.c b/sched/wqueue/kwork_thread.c index 74e3b8b2942..19585f0b28d 100644 --- a/sched/wqueue/kwork_thread.c +++ b/sched/wqueue/kwork_thread.c @@ -149,6 +149,7 @@ static int work_thread(int argc, FAR char *argv[]) ((uintptr_t)strtoul(argv[2], NULL, 16)); flags = spin_lock_irqsave(&wqueue->lock); + sched_lock(); /* Loop forever */ @@ -191,10 +192,11 @@ static int work_thread(int argc, FAR char *argv[]) */ spin_unlock_irqrestore(&wqueue->lock, flags); + sched_unlock(); CALL_WORKER(worker, arg); - flags = spin_lock_irqsave(&wqueue->lock); + sched_lock(); /* Mark the thread un-busy */ @@ -205,9 +207,7 @@ static int work_thread(int argc, FAR char *argv[]) while (kworker->wait_count > 0) { kworker->wait_count--; - sched_lock(); nxsem_post(&kworker->wait); - sched_unlock(); } } @@ -217,18 +217,19 @@ static int work_thread(int argc, FAR char *argv[]) */ wqueue->wait_count++; - spin_unlock_irqrestore(&wqueue->lock, flags); + sched_unlock(); nxsem_wait_uninterruptible(&wqueue->sem); - flags = spin_lock_irqsave(&wqueue->lock); + sched_lock(); } spin_unlock_irqrestore(&wqueue->lock, flags); + sched_unlock(); nxsem_post(&wqueue->exsem); - return 0; + return OK; } /**************************************************************************** @@ -291,7 +292,7 @@ static int work_thread_create(FAR const char *name, int priority, } sched_unlock(); - return 0; + return OK; } /**************************************************************************** @@ -407,7 +408,7 @@ int work_queue_free(FAR struct kwork_wqueue_s *wqueue) nxsem_destroy(&wqueue->exsem); kmm_free(wqueue); - return 0; + return OK; } /****************************************************************************