mirror of
https://github.com/apache/nuttx.git
synced 2026-05-28 03:45:50 +08:00
Revert "sched/wqueue: some minor improve to reduce sched_lock range"
This reverts commit 2779989add.
This commit is contained in:
@@ -140,6 +140,7 @@ int work_queue_wq(FAR struct kwork_wqueue_s *wqueue,
|
|||||||
FAR void *arg, clock_t delay)
|
FAR void *arg, clock_t delay)
|
||||||
{
|
{
|
||||||
irqstate_t flags;
|
irqstate_t flags;
|
||||||
|
int ret = OK;
|
||||||
|
|
||||||
if (wqueue == NULL || work == NULL || worker == NULL)
|
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);
|
flags = spin_lock_irqsave(&wqueue->lock);
|
||||||
|
sched_lock();
|
||||||
|
|
||||||
/* Remove the entry from the timer and work queue. */
|
/* 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))
|
if (work_is_canceling(wqueue->worker, wqueue->nthreads, work))
|
||||||
{
|
{
|
||||||
spin_unlock_irqrestore(&wqueue->lock, flags);
|
goto out;
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Initialize the work structure. */
|
/* Initialize the work structure. */
|
||||||
@@ -184,18 +185,17 @@ int work_queue_wq(FAR struct kwork_wqueue_s *wqueue,
|
|||||||
|
|
||||||
if (!delay)
|
if (!delay)
|
||||||
{
|
{
|
||||||
sched_lock();
|
|
||||||
queue_work(wqueue, work);
|
queue_work(wqueue, work);
|
||||||
spin_unlock_irqrestore(&wqueue->lock, flags);
|
|
||||||
sched_unlock();
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
wd_start(&work->u.timer, delay, work_timer_expiry, (wdparm_t)work);
|
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,
|
int work_queue(int qid, FAR struct work_s *work, worker_t worker,
|
||||||
|
|||||||
@@ -149,6 +149,7 @@ static int work_thread(int argc, FAR char *argv[])
|
|||||||
((uintptr_t)strtoul(argv[2], NULL, 16));
|
((uintptr_t)strtoul(argv[2], NULL, 16));
|
||||||
|
|
||||||
flags = spin_lock_irqsave(&wqueue->lock);
|
flags = spin_lock_irqsave(&wqueue->lock);
|
||||||
|
sched_lock();
|
||||||
|
|
||||||
/* Loop forever */
|
/* Loop forever */
|
||||||
|
|
||||||
@@ -191,10 +192,11 @@ static int work_thread(int argc, FAR char *argv[])
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
spin_unlock_irqrestore(&wqueue->lock, flags);
|
spin_unlock_irqrestore(&wqueue->lock, flags);
|
||||||
|
sched_unlock();
|
||||||
|
|
||||||
CALL_WORKER(worker, arg);
|
CALL_WORKER(worker, arg);
|
||||||
|
|
||||||
flags = spin_lock_irqsave(&wqueue->lock);
|
flags = spin_lock_irqsave(&wqueue->lock);
|
||||||
|
sched_lock();
|
||||||
|
|
||||||
/* Mark the thread un-busy */
|
/* Mark the thread un-busy */
|
||||||
|
|
||||||
@@ -205,9 +207,7 @@ static int work_thread(int argc, FAR char *argv[])
|
|||||||
while (kworker->wait_count > 0)
|
while (kworker->wait_count > 0)
|
||||||
{
|
{
|
||||||
kworker->wait_count--;
|
kworker->wait_count--;
|
||||||
sched_lock();
|
|
||||||
nxsem_post(&kworker->wait);
|
nxsem_post(&kworker->wait);
|
||||||
sched_unlock();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -217,18 +217,19 @@ static int work_thread(int argc, FAR char *argv[])
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
wqueue->wait_count++;
|
wqueue->wait_count++;
|
||||||
|
|
||||||
spin_unlock_irqrestore(&wqueue->lock, flags);
|
spin_unlock_irqrestore(&wqueue->lock, flags);
|
||||||
|
sched_unlock();
|
||||||
|
|
||||||
nxsem_wait_uninterruptible(&wqueue->sem);
|
nxsem_wait_uninterruptible(&wqueue->sem);
|
||||||
|
|
||||||
flags = spin_lock_irqsave(&wqueue->lock);
|
flags = spin_lock_irqsave(&wqueue->lock);
|
||||||
|
sched_lock();
|
||||||
}
|
}
|
||||||
|
|
||||||
spin_unlock_irqrestore(&wqueue->lock, flags);
|
spin_unlock_irqrestore(&wqueue->lock, flags);
|
||||||
|
sched_unlock();
|
||||||
|
|
||||||
nxsem_post(&wqueue->exsem);
|
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();
|
sched_unlock();
|
||||||
return 0;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
@@ -407,7 +408,7 @@ int work_queue_free(FAR struct kwork_wqueue_s *wqueue)
|
|||||||
nxsem_destroy(&wqueue->exsem);
|
nxsem_destroy(&wqueue->exsem);
|
||||||
kmm_free(wqueue);
|
kmm_free(wqueue);
|
||||||
|
|
||||||
return 0;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
|
|||||||
Reference in New Issue
Block a user