Commit f191e3b4 authored by Bob Halley's avatar Bob Halley
Browse files

Switch from BROADCAST to SIGNAL in many cases; hold lock while doing either.

parent 0bbadb0a
......@@ -28,6 +28,8 @@
INSIST(isc_mutex_unlock((lp)) == ISC_R_SUCCESS);
#define BROADCAST(cvp) \
INSIST(isc_condition_broadcast((cvp)) == ISC_R_SUCCESS);
#define SIGNAL(cvp) \
INSIST(isc_condition_signal((cvp)) == ISC_R_SUCCESS);
#define WAIT(cvp, lp) \
INSIST(isc_condition_wait((cvp), (lp)) == ISC_R_SUCCESS);
#define WAITUNTIL(cvp, lp, tp, bp) \
......@@ -303,7 +305,6 @@ isc_task_send(isc_task_t task, isc_event_t *eventp) {
}
if (was_idle) {
isc_boolean_t need_wakeup = ISC_FALSE;
isc_taskmgr_t manager;
/*
......@@ -328,18 +329,9 @@ isc_task_send(isc_task_t task, isc_event_t *eventp) {
manager = task->manager;
INSIST(VALID_MANAGER(manager));
LOCK(&manager->lock);
if (EMPTY(manager->ready_tasks))
need_wakeup = ISC_TRUE;
ENQUEUE(manager->ready_tasks, task, ready_link);
SIGNAL(&manager->work_available);
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;
......@@ -416,19 +408,14 @@ isc_task_shutdown(isc_task_t task) {
return;
if (was_idle) {
isc_boolean_t need_wakeup = ISC_FALSE;
isc_taskmgr_t manager;
manager = task->manager;
INSIST(VALID_MANAGER(manager));
LOCK(&manager->lock);
if (EMPTY(manager->ready_tasks))
need_wakeup = ISC_TRUE;
ENQUEUE(manager->ready_tasks, task, ready_link);
SIGNAL(&manager->work_available);
UNLOCK(&manager->lock);
if (need_wakeup)
BROADCAST(&manager->work_available);
}
}
......
......@@ -26,6 +26,8 @@
INSIST(isc_mutex_unlock((lp)) == ISC_R_SUCCESS);
#define BROADCAST(cvp) \
INSIST(isc_condition_broadcast((cvp)) == ISC_R_SUCCESS);
#define SIGNAL(cvp) \
INSIST(isc_condition_signal((cvp)) == ISC_R_SUCCESS);
#define WAIT(cvp, lp) \
INSIST(isc_condition_wait((cvp), (lp)) == ISC_R_SUCCESS);
#define WAITUNTIL(cvp, lp, tp) \
......@@ -91,7 +93,7 @@ struct isc_timermgr {
};
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_timermgr_t manager;
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
* want it to oversleep.
*/
if (timer->index == 1 && broadcast_ok) {
XTRACE("broadcast (schedule)");
BROADCAST(&manager->wakeup);
if (timer->index == 1 && signal_ok) {
XTRACE("signal (schedule)");
SIGNAL(&manager->wakeup);
}
return (ISC_R_SUCCESS);
......@@ -182,8 +184,8 @@ deschedule(isc_timer_t timer) {
INSIST(manager->nscheduled > 0);
manager->nscheduled--;
if (need_wakeup) {
XTRACE("broadcast (deschedule)");
BROADCAST(&manager->wakeup);
XTRACE("signal (deschedule)");
SIGNAL(&manager->wakeup);
}
}
}
......@@ -620,8 +622,8 @@ isc_timermgr_destroy(isc_timermgr_t *managerp) {
UNLOCK(&manager->lock);
XTRACE("broadcast (destroy)");
BROADCAST(&manager->wakeup);
XTRACE("signal (destroy)");
SIGNAL(&manager->wakeup);
/*
* Wait for thread to exit.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment