diff options
Diffstat (limited to 'usr.sbin/bind/lib/isc/unix/app.c')
| -rw-r--r-- | usr.sbin/bind/lib/isc/unix/app.c | 59 |
1 files changed, 38 insertions, 21 deletions
diff --git a/usr.sbin/bind/lib/isc/unix/app.c b/usr.sbin/bind/lib/isc/unix/app.c index ed3318d1c0a..86de05b054c 100644 --- a/usr.sbin/bind/lib/isc/unix/app.c +++ b/usr.sbin/bind/lib/isc/unix/app.c @@ -1,21 +1,21 @@ /* - * Copyright (C) 1999-2002 Internet Software Consortium. + * Copyright (C) 2004 Internet Systems Consortium, Inc. ("ISC") + * Copyright (C) 1999-2003 Internet Software Consortium. * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * - * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM - * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL - * INTERNET SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, - * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING - * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, - * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION - * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH + * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY + * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, + * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM + * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE + * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + * PERFORMANCE OF THIS SOFTWARE. */ -/* $ISC: app.c,v 1.43.2.3 2002/08/05 06:57:16 marka Exp $ */ +/* $ISC: app.c,v 1.43.2.3.8.5 2004/03/08 02:08:05 marka Exp $ */ #include <config.h> @@ -101,7 +101,7 @@ handle_signal(int sig, void (*handler)(int)) { struct sigaction sa; char strbuf[ISC_STRERRORSIZE]; - memset(&sa, 0, sizeof sa); + memset(&sa, 0, sizeof(sa)); sa.sa_handler = handler; if (sigfillset(&sa.sa_mask) != 0 || @@ -274,7 +274,7 @@ isc_app_onrun(isc_mem_t *mctx, isc_task_t *task, isc_taskaction_t action, */ isc_task_attach(task, &cloned_task); event = isc_event_allocate(mctx, cloned_task, ISC_APPEVENT_SHUTDOWN, - action, arg, sizeof *event); + action, arg, sizeof(*event)); if (event == NULL) { result = ISC_R_NOMEMORY; goto unlock; @@ -304,12 +304,14 @@ evloop() { fd_set readfds, writefds; int maxfd; isc_boolean_t readytasks; + isc_boolean_t call_timer_dispatch = ISC_FALSE; readytasks = isc__taskmgr_ready(); if (readytasks) { tv.tv_sec = 0; tv.tv_usec = 0; tvp = &tv; + call_timer_dispatch = ISC_TRUE; } else { result = isc__timermgr_nextevent(&when); if (result != ISC_R_SUCCESS) @@ -317,8 +319,10 @@ evloop() { else { isc_uint64_t us; - (void)isc_time_now(&now); + TIME_NOW(&now); us = isc_time_microdiff(&when, &now); + if (us == 0) + call_timer_dispatch = ISC_TRUE; tv.tv_sec = us / 1000000; tv.tv_usec = us % 1000000; tvp = &tv; @@ -328,7 +332,23 @@ evloop() { isc__socketmgr_getfdsets(&readfds, &writefds, &maxfd); n = select(maxfd, &readfds, &writefds, NULL, tvp); - (void)isc__timermgr_dispatch(); + if (n == 0 || call_timer_dispatch) { + /* + * We call isc__timermgr_dispatch() only when + * necessary, in order to reduce overhead. If the + * select() call indicates a timeout, we need the + * dispatch. Even if not, if we set the 0-timeout + * for the select() call, we need to check the timer + * events. In the 'readytasks' case, there may be no + * timeout event actually, but there is no other way + * to reduce the overhead. + * Note that we do not have to worry about the case + * where a new timer is inserted during the select() + * call, since this loop only runs in the non-thread + * mode. + */ + isc__timermgr_dispatch(); + } if (n > 0) (void)isc__socketmgr_dispatch(&readfds, &writefds, maxfd); @@ -367,16 +387,16 @@ static isc_boolean_t signalled = ISC_FALSE; isc_result_t isc__nothread_wait_hack(isc_condition_t *cp, isc_mutex_t *mp) { isc_result_t result; - + UNUSED(cp); UNUSED(mp); - + INSIST(!in_recursive_evloop); in_recursive_evloop = ISC_TRUE; INSIST(*mp == 1); /* Mutex must be locked on entry. */ --*mp; - + result = evloop(); if (result == ISC_R_RELOAD) want_reload = ISC_TRUE; @@ -394,7 +414,7 @@ isc_result_t isc__nothread_signal_hack(isc_condition_t *cp) { UNUSED(cp); - + INSIST(in_recursive_evloop); want_shutdown = ISC_TRUE; @@ -528,9 +548,6 @@ isc_app_run(void) { if (result != ISC_R_SUCCESS) return (result); - while (isc__taskmgr_ready()) - (void)isc__taskmgr_dispatch(); - #endif /* ISC_PLATFORM_USETHREADS */ return (ISC_R_SUCCESS); |
