summaryrefslogtreecommitdiffstats
path: root/usr.sbin/bind/lib/isc/timer.c
diff options
context:
space:
mode:
authorflorian <florian@openbsd.org>2020-01-20 18:45:29 +0000
committerflorian <florian@openbsd.org>2020-01-20 18:45:29 +0000
commitfa3a1816afb93dde45ab942fddbaf1c47288305c (patch)
treed4c1325a99ecec92b8537b6d7b3c9779d5cc2ef2 /usr.sbin/bind/lib/isc/timer.c
parentRemove unused tm.c (diff)
downloadwireguard-openbsd-fa3a1816afb93dde45ab942fddbaf1c47288305c.tar.xz
wireguard-openbsd-fa3a1816afb93dde45ab942fddbaf1c47288305c.zip
unifdef threading related defines
input & OK millert
Diffstat (limited to 'usr.sbin/bind/lib/isc/timer.c')
-rw-r--r--usr.sbin/bind/lib/isc/timer.c190
1 files changed, 1 insertions, 189 deletions
diff --git a/usr.sbin/bind/lib/isc/timer.c b/usr.sbin/bind/lib/isc/timer.c
index c79d958000e..2272b1bac8b 100644
--- a/usr.sbin/bind/lib/isc/timer.c
+++ b/usr.sbin/bind/lib/isc/timer.c
@@ -14,7 +14,7 @@
* PERFORMANCE OF THIS SOFTWARE.
*/
-/* $Id: timer.c,v 1.9 2020/01/09 18:17:19 florian Exp $ */
+/* $Id: timer.c,v 1.10 2020/01/20 18:45:29 florian Exp $ */
/*! \file */
@@ -36,12 +36,7 @@
#include <isc/timer.h>
#include <isc/util.h>
-/* See task.c about the following definition: */
-#define USE_SHARED_MANAGER
-
-#ifndef USE_TIMER_THREAD
#include "timer_p.h"
-#endif /* USE_TIMER_THREAD */
#ifdef ISC_TIMER_TRACE
#define XTRACE(s) fprintf(stderr, "%s\n", (s))
@@ -99,13 +94,7 @@ struct isc__timermgr {
LIST(isc__timer_t) timers;
unsigned int nscheduled;
isc_time_t due;
-#ifdef USE_TIMER_THREAD
- isc_condition_t wakeup;
- isc_thread_t thread;
-#endif /* USE_TIMER_THREAD */
-#ifdef USE_SHARED_MANAGER
unsigned int refs;
-#endif /* USE_SHARED_MANAGER */
isc_heap_t * heap;
};
@@ -167,12 +156,10 @@ static struct isc__timermgrmethods {
(void *)isc_timermgr_poke
};
-#ifdef USE_SHARED_MANAGER
/*!
* If the manager is supposed to be shared, there can be only one.
*/
static isc__timermgr_t *timermgr = NULL;
-#endif /* USE_SHARED_MANAGER */
static inline isc_result_t
schedule(isc__timer_t *timer, isc_time_t *now, isc_boolean_t signal_ok) {
@@ -180,9 +167,6 @@ schedule(isc__timer_t *timer, isc_time_t *now, isc_boolean_t signal_ok) {
isc__timermgr_t *manager;
isc_time_t due;
int cmp;
-#ifdef USE_TIMER_THREAD
- isc_boolean_t timedwait;
-#endif
/*!
* Note: the caller must ensure locking.
@@ -190,21 +174,10 @@ schedule(isc__timer_t *timer, isc_time_t *now, isc_boolean_t signal_ok) {
REQUIRE(timer->type != isc_timertype_inactive);
-#ifndef USE_TIMER_THREAD
UNUSED(signal_ok);
-#endif /* USE_TIMER_THREAD */
manager = timer->manager;
-#ifdef USE_TIMER_THREAD
- /*!
- * If the manager was timed wait, we may need to signal the
- * manager to force a wakeup.
- */
- timedwait = ISC_TF(manager->nscheduled > 0 &&
- isc_time_seconds(&manager->due) != 0);
-#endif
-
/*
* Compute the new due time.
*/
@@ -266,53 +239,15 @@ schedule(isc__timer_t *timer, isc_time_t *now, isc_boolean_t signal_ok) {
* the current "next" timer. We do this either by waking up the
* run thread, or explicitly setting the value in the manager.
*/
-#ifdef USE_TIMER_THREAD
-
- /*
- * This is a temporary (probably) hack to fix a bug on tru64 5.1
- * and 5.1a. Sometimes, pthread_cond_timedwait() doesn't actually
- * return when the time expires, so here, we check to see if
- * we're 15 seconds or more behind, and if we are, we signal
- * the dispatcher. This isn't such a bad idea as a general purpose
- * watchdog, so perhaps we should just leave it in here.
- */
- if (signal_ok && timedwait) {
- interval_t fifteen;
- isc_time_t then;
-
- interval_set(&fifteen, 15, 0);
- result = isc_time_add(&manager->due, &fifteen, &then);
-
- if (result == ISC_R_SUCCESS &&
- isc_time_compare(&then, now) < 0) {
- SIGNAL(&manager->wakeup);
- signal_ok = ISC_FALSE;
- isc_log_write(isc_lctx, ISC_LOGCATEGORY_GENERAL,
- ISC_LOGMODULE_TIMER, ISC_LOG_WARNING,
- "*** POKED TIMER ***");
- }
- }
-
- if (timer->index == 1 && signal_ok) {
- XTRACE(isc_msgcat_get(isc_msgcat, ISC_MSGSET_TIMER,
- ISC_MSG_SIGNALSCHED,
- "signal (schedule)"));
- SIGNAL(&manager->wakeup);
- }
-#else /* USE_TIMER_THREAD */
if (timer->index == 1 &&
isc_time_compare(&timer->due, &manager->due) < 0)
manager->due = timer->due;
-#endif /* USE_TIMER_THREAD */
return (ISC_R_SUCCESS);
}
static inline void
deschedule(isc__timer_t *timer) {
-#ifdef USE_TIMER_THREAD
- isc_boolean_t need_wakeup = ISC_FALSE;
-#endif
isc__timermgr_t *manager;
/*
@@ -321,22 +256,10 @@ deschedule(isc__timer_t *timer) {
manager = timer->manager;
if (timer->index > 0) {
-#ifdef USE_TIMER_THREAD
- if (timer->index == 1)
- need_wakeup = ISC_TRUE;
-#endif
isc_heap_delete(manager->heap, timer->index);
timer->index = 0;
INSIST(manager->nscheduled > 0);
manager->nscheduled--;
-#ifdef USE_TIMER_THREAD
- if (need_wakeup) {
- XTRACE(isc_msgcat_get(isc_msgcat, ISC_MSGSET_TIMER,
- ISC_MSG_SIGNALDESCHED,
- "signal (deschedule)"));
- SIGNAL(&manager->wakeup);
- }
-#endif /* USE_TIMER_THREAD */
}
}
@@ -773,46 +696,6 @@ dispatch(isc__timermgr_t *manager, isc_time_t *now) {
}
}
-#ifdef USE_TIMER_THREAD
-static isc_threadresult_t
-run(void *uap) {
- isc__timermgr_t *manager = uap;
- isc_time_t now;
- isc_result_t result;
-
- LOCK(&manager->lock);
- while (!manager->done) {
- TIME_NOW(&now);
-
- XTRACETIME(isc_msgcat_get(isc_msgcat, ISC_MSGSET_GENERAL,
- ISC_MSG_RUNNING,
- "running"), now);
-
- dispatch(manager, &now);
-
- if (manager->nscheduled > 0) {
- XTRACETIME2(isc_msgcat_get(isc_msgcat,
- ISC_MSGSET_GENERAL,
- ISC_MSG_WAITUNTIL,
- "waituntil"),
- manager->due, now);
- result = WAITUNTIL(&manager->wakeup, &manager->lock, &manager->due);
- INSIST(result == ISC_R_SUCCESS ||
- result == ISC_R_TIMEDOUT);
- } else {
- XTRACETIME(isc_msgcat_get(isc_msgcat, ISC_MSGSET_GENERAL,
- ISC_MSG_WAIT, "wait"), now);
- WAIT(&manager->wakeup, &manager->lock);
- }
- XTRACE(isc_msgcat_get(isc_msgcat, ISC_MSGSET_TIMER,
- ISC_MSG_WAKEUP, "wakeup"));
- }
- UNLOCK(&manager->lock);
-
- return ((isc_threadresult_t)0);
-}
-#endif /* USE_TIMER_THREAD */
-
static isc_boolean_t
sooner(void *v1, void *v2) {
isc__timer_t *t1, *t2;
@@ -848,13 +731,11 @@ isc__timermgr_create(isc_mem_t *mctx, isc_timermgr_t **managerp) {
REQUIRE(managerp != NULL && *managerp == NULL);
-#ifdef USE_SHARED_MANAGER
if (timermgr != NULL) {
timermgr->refs++;
*managerp = (isc_timermgr_t *)timermgr;
return (ISC_R_SUCCESS);
}
-#endif /* USE_SHARED_MANAGER */
manager = isc_mem_get(mctx, sizeof(*manager));
if (manager == NULL)
@@ -882,37 +763,8 @@ isc__timermgr_create(isc_mem_t *mctx, isc_timermgr_t **managerp) {
return (result);
}
isc_mem_attach(mctx, &manager->mctx);
-#ifdef USE_TIMER_THREAD
- if (isc_condition_init(&manager->wakeup) != ISC_R_SUCCESS) {
- isc_mem_detach(&manager->mctx);
- DESTROYLOCK(&manager->lock);
- isc_heap_destroy(&manager->heap);
- isc_mem_put(mctx, manager, sizeof(*manager));
- UNEXPECTED_ERROR(__FILE__, __LINE__,
- "isc_condition_init() %s",
- isc_msgcat_get(isc_msgcat, ISC_MSGSET_GENERAL,
- ISC_MSG_FAILED, "failed"));
- return (ISC_R_UNEXPECTED);
- }
- if (isc_thread_create(run, manager, &manager->thread) !=
- ISC_R_SUCCESS) {
- isc_mem_detach(&manager->mctx);
- (void)isc_condition_destroy(&manager->wakeup);
- DESTROYLOCK(&manager->lock);
- isc_heap_destroy(&manager->heap);
- isc_mem_put(mctx, manager, sizeof(*manager));
- UNEXPECTED_ERROR(__FILE__, __LINE__,
- "isc_thread_create() %s",
- isc_msgcat_get(isc_msgcat, ISC_MSGSET_GENERAL,
- ISC_MSG_FAILED, "failed"));
- return (ISC_R_UNEXPECTED);
- }
- isc_thread_setname(manager->thread, "isc-timer");
-#endif
-#ifdef USE_SHARED_MANAGER
manager->refs = 1;
timermgr = manager;
-#endif /* USE_SHARED_MANAGER */
*managerp = (isc_timermgr_t *)manager;
@@ -921,15 +773,7 @@ isc__timermgr_create(isc_mem_t *mctx, isc_timermgr_t **managerp) {
void
isc_timermgr_poke(isc_timermgr_t *manager0) {
-#ifdef USE_TIMER_THREAD
- isc__timermgr_t *manager = (isc__timermgr_t *)manager0;
-
- REQUIRE(VALID_MANAGER(manager));
-
- SIGNAL(&manager->wakeup);
-#else
UNUSED(manager0);
-#endif
}
void
@@ -947,7 +791,6 @@ isc__timermgr_destroy(isc_timermgr_t **managerp) {
LOCK(&manager->lock);
-#ifdef USE_SHARED_MANAGER
manager->refs--;
if (manager->refs > 0) {
UNLOCK(&manager->lock);
@@ -955,40 +798,17 @@ isc__timermgr_destroy(isc_timermgr_t **managerp) {
return;
}
timermgr = NULL;
-#endif /* USE_SHARED_MANAGER */
-#ifndef USE_TIMER_THREAD
isc__timermgr_dispatch((isc_timermgr_t *)manager);
-#endif
REQUIRE(EMPTY(manager->timers));
manager->done = ISC_TRUE;
-#ifdef USE_TIMER_THREAD
- XTRACE(isc_msgcat_get(isc_msgcat, ISC_MSGSET_TIMER,
- ISC_MSG_SIGNALDESTROY, "signal (destroy)"));
- SIGNAL(&manager->wakeup);
-#endif /* USE_TIMER_THREAD */
-
UNLOCK(&manager->lock);
-#ifdef USE_TIMER_THREAD
- /*
- * Wait for thread to exit.
- */
- if (isc_thread_join(manager->thread, NULL) != ISC_R_SUCCESS)
- UNEXPECTED_ERROR(__FILE__, __LINE__,
- "isc_thread_join() %s",
- isc_msgcat_get(isc_msgcat, ISC_MSGSET_GENERAL,
- ISC_MSG_FAILED, "failed"));
-#endif /* USE_TIMER_THREAD */
-
/*
* Clean up.
*/
-#ifdef USE_TIMER_THREAD
- (void)isc_condition_destroy(&manager->wakeup);
-#endif /* USE_TIMER_THREAD */
DESTROYLOCK(&manager->lock);
isc_heap_destroy(&manager->heap);
manager->common.impmagic = 0;
@@ -999,20 +819,15 @@ isc__timermgr_destroy(isc_timermgr_t **managerp) {
*managerp = NULL;
-#ifdef USE_SHARED_MANAGER
timermgr = NULL;
-#endif
}
-#ifndef USE_TIMER_THREAD
isc_result_t
isc__timermgr_nextevent(isc_timermgr_t *manager0, isc_time_t *when) {
isc__timermgr_t *manager = (isc__timermgr_t *)manager0;
-#ifdef USE_SHARED_MANAGER
if (manager == NULL)
manager = timermgr;
-#endif
if (manager == NULL || manager->nscheduled == 0)
return (ISC_R_NOTFOUND);
*when = manager->due;
@@ -1024,16 +839,13 @@ isc__timermgr_dispatch(isc_timermgr_t *manager0) {
isc__timermgr_t *manager = (isc__timermgr_t *)manager0;
isc_time_t now;
-#ifdef USE_SHARED_MANAGER
if (manager == NULL)
manager = timermgr;
-#endif
if (manager == NULL)
return;
TIME_NOW(&now);
dispatch(manager, &now);
}
-#endif /* USE_TIMER_THREAD */
isc_result_t
isc__timer_register(void) {