mirror of
https://gitlab.isc.org/isc-projects/bind9
synced 2025-09-04 08:35:31 +00:00
Use proper memory ordering for tasks_running/tasks_ready
This commit is contained in:
@@ -915,7 +915,8 @@ push_readyq(isc__taskmgr_t *manager, isc__task_t *task, int c) {
|
|||||||
if ((task->flags & TASK_F_PRIVILEGED) != 0)
|
if ((task->flags & TASK_F_PRIVILEGED) != 0)
|
||||||
ENQUEUE(manager->queues[c].ready_priority_tasks, task,
|
ENQUEUE(manager->queues[c].ready_priority_tasks, task,
|
||||||
ready_priority_link);
|
ready_priority_link);
|
||||||
atomic_fetch_add_explicit(&manager->tasks_ready, 1, memory_order_relaxed);
|
atomic_fetch_add_explicit(&manager->tasks_ready, 1,
|
||||||
|
memory_order_acquire);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@@ -1051,13 +1052,15 @@ dispatch(isc__taskmgr_t *manager, unsigned int threadid) {
|
|||||||
INSIST(VALID_TASK(task));
|
INSIST(VALID_TASK(task));
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Note we only unlock the manager lock if we actually
|
* Note we only unlock the queue lock if we actually
|
||||||
* have a task to do. We must reacquire the manager
|
* have a task to do. We must reacquire the queue
|
||||||
* lock before exiting the 'if (task != NULL)' block.
|
* lock before exiting the 'if (task != NULL)' block.
|
||||||
*/
|
*/
|
||||||
UNLOCK(&manager->queues[threadid].lock);
|
UNLOCK(&manager->queues[threadid].lock);
|
||||||
atomic_fetch_add_explicit(&manager->tasks_ready, -1, memory_order_relaxed);
|
RUNTIME_CHECK(atomic_fetch_sub_explicit(&manager->tasks_ready,
|
||||||
atomic_fetch_add_explicit(&manager->tasks_running, 1, memory_order_relaxed);
|
1, memory_order_release) > 0);
|
||||||
|
atomic_fetch_add_explicit(&manager->tasks_running, 1,
|
||||||
|
memory_order_acquire);
|
||||||
|
|
||||||
LOCK(&task->lock);
|
LOCK(&task->lock);
|
||||||
INSIST(task->state == task_state_ready);
|
INSIST(task->state == task_state_ready);
|
||||||
@@ -1171,7 +1174,8 @@ dispatch(isc__taskmgr_t *manager, unsigned int threadid) {
|
|||||||
if (finished)
|
if (finished)
|
||||||
task_finished(task);
|
task_finished(task);
|
||||||
|
|
||||||
atomic_fetch_add_explicit(&manager->tasks_running, -1, memory_order_relaxed);
|
RUNTIME_CHECK(atomic_fetch_sub_explicit(&manager->tasks_running,
|
||||||
|
1, memory_order_release) > 0);
|
||||||
LOCK(&manager->queues[threadid].lock);
|
LOCK(&manager->queues[threadid].lock);
|
||||||
if (requeue) {
|
if (requeue) {
|
||||||
/*
|
/*
|
||||||
@@ -1203,7 +1207,10 @@ dispatch(isc__taskmgr_t *manager, unsigned int threadid) {
|
|||||||
* we're stuck. Automatically drop privileges at that
|
* we're stuck. Automatically drop privileges at that
|
||||||
* point and continue with the regular ready queue.
|
* point and continue with the regular ready queue.
|
||||||
*/
|
*/
|
||||||
if (atomic_load(&manager->tasks_running) == 0 && manager->mode != isc_taskmgrmode_normal) {
|
if (atomic_load_explicit(&manager->tasks_running,
|
||||||
|
memory_order_acquire) == 0 &&
|
||||||
|
manager->mode != isc_taskmgrmode_normal)
|
||||||
|
{
|
||||||
bool empty = true;
|
bool empty = true;
|
||||||
for (unsigned i=0; i<manager->workers && empty; i++) {
|
for (unsigned i=0; i<manager->workers && empty; i++) {
|
||||||
if (i != threadid) {
|
if (i != threadid) {
|
||||||
|
Reference in New Issue
Block a user