mirror of
https://gitlab.isc.org/isc-projects/bind9
synced 2025-09-02 07:35:26 +00:00
Switch from BROADCAST to SIGNAL in many cases; hold lock while doing either.
This commit is contained in:
@@ -28,6 +28,8 @@
|
|||||||
INSIST(isc_mutex_unlock((lp)) == ISC_R_SUCCESS);
|
INSIST(isc_mutex_unlock((lp)) == ISC_R_SUCCESS);
|
||||||
#define BROADCAST(cvp) \
|
#define BROADCAST(cvp) \
|
||||||
INSIST(isc_condition_broadcast((cvp)) == ISC_R_SUCCESS);
|
INSIST(isc_condition_broadcast((cvp)) == ISC_R_SUCCESS);
|
||||||
|
#define SIGNAL(cvp) \
|
||||||
|
INSIST(isc_condition_signal((cvp)) == ISC_R_SUCCESS);
|
||||||
#define WAIT(cvp, lp) \
|
#define WAIT(cvp, lp) \
|
||||||
INSIST(isc_condition_wait((cvp), (lp)) == ISC_R_SUCCESS);
|
INSIST(isc_condition_wait((cvp), (lp)) == ISC_R_SUCCESS);
|
||||||
#define WAITUNTIL(cvp, lp, tp, bp) \
|
#define WAITUNTIL(cvp, lp, tp, bp) \
|
||||||
@@ -303,7 +305,6 @@ isc_task_send(isc_task_t task, isc_event_t *eventp) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (was_idle) {
|
if (was_idle) {
|
||||||
isc_boolean_t need_wakeup = ISC_FALSE;
|
|
||||||
isc_taskmgr_t manager;
|
isc_taskmgr_t manager;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -328,18 +329,9 @@ isc_task_send(isc_task_t task, isc_event_t *eventp) {
|
|||||||
manager = task->manager;
|
manager = task->manager;
|
||||||
INSIST(VALID_MANAGER(manager));
|
INSIST(VALID_MANAGER(manager));
|
||||||
LOCK(&manager->lock);
|
LOCK(&manager->lock);
|
||||||
if (EMPTY(manager->ready_tasks))
|
|
||||||
need_wakeup = ISC_TRUE;
|
|
||||||
ENQUEUE(manager->ready_tasks, task, ready_link);
|
ENQUEUE(manager->ready_tasks, task, ready_link);
|
||||||
|
SIGNAL(&manager->work_available);
|
||||||
UNLOCK(&manager->lock);
|
UNLOCK(&manager->lock);
|
||||||
|
|
||||||
/*
|
|
||||||
* If the runnable queue is empty, the worker threads could
|
|
||||||
* either be executing tasks or waiting for something to do.
|
|
||||||
* We wakeup anyone who is sleeping.
|
|
||||||
*/
|
|
||||||
if (need_wakeup)
|
|
||||||
BROADCAST(&manager->work_available);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
*eventp = NULL;
|
*eventp = NULL;
|
||||||
@@ -416,19 +408,14 @@ isc_task_shutdown(isc_task_t task) {
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
if (was_idle) {
|
if (was_idle) {
|
||||||
isc_boolean_t need_wakeup = ISC_FALSE;
|
|
||||||
isc_taskmgr_t manager;
|
isc_taskmgr_t manager;
|
||||||
|
|
||||||
manager = task->manager;
|
manager = task->manager;
|
||||||
INSIST(VALID_MANAGER(manager));
|
INSIST(VALID_MANAGER(manager));
|
||||||
LOCK(&manager->lock);
|
LOCK(&manager->lock);
|
||||||
if (EMPTY(manager->ready_tasks))
|
|
||||||
need_wakeup = ISC_TRUE;
|
|
||||||
ENQUEUE(manager->ready_tasks, task, ready_link);
|
ENQUEUE(manager->ready_tasks, task, ready_link);
|
||||||
|
SIGNAL(&manager->work_available);
|
||||||
UNLOCK(&manager->lock);
|
UNLOCK(&manager->lock);
|
||||||
|
|
||||||
if (need_wakeup)
|
|
||||||
BROADCAST(&manager->work_available);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -26,6 +26,8 @@
|
|||||||
INSIST(isc_mutex_unlock((lp)) == ISC_R_SUCCESS);
|
INSIST(isc_mutex_unlock((lp)) == ISC_R_SUCCESS);
|
||||||
#define BROADCAST(cvp) \
|
#define BROADCAST(cvp) \
|
||||||
INSIST(isc_condition_broadcast((cvp)) == ISC_R_SUCCESS);
|
INSIST(isc_condition_broadcast((cvp)) == ISC_R_SUCCESS);
|
||||||
|
#define SIGNAL(cvp) \
|
||||||
|
INSIST(isc_condition_signal((cvp)) == ISC_R_SUCCESS);
|
||||||
#define WAIT(cvp, lp) \
|
#define WAIT(cvp, lp) \
|
||||||
INSIST(isc_condition_wait((cvp), (lp)) == ISC_R_SUCCESS);
|
INSIST(isc_condition_wait((cvp), (lp)) == ISC_R_SUCCESS);
|
||||||
#define WAITUNTIL(cvp, lp, tp) \
|
#define WAITUNTIL(cvp, lp, tp) \
|
||||||
@@ -91,7 +93,7 @@ struct isc_timermgr {
|
|||||||
};
|
};
|
||||||
|
|
||||||
static inline isc_result
|
static inline isc_result
|
||||||
schedule(isc_timer_t timer, isc_time_t now, isc_boolean_t broadcast_ok) {
|
schedule(isc_timer_t timer, isc_time_t now, isc_boolean_t signal_ok) {
|
||||||
isc_result result;
|
isc_result result;
|
||||||
isc_timermgr_t manager;
|
isc_timermgr_t manager;
|
||||||
struct isc_time due;
|
struct isc_time due;
|
||||||
@@ -156,9 +158,9 @@ schedule(isc_timer_t timer, isc_time_t now, isc_boolean_t broadcast_ok) {
|
|||||||
* due time than the one the run thread is sleeping on, and we don't
|
* due time than the one the run thread is sleeping on, and we don't
|
||||||
* want it to oversleep.
|
* want it to oversleep.
|
||||||
*/
|
*/
|
||||||
if (timer->index == 1 && broadcast_ok) {
|
if (timer->index == 1 && signal_ok) {
|
||||||
XTRACE("broadcast (schedule)");
|
XTRACE("signal (schedule)");
|
||||||
BROADCAST(&manager->wakeup);
|
SIGNAL(&manager->wakeup);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (ISC_R_SUCCESS);
|
return (ISC_R_SUCCESS);
|
||||||
@@ -182,8 +184,8 @@ deschedule(isc_timer_t timer) {
|
|||||||
INSIST(manager->nscheduled > 0);
|
INSIST(manager->nscheduled > 0);
|
||||||
manager->nscheduled--;
|
manager->nscheduled--;
|
||||||
if (need_wakeup) {
|
if (need_wakeup) {
|
||||||
XTRACE("broadcast (deschedule)");
|
XTRACE("signal (deschedule)");
|
||||||
BROADCAST(&manager->wakeup);
|
SIGNAL(&manager->wakeup);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -620,8 +622,8 @@ isc_timermgr_destroy(isc_timermgr_t *managerp) {
|
|||||||
|
|
||||||
UNLOCK(&manager->lock);
|
UNLOCK(&manager->lock);
|
||||||
|
|
||||||
XTRACE("broadcast (destroy)");
|
XTRACE("signal (destroy)");
|
||||||
BROADCAST(&manager->wakeup);
|
SIGNAL(&manager->wakeup);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Wait for thread to exit.
|
* Wait for thread to exit.
|
||||||
|
Reference in New Issue
Block a user