Compare commits
11
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4c736b1d09 | ||
|
|
bb1742100e | ||
|
|
f9ae267158 | ||
|
|
00441917e0 | ||
|
|
8976d7e9e4 | ||
|
|
6687217b8f | ||
|
|
b735d281be | ||
|
|
5bcb036101 | ||
|
|
e65c23f8a6 | ||
|
|
83f06fd8e1 | ||
|
|
ca6fc94400 |
+3
-3
@@ -1622,9 +1622,9 @@ main(int argc, char *argv[]) {
|
||||
fatal("failed to create mctx");
|
||||
|
||||
CHECK(isc_appctx_create(mctx, &actx));
|
||||
CHECK(isc_taskmgr_createinctx(mctx, actx, 1, 0, &taskmgr));
|
||||
CHECK(isc_socketmgr_createinctx(mctx, actx, &socketmgr));
|
||||
CHECK(isc_timermgr_createinctx(mctx, actx, &timermgr));
|
||||
CHECK(isc_taskmgr_createinctx(mctx, 1, 0, &taskmgr));
|
||||
CHECK(isc_socketmgr_createinctx(mctx, &socketmgr));
|
||||
CHECK(isc_timermgr_createinctx(mctx, &timermgr));
|
||||
|
||||
parse_args(argc, argv);
|
||||
|
||||
|
||||
@@ -155,7 +155,8 @@ static unsigned char *gsalt = saltbuf;
|
||||
static size_t salt_length = 0;
|
||||
static isc_task_t *master = NULL;
|
||||
static unsigned int ntasks = 0;
|
||||
static bool shuttingdown = false, finished = false;
|
||||
static atomic_bool shuttingdown = ATOMIC_VAR_INIT(false);
|
||||
static atomic_bool finished = ATOMIC_VAR_INIT(false);
|
||||
static bool nokeys = false;
|
||||
static bool removefile = false;
|
||||
static bool generateds = false;
|
||||
@@ -1454,11 +1455,12 @@ signapex(void) {
|
||||
cleannode(gdb, gversion, node);
|
||||
dns_db_detachnode(gdb, &node);
|
||||
result = dns_dbiterator_first(gdbiter);
|
||||
if (result == ISC_R_NOMORE)
|
||||
finished = true;
|
||||
else if (result != ISC_R_SUCCESS)
|
||||
if (result == ISC_R_NOMORE) {
|
||||
atomic_store(&finished, true);
|
||||
} else if (result != ISC_R_SUCCESS) {
|
||||
fatal("failure iterating database: %s",
|
||||
isc_result_totext(result));
|
||||
}
|
||||
}
|
||||
|
||||
/*%
|
||||
@@ -1478,11 +1480,12 @@ assignwork(isc_task_t *task, isc_task_t *worker) {
|
||||
static dns_fixedname_t fzonecut; /* Protected by namelock. */
|
||||
static unsigned int ended = 0; /* Protected by namelock. */
|
||||
|
||||
if (shuttingdown)
|
||||
if (atomic_load(&shuttingdown)) {
|
||||
return;
|
||||
}
|
||||
|
||||
LOCK(&namelock);
|
||||
if (finished) {
|
||||
if (atomic_load(&finished)) {
|
||||
ended++;
|
||||
if (ended == ntasks) {
|
||||
isc_task_detach(&task);
|
||||
@@ -1552,7 +1555,7 @@ assignwork(isc_task_t *task, isc_task_t *worker) {
|
||||
next:
|
||||
result = dns_dbiterator_next(gdbiter);
|
||||
if (result == ISC_R_NOMORE) {
|
||||
finished = true;
|
||||
atomic_store(&finished, true);
|
||||
break;
|
||||
} else if (result != ISC_R_SUCCESS)
|
||||
fatal("failure iterating database: %s",
|
||||
@@ -3854,7 +3857,7 @@ main(int argc, char *argv[]) {
|
||||
presign();
|
||||
TIME_NOW(&sign_start);
|
||||
signapex();
|
||||
if (!finished) {
|
||||
if (!atomic_load(&finished)) {
|
||||
/*
|
||||
* There is more work to do. Spread it out over multiple
|
||||
* processors if possible.
|
||||
@@ -3867,11 +3870,12 @@ main(int argc, char *argv[]) {
|
||||
isc_result_totext(result));
|
||||
}
|
||||
(void)isc_app_run();
|
||||
if (!finished)
|
||||
if (!atomic_load(&finished)) {
|
||||
fatal("process aborted by user");
|
||||
}
|
||||
} else
|
||||
isc_task_detach(&master);
|
||||
shuttingdown = true;
|
||||
atomic_store(&shuttingdown, true);;
|
||||
for (i = 0; i < (int)ntasks; i++)
|
||||
isc_task_detach(&tasks[i]);
|
||||
isc_taskmgr_destroy(&taskmgr);
|
||||
|
||||
+22
-15
@@ -16,6 +16,7 @@
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <isc/app.h>
|
||||
#include <isc/atomic.h>
|
||||
#include <isc/buffer.h>
|
||||
#include <isc/commandline.h>
|
||||
#include <isc/file.h>
|
||||
@@ -24,6 +25,7 @@
|
||||
#include <isc/mem.h>
|
||||
#include <isc/print.h>
|
||||
#include <isc/random.h>
|
||||
#include <isc/refcount.h>
|
||||
#include <isc/socket.h>
|
||||
#include <isc/stdtime.h>
|
||||
#include <isc/string.h>
|
||||
@@ -73,7 +75,7 @@ static isccc_region_t secret;
|
||||
static bool failed = false;
|
||||
static bool c_flag = false;
|
||||
static isc_mem_t *rndc_mctx;
|
||||
static int sends, recvs, connects;
|
||||
static isc_refcount_t sends, recvs, connects;
|
||||
static char *command;
|
||||
static char *args;
|
||||
static char program[256];
|
||||
@@ -271,14 +273,14 @@ rndc_senddone(isc_task_t *task, isc_event_t *event) {
|
||||
|
||||
UNUSED(task);
|
||||
|
||||
sends--;
|
||||
if (sevent->result != ISC_R_SUCCESS)
|
||||
fatal("send failed: %s", isc_result_totext(sevent->result));
|
||||
isc_event_free(&event);
|
||||
if (sends == 0 && recvs == 0) {
|
||||
if (isc_refcount_decrement(&sends) == 1
|
||||
&& isc_refcount_current(&recvs) == 0) {
|
||||
isc_socket_detach(&sock);
|
||||
isc_task_shutdown(task);
|
||||
RUNTIME_CHECK(isc_app_shutdown() == ISC_R_SUCCESS);
|
||||
isc_app_shutdown();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -291,7 +293,7 @@ rndc_recvdone(isc_task_t *task, isc_event_t *event) {
|
||||
char *textmsg = NULL;
|
||||
isc_result_t result;
|
||||
|
||||
recvs--;
|
||||
isc_refcount_decrement(&recvs);
|
||||
|
||||
if (ccmsg.result == ISC_R_EOF)
|
||||
fatal("connection to remote host closed\n"
|
||||
@@ -344,10 +346,11 @@ rndc_recvdone(isc_task_t *task, isc_event_t *event) {
|
||||
|
||||
isc_event_free(&event);
|
||||
isccc_sexpr_free(&response);
|
||||
if (sends == 0 && recvs == 0) {
|
||||
if (isc_refcount_current(&sends) == 0
|
||||
&& isc_refcount_current(&recvs) == 0) {
|
||||
isc_socket_detach(&sock);
|
||||
isc_task_shutdown(task);
|
||||
RUNTIME_CHECK(isc_app_shutdown() == ISC_R_SUCCESS);
|
||||
isc_app_shutdown();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -364,7 +367,7 @@ rndc_recvnonce(isc_task_t *task, isc_event_t *event) {
|
||||
isccc_sexpr_t *data;
|
||||
isc_buffer_t b;
|
||||
|
||||
recvs--;
|
||||
isc_refcount_decrement(&recvs);
|
||||
|
||||
if (ccmsg.result == ISC_R_EOF)
|
||||
fatal("connection to remote host closed\n"
|
||||
@@ -425,10 +428,10 @@ rndc_recvnonce(isc_task_t *task, isc_event_t *event) {
|
||||
isccc_ccmsg_cancelread(&ccmsg);
|
||||
DO("schedule recv", isccc_ccmsg_readmessage(&ccmsg, task,
|
||||
rndc_recvdone, NULL));
|
||||
recvs++;
|
||||
isc_refcount_increment(&recvs);
|
||||
DO("send message", isc_socket_send(sock, &r, task, rndc_senddone,
|
||||
NULL));
|
||||
sends++;
|
||||
isc_refcount_increment(&sends);
|
||||
|
||||
isc_event_free(&event);
|
||||
isccc_sexpr_free(&response);
|
||||
@@ -447,7 +450,7 @@ rndc_connected(isc_task_t *task, isc_event_t *event) {
|
||||
isc_buffer_t b;
|
||||
isc_result_t result;
|
||||
|
||||
connects--;
|
||||
isc_refcount_decrement(&connects);
|
||||
|
||||
if (sevent->result != ISC_R_SUCCESS) {
|
||||
isc_sockaddr_format(&serveraddrs[currentaddr], socktext,
|
||||
@@ -493,10 +496,10 @@ rndc_connected(isc_task_t *task, isc_event_t *event) {
|
||||
|
||||
DO("schedule recv", isccc_ccmsg_readmessage(&ccmsg, task,
|
||||
rndc_recvnonce, NULL));
|
||||
recvs++;
|
||||
isc_refcount_increment(&recvs);
|
||||
DO("send message", isc_socket_send(sock, &r, task, rndc_senddone,
|
||||
NULL));
|
||||
sends++;
|
||||
isc_refcount_increment(&sends);
|
||||
isc_event_free(&event);
|
||||
isccc_sexpr_free(&request);
|
||||
}
|
||||
@@ -531,7 +534,7 @@ rndc_startconnect(isc_sockaddr_t *addr, isc_task_t *task) {
|
||||
}
|
||||
DO("connect", isc_socket_connect(sock, addr, task, rndc_connected,
|
||||
NULL));
|
||||
connects++;
|
||||
isc_refcount_increment(&connects);
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -997,8 +1000,12 @@ main(int argc, char **argv) {
|
||||
if (result != ISC_R_SUCCESS)
|
||||
fatal("isc_app_run() failed: %s", isc_result_totext(result));
|
||||
|
||||
if (connects > 0 || sends > 0 || recvs > 0)
|
||||
if (isc_refcount_current(&connects) > 0 ||
|
||||
isc_refcount_current(&sends) > 0 ||
|
||||
isc_refcount_current(&recvs) > 0)
|
||||
{
|
||||
isc_socket_cancel(sock, task, ISC_SOCKCANCEL_ALL);
|
||||
}
|
||||
|
||||
isc_task_detach(&task);
|
||||
isc_taskmgr_destroy(&taskmgr);
|
||||
|
||||
@@ -98,7 +98,7 @@ tick(isc_task_t *task, isc_event_t *event) {
|
||||
info->ticks++;
|
||||
if (strcmp(info->name, "1") == 0) {
|
||||
if (info->ticks == 10) {
|
||||
RUNTIME_CHECK(isc_app_shutdown() == ISC_R_SUCCESS);
|
||||
isc_app_shutdown();
|
||||
} else if (info->ticks >= 15 && info->exiting) {
|
||||
isc_timer_detach(&info->timer);
|
||||
isc_task_detach(&info->task);
|
||||
|
||||
+6
-3
@@ -309,6 +309,9 @@
|
||||
/* Have PTHREAD_PRIO_INHERIT. */
|
||||
#undef HAVE_PTHREAD_PRIO_INHERIT
|
||||
|
||||
/* Define to 1 if you have the `pthread_rwlock_rdlock' function. */
|
||||
#undef HAVE_PTHREAD_RWLOCK_RDLOCK
|
||||
|
||||
/* Define to 1 if you have the `pthread_setaffinity_np' function. */
|
||||
#undef HAVE_PTHREAD_SETAFFINITY_NP
|
||||
|
||||
@@ -363,9 +366,6 @@
|
||||
/* Define to 1 if you have the `setresuid' function. */
|
||||
#undef HAVE_SETRESUID
|
||||
|
||||
/* Define to 1 if you have the `sigwait' function. */
|
||||
#undef HAVE_SIGWAIT
|
||||
|
||||
/* define if struct stat has st_mtim.tv_nsec field */
|
||||
#undef HAVE_STAT_NSEC
|
||||
|
||||
@@ -556,6 +556,9 @@
|
||||
/* define if PKCS11 is used for Public-Key Cryptography */
|
||||
#undef USE_PKCS11
|
||||
|
||||
/* Define if you want to use pthread rwlock implementation */
|
||||
#undef USE_PTHREAD_RWLOCK
|
||||
|
||||
/* Enable extensions on AIX 3, Interix. */
|
||||
#ifndef _ALL_SOURCE
|
||||
# undef _ALL_SOURCE
|
||||
|
||||
@@ -896,6 +896,7 @@ enable_devpoll
|
||||
with_geoip
|
||||
with_locktype
|
||||
with_libtool
|
||||
enable_pthread_rwlock
|
||||
with_openssl
|
||||
enable_fips_mode
|
||||
with_cc_alg
|
||||
@@ -1592,6 +1593,8 @@ Optional Features:
|
||||
--enable-kqueue use BSD kqueue when available [default=yes]
|
||||
--enable-epoll use Linux epoll when available [default=auto]
|
||||
--enable-devpoll use /dev/poll when available [default=yes]
|
||||
--enable-pthread-rwlock use pthread rwlock instead of internal rwlock
|
||||
implementation
|
||||
--enable-fips-mode enable FIPS mode in OpenSSL library [default=no]
|
||||
--enable-native-pkcs11 use native PKCS11 for public-key crypto [default=no]
|
||||
--enable-backtrace log stack backtrace on abort [default=yes]
|
||||
@@ -15308,10 +15311,7 @@ LIBS="$PTHREAD_LIBS $LIBS"
|
||||
CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
|
||||
CC="$PTHREAD_CC"
|
||||
|
||||
#
|
||||
# We'd like to use sigwait() too
|
||||
#
|
||||
for ac_func in sigwait pthread_attr_getstacksize pthread_attr_setstacksize
|
||||
for ac_func in pthread_attr_getstacksize pthread_attr_setstacksize
|
||||
do :
|
||||
as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
|
||||
ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var"
|
||||
@@ -15598,6 +15598,36 @@ $as_echo "no" >&6; }
|
||||
esac
|
||||
|
||||
|
||||
# Do we want to use pthread rwlock? (useful for ThreadSanitizer)
|
||||
#
|
||||
# Check whether --enable-pthread_rwlock was given.
|
||||
if test "${enable_pthread_rwlock+set}" = set; then :
|
||||
enableval=$enable_pthread_rwlock;
|
||||
else
|
||||
enable_pthread_rwlock=no
|
||||
fi
|
||||
|
||||
|
||||
if test "$enable_pthread_rwlock" = "yes"; then :
|
||||
for ac_func in pthread_rwlock_rdlock
|
||||
do :
|
||||
ac_fn_c_check_func "$LINENO" "pthread_rwlock_rdlock" "ac_cv_func_pthread_rwlock_rdlock"
|
||||
if test "x$ac_cv_func_pthread_rwlock_rdlock" = xyes; then :
|
||||
cat >>confdefs.h <<_ACEOF
|
||||
#define HAVE_PTHREAD_RWLOCK_RDLOCK 1
|
||||
_ACEOF
|
||||
|
||||
else
|
||||
as_fn_error $? "pthread_rwlock_rdlock requested but not found" "$LINENO" 5
|
||||
fi
|
||||
done
|
||||
|
||||
|
||||
$as_echo "#define USE_PTHREAD_RWLOCK 1" >>confdefs.h
|
||||
|
||||
|
||||
fi
|
||||
|
||||
#
|
||||
# If PIC is disabled, shared libraries must also be
|
||||
#
|
||||
|
||||
+14
-4
@@ -635,10 +635,7 @@ LIBS="$PTHREAD_LIBS $LIBS"
|
||||
CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
|
||||
CC="$PTHREAD_CC"
|
||||
|
||||
#
|
||||
# We'd like to use sigwait() too
|
||||
#
|
||||
AC_CHECK_FUNCS([sigwait pthread_attr_getstacksize pthread_attr_setstacksize])
|
||||
AC_CHECK_FUNCS([pthread_attr_getstacksize pthread_attr_setstacksize])
|
||||
|
||||
AC_ARG_WITH([locktype],
|
||||
AS_HELP_STRING([--with-locktype=ARG],
|
||||
@@ -728,6 +725,19 @@ case $use_libtool in
|
||||
esac
|
||||
AC_SUBST(INSTALL_LIBRARY)
|
||||
|
||||
# Do we want to use pthread rwlock? (useful for ThreadSanitizer)
|
||||
#
|
||||
AC_ARG_ENABLE([pthread_rwlock],
|
||||
[AS_HELP_STRING([--enable-pthread-rwlock],
|
||||
[use pthread rwlock instead of internal rwlock implementation])],
|
||||
[], [enable_pthread_rwlock=no])
|
||||
|
||||
AS_IF([test "$enable_pthread_rwlock" = "yes"],
|
||||
[AC_CHECK_FUNCS([pthread_rwlock_rdlock], [],
|
||||
[AC_MSG_ERROR([pthread_rwlock_rdlock requested but not found])])
|
||||
AC_DEFINE([USE_PTHREAD_RWLOCK],[1],[Define if you want to use pthread rwlock implementation])
|
||||
])
|
||||
|
||||
#
|
||||
# If PIC is disabled, shared libraries must also be
|
||||
#
|
||||
|
||||
+3
-3
@@ -420,13 +420,13 @@ dns_client_create(dns_client_t **clientp, unsigned int options) {
|
||||
result = isc_app_ctxstart(actx);
|
||||
if (result != ISC_R_SUCCESS)
|
||||
goto cleanup;
|
||||
result = isc_taskmgr_createinctx(mctx, actx, 1, 0, &taskmgr);
|
||||
result = isc_taskmgr_createinctx(mctx, 1, 0, &taskmgr);
|
||||
if (result != ISC_R_SUCCESS)
|
||||
goto cleanup;
|
||||
result = isc_socketmgr_createinctx(mctx, actx, &socketmgr);
|
||||
result = isc_socketmgr_createinctx(mctx, &socketmgr);
|
||||
if (result != ISC_R_SUCCESS)
|
||||
goto cleanup;
|
||||
result = isc_timermgr_createinctx(mctx, actx, &timermgr);
|
||||
result = isc_timermgr_createinctx(mctx, &timermgr);
|
||||
if (result != ISC_R_SUCCESS)
|
||||
goto cleanup;
|
||||
#if 0
|
||||
|
||||
+4
-4
@@ -702,7 +702,7 @@ static char FILE_VERSION[32] = "\0";
|
||||
* that indicates that the database does not implement cyclic
|
||||
* processing.
|
||||
*/
|
||||
static unsigned int init_count;
|
||||
static atomic_uint_fast32_t init_count;
|
||||
|
||||
/*
|
||||
* Locking
|
||||
@@ -6486,7 +6486,7 @@ addrdataset(dns_db_t *db, dns_dbnode_t *node, dns_dbversion_t *version,
|
||||
newheader->attributes |= RDATASET_ATTR_ZEROTTL;
|
||||
newheader->noqname = NULL;
|
||||
newheader->closest = NULL;
|
||||
newheader->count = init_count++;
|
||||
newheader->count = atomic_fetch_add(&init_count, 1);
|
||||
newheader->trust = rdataset->trust;
|
||||
newheader->last_used = now;
|
||||
newheader->node = rbtnode;
|
||||
@@ -6673,7 +6673,7 @@ subtractrdataset(dns_db_t *db, dns_dbnode_t *node, dns_dbversion_t *version,
|
||||
newheader->trust = 0;
|
||||
newheader->noqname = NULL;
|
||||
newheader->closest = NULL;
|
||||
newheader->count = init_count++;
|
||||
newheader->count = atomic_fetch_add(&init_count, 1);
|
||||
newheader->last_used = 0;
|
||||
newheader->node = rbtnode;
|
||||
if ((rdataset->attributes & DNS_RDATASETATTR_RESIGN) != 0) {
|
||||
@@ -7057,7 +7057,7 @@ loading_addrdataset(void *arg, const dns_name_t *name,
|
||||
newheader->serial = 1;
|
||||
newheader->noqname = NULL;
|
||||
newheader->closest = NULL;
|
||||
newheader->count = init_count++;
|
||||
newheader->count = atomic_fetch_add(&init_count, 1);
|
||||
newheader->last_used = 0;
|
||||
newheader->node = node;
|
||||
setownercase(newheader, name);
|
||||
|
||||
+3
-3
@@ -101,15 +101,15 @@ ctxs_init(isc_mem_t **mctxp, isc_appctx_t **actxp,
|
||||
if (result != ISC_R_SUCCESS)
|
||||
goto fail;
|
||||
|
||||
result = isc_taskmgr_createinctx(*mctxp, *actxp, 1, 0, taskmgrp);
|
||||
result = isc_taskmgr_createinctx(*mctxp, 1, 0, taskmgrp);
|
||||
if (result != ISC_R_SUCCESS)
|
||||
goto fail;
|
||||
|
||||
result = isc_socketmgr_createinctx(*mctxp, *actxp, socketmgrp);
|
||||
result = isc_socketmgr_createinctx(*mctxp, socketmgrp);
|
||||
if (result != ISC_R_SUCCESS)
|
||||
goto fail;
|
||||
|
||||
result = isc_timermgr_createinctx(*mctxp, *actxp, timermgrp);
|
||||
result = isc_timermgr_createinctx(*mctxp, timermgrp);
|
||||
if (result != ISC_R_SUCCESS)
|
||||
goto fail;
|
||||
|
||||
|
||||
@@ -103,14 +103,7 @@ typedef isc_event_t isc_appevent_t;
|
||||
* of the isc_app_ routines to work. app implementations must maintain
|
||||
* all app context invariants.
|
||||
*/
|
||||
struct isc_appctx {
|
||||
unsigned int impmagic;
|
||||
unsigned int magic;
|
||||
};
|
||||
|
||||
#define ISCAPI_APPCTX_MAGIC ISC_MAGIC('A','a','p','c')
|
||||
#define ISCAPI_APPCTX_VALID(c) ((c) != NULL && \
|
||||
(c)->magic == ISCAPI_APPCTX_MAGIC)
|
||||
struct isc_appctx;
|
||||
|
||||
ISC_LANG_BEGINDECLS
|
||||
|
||||
@@ -184,10 +177,10 @@ isc_app_isrunning(void);
|
||||
*\li false App is not running.
|
||||
*/
|
||||
|
||||
isc_result_t
|
||||
void
|
||||
isc_app_ctxshutdown(isc_appctx_t *ctx);
|
||||
|
||||
isc_result_t
|
||||
void
|
||||
isc_app_shutdown(void);
|
||||
/*!<
|
||||
* \brief Request application shutdown.
|
||||
@@ -205,13 +198,13 @@ isc_app_shutdown(void);
|
||||
*\li ISC_R_UNEXPECTED
|
||||
*/
|
||||
|
||||
isc_result_t
|
||||
void
|
||||
isc_app_ctxsuspend(isc_appctx_t *ctx);
|
||||
/*!<
|
||||
* \brief This has the same behavior as isc_app_ctxsuspend().
|
||||
*/
|
||||
|
||||
isc_result_t
|
||||
void
|
||||
isc_app_reload(void);
|
||||
/*!<
|
||||
* \brief Request application reload.
|
||||
@@ -295,44 +288,6 @@ isc_appctx_destroy(isc_appctx_t **ctxp);
|
||||
*\li *ctxp == NULL.
|
||||
*/
|
||||
|
||||
void
|
||||
isc_appctx_settaskmgr(isc_appctx_t *ctx, isc_taskmgr_t *taskmgr);
|
||||
/*!<
|
||||
* \brief Associate a task manager with an application context.
|
||||
*
|
||||
* This must be done before running tasks within the application context.
|
||||
*
|
||||
* Requires:
|
||||
*\li 'ctx' is a valid application context.
|
||||
*\li 'taskmgr' is a valid task manager.
|
||||
*/
|
||||
|
||||
void
|
||||
isc_appctx_setsocketmgr(isc_appctx_t *ctx, isc_socketmgr_t *socketmgr);
|
||||
/*!<
|
||||
* \brief Associate a socket manager with an application context.
|
||||
*
|
||||
* This must be done before handling socket events within the application
|
||||
* context.
|
||||
*
|
||||
* Requires:
|
||||
*\li 'ctx' is a valid application context.
|
||||
*\li 'socketmgr' is a valid socket manager.
|
||||
*/
|
||||
|
||||
void
|
||||
isc_appctx_settimermgr(isc_appctx_t *ctx, isc_timermgr_t *timermgr);
|
||||
/*!<
|
||||
* \brief Associate a socket timer with an application context.
|
||||
*
|
||||
* This must be done before handling timer events within the application
|
||||
* context.
|
||||
*
|
||||
* Requires:
|
||||
*\li 'ctx' is a valid application context.
|
||||
*\li 'timermgr' is a valid timer manager.
|
||||
*/
|
||||
|
||||
ISC_LANG_ENDDECLS
|
||||
|
||||
#endif /* ISC_APP_H */
|
||||
|
||||
@@ -37,6 +37,10 @@
|
||||
atomic_compare_exchange_weak_explicit((o), (e), (d), \
|
||||
memory_order_relaxed, \
|
||||
memory_order_relaxed)
|
||||
#define atomic_compare_exchange_strong_relaxed(o, e, d) \
|
||||
atomic_compare_exchange_strong_explicit((o), (e), (d), \
|
||||
memory_order_relaxed, \
|
||||
memory_order_relaxed)
|
||||
|
||||
/* Acquire-Release Memory Ordering */
|
||||
|
||||
|
||||
@@ -31,11 +31,20 @@ typedef enum {
|
||||
isc_rwlocktype_write
|
||||
} isc_rwlocktype_t;
|
||||
|
||||
#if USE_PTHREAD_RWLOCK || __has_feature(thread_sanitizer)
|
||||
|
||||
struct isc_rwlock {
|
||||
pthread_rwlock_t rwlock;
|
||||
atomic_bool downgrade;
|
||||
};
|
||||
|
||||
#else /* USE_PTHREAD_RWLOCK || __has_feature(thread_sanitizer) */
|
||||
|
||||
struct isc_rwlock {
|
||||
/* Unlocked. */
|
||||
unsigned int magic;
|
||||
isc_mutex_t lock;
|
||||
int32_t spins;
|
||||
atomic_int_fast32_t spins;
|
||||
|
||||
/*
|
||||
* When some atomic instructions with hardware assistance are
|
||||
@@ -58,16 +67,17 @@ struct isc_rwlock {
|
||||
/* Locked by lock. */
|
||||
isc_condition_t readable;
|
||||
isc_condition_t writeable;
|
||||
unsigned int readers_waiting;
|
||||
unsigned int readers_waiting;
|
||||
|
||||
/* Locked by rwlock itself. */
|
||||
unsigned int write_granted;
|
||||
atomic_int_fast32_t write_granted;
|
||||
|
||||
/* Unlocked. */
|
||||
unsigned int write_quota;
|
||||
|
||||
};
|
||||
|
||||
#endif /* USE_PTHREAD_RWLOCK || __has_feature(thread_sanitizer) */
|
||||
|
||||
isc_result_t
|
||||
isc_rwlock_init(isc_rwlock_t *rwl, unsigned int read_quota,
|
||||
unsigned int write_quota);
|
||||
|
||||
@@ -805,8 +805,7 @@ isc_socket_sendto2(isc_socket_t *sock, isc_region_t *region,
|
||||
/*@}*/
|
||||
|
||||
isc_result_t
|
||||
isc_socketmgr_createinctx(isc_mem_t *mctx, isc_appctx_t *actx,
|
||||
isc_socketmgr_t **managerp);
|
||||
isc_socketmgr_createinctx(isc_mem_t *mctx, isc_socketmgr_t **managerp);
|
||||
|
||||
isc_result_t
|
||||
isc_socketmgr_create(isc_mem_t *mctx, isc_socketmgr_t **managerp);
|
||||
|
||||
@@ -630,7 +630,7 @@ isc_task_privilege(isc_task_t *task);
|
||||
*****/
|
||||
|
||||
isc_result_t
|
||||
isc_taskmgr_createinctx(isc_mem_t *mctx, isc_appctx_t *actx,
|
||||
isc_taskmgr_createinctx(isc_mem_t *mctx,
|
||||
unsigned int workers, unsigned int default_quantum,
|
||||
isc_taskmgr_t **managerp);
|
||||
isc_result_t
|
||||
|
||||
@@ -316,8 +316,7 @@ isc_timer_gettype(isc_timer_t *timer);
|
||||
*/
|
||||
|
||||
isc_result_t
|
||||
isc_timermgr_createinctx(isc_mem_t *mctx, isc_appctx_t *actx,
|
||||
isc_timermgr_t **managerp);
|
||||
isc_timermgr_createinctx(isc_mem_t *mctx, isc_timermgr_t **managerp);
|
||||
|
||||
isc_result_t
|
||||
isc_timermgr_create(isc_mem_t *mctx, isc_timermgr_t **managerp);
|
||||
|
||||
+169
-77
@@ -27,6 +27,101 @@
|
||||
#include <isc/rwlock.h>
|
||||
#include <isc/util.h>
|
||||
|
||||
#if USE_PTHREAD_RWLOCK || __has_feature(thread_sanitizer)
|
||||
|
||||
#include <errno.h>
|
||||
#include <pthread.h>
|
||||
|
||||
isc_result_t
|
||||
isc_rwlock_init(isc_rwlock_t *rwl, unsigned int read_quota,
|
||||
unsigned int write_quota)
|
||||
{
|
||||
UNUSED(read_quota);
|
||||
UNUSED(write_quota);
|
||||
REQUIRE(pthread_rwlock_init(&rwl->rwlock, NULL) == 0);
|
||||
atomic_init(&rwl->downgrade, false);
|
||||
return (ISC_R_SUCCESS);
|
||||
}
|
||||
|
||||
isc_result_t
|
||||
isc_rwlock_lock(isc_rwlock_t *rwl, isc_rwlocktype_t type) {
|
||||
switch (type) {
|
||||
case isc_rwlocktype_read:
|
||||
REQUIRE(pthread_rwlock_rdlock(&rwl->rwlock) == 0);
|
||||
break;
|
||||
case isc_rwlocktype_write:
|
||||
while (true) {
|
||||
REQUIRE(pthread_rwlock_wrlock(&rwl->rwlock) == 0);
|
||||
/* Unlock if in middle of downgrade operation */
|
||||
if (atomic_load(&rwl->downgrade)) {
|
||||
isc_rwlock_unlock(rwl, type);
|
||||
while (atomic_load(&rwl->downgrade));
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
INSIST(0);
|
||||
ISC_UNREACHABLE();
|
||||
}
|
||||
return (ISC_R_SUCCESS);
|
||||
}
|
||||
|
||||
isc_result_t
|
||||
isc_rwlock_trylock(isc_rwlock_t *rwl, isc_rwlocktype_t type) {
|
||||
int ret = 0;
|
||||
switch (type) {
|
||||
case isc_rwlocktype_read:
|
||||
ret = pthread_rwlock_tryrdlock(&rwl->rwlock);
|
||||
break;
|
||||
case isc_rwlocktype_write:
|
||||
ret = pthread_rwlock_trywrlock(&rwl->rwlock);
|
||||
if ((ret == 0) && atomic_load(&rwl->downgrade)) {
|
||||
isc_rwlock_unlock(rwl, type);
|
||||
return (ISC_R_LOCKBUSY);
|
||||
}
|
||||
break;
|
||||
default: INSIST(0);
|
||||
}
|
||||
|
||||
switch (ret) {
|
||||
case 0: return (ISC_R_SUCCESS);
|
||||
case EBUSY: return (ISC_R_LOCKBUSY);
|
||||
case EAGAIN: return (ISC_R_LOCKBUSY);
|
||||
default: INSIST(0); ISC_UNREACHABLE();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
isc_result_t
|
||||
isc_rwlock_unlock(isc_rwlock_t *rwl, isc_rwlocktype_t type) {
|
||||
UNUSED(type);
|
||||
REQUIRE(pthread_rwlock_unlock(&rwl->rwlock) == 0);
|
||||
return (ISC_R_SUCCESS);
|
||||
}
|
||||
|
||||
isc_result_t
|
||||
isc_rwlock_tryupgrade(isc_rwlock_t *rwl) {
|
||||
isc_rwlock_unlock(rwl, isc_rwlocktype_read);
|
||||
return (isc_rwlock_trylock(rwl, isc_rwlocktype_write));
|
||||
}
|
||||
|
||||
void
|
||||
isc_rwlock_downgrade(isc_rwlock_t *rwl) {
|
||||
atomic_store(&rwl->downgrade, true);
|
||||
isc_rwlock_unlock(rwl, isc_rwlocktype_write);
|
||||
isc_rwlock_lock(rwl, isc_rwlocktype_read);
|
||||
atomic_store(&rwl->downgrade, false);
|
||||
}
|
||||
|
||||
void
|
||||
isc_rwlock_destroy(isc_rwlock_t *rwl) {
|
||||
pthread_rwlock_destroy(&rwl->rwlock);
|
||||
}
|
||||
|
||||
#else /* USE_PTHREAD_RWLOCK·||·__has_feature(thread_sanitizer)$ */
|
||||
|
||||
#define RWLOCK_MAGIC ISC_MAGIC('R', 'W', 'L', 'k')
|
||||
#define VALID_RWLOCK(rwl) ISC_MAGIC_VALID(rwl, RWLOCK_MAGIC)
|
||||
|
||||
@@ -81,11 +176,11 @@ print_lock(const char *operation, isc_rwlock_t *rwl, isc_rwlocktype_t type) {
|
||||
"write_granted=%u, write_quota=%u\n",
|
||||
rwl, isc_thread_self(), operation,
|
||||
(type == isc_rwlocktype_read ? "read" : "write"),
|
||||
atomic_load_explicit(&rwl->write_requests, memory_order_relaxed),
|
||||
atomic_load_explicit(&rwl->write_completions, memory_order_relaxed),
|
||||
atomic_load_explicit(&rwl->cnt_and_flag, memory_order_relaxed),
|
||||
atomic_load_relaxed(&rwl->write_requests),
|
||||
atomic_load_relaxed(&rwl->write_completions),
|
||||
atomic_load_relaxed(&rwl->cnt_and_flag),
|
||||
rwl->readers_waiting,
|
||||
rwl->write_granted, rwl->write_quota);
|
||||
atomic_load_relaxed(&rwl->write_granted), rwl->write_quota);
|
||||
}
|
||||
#endif /* ISC_RWLOCK_TRACE */
|
||||
|
||||
@@ -101,12 +196,12 @@ isc_rwlock_init(isc_rwlock_t *rwl, unsigned int read_quota,
|
||||
*/
|
||||
rwl->magic = 0;
|
||||
|
||||
rwl->spins = 0;
|
||||
atomic_init(&rwl->spins, 0);
|
||||
atomic_init(&rwl->write_requests, 0);
|
||||
atomic_init(&rwl->write_completions, 0);
|
||||
atomic_init(&rwl->cnt_and_flag, 0);
|
||||
rwl->readers_waiting = 0;
|
||||
rwl->write_granted = 0;
|
||||
atomic_init(&rwl->write_granted, 0);
|
||||
if (read_quota != 0) {
|
||||
UNEXPECTED_ERROR(__FILE__, __LINE__,
|
||||
"read quota is not supported");
|
||||
@@ -129,9 +224,9 @@ void
|
||||
isc_rwlock_destroy(isc_rwlock_t *rwl) {
|
||||
REQUIRE(VALID_RWLOCK(rwl));
|
||||
|
||||
REQUIRE(atomic_load_explicit(&rwl->write_requests, memory_order_relaxed) ==
|
||||
atomic_load_explicit(&rwl->write_completions, memory_order_relaxed) &&
|
||||
atomic_load_explicit(&rwl->cnt_and_flag, memory_order_relaxed) == 0 && rwl->readers_waiting == 0);
|
||||
REQUIRE(atomic_load_relaxed(&rwl->write_requests) ==
|
||||
atomic_load_relaxed(&rwl->write_completions) &&
|
||||
atomic_load_relaxed(&rwl->cnt_and_flag) == 0 && rwl->readers_waiting == 0);
|
||||
|
||||
rwl->magic = 0;
|
||||
(void)isc_condition_destroy(&rwl->readable);
|
||||
@@ -215,13 +310,13 @@ isc__rwlock_lock(isc_rwlock_t *rwl, isc_rwlocktype_t type) {
|
||||
#endif
|
||||
|
||||
if (type == isc_rwlocktype_read) {
|
||||
if (atomic_load_explicit(&rwl->write_requests, memory_order_relaxed) !=
|
||||
atomic_load_explicit(&rwl->write_completions, memory_order_relaxed))
|
||||
if (atomic_load_relaxed(&rwl->write_requests) !=
|
||||
atomic_load_relaxed(&rwl->write_completions))
|
||||
{
|
||||
/* there is a waiting or active writer */
|
||||
LOCK(&rwl->lock);
|
||||
if (atomic_load_explicit(&rwl->write_requests, memory_order_relaxed) !=
|
||||
atomic_load_explicit(&rwl->write_completions, memory_order_relaxed)) {
|
||||
if (atomic_load_relaxed(&rwl->write_requests) !=
|
||||
atomic_load_relaxed(&rwl->write_completions)) {
|
||||
rwl->readers_waiting++;
|
||||
WAIT(&rwl->readable, &rwl->lock);
|
||||
rwl->readers_waiting--;
|
||||
@@ -229,18 +324,22 @@ isc__rwlock_lock(isc_rwlock_t *rwl, isc_rwlocktype_t type) {
|
||||
UNLOCK(&rwl->lock);
|
||||
}
|
||||
|
||||
cntflag = atomic_fetch_add_explicit(&rwl->cnt_and_flag,
|
||||
READER_INCR,
|
||||
memory_order_relaxed);
|
||||
cntflag = atomic_fetch_add_relaxed(&rwl->cnt_and_flag,
|
||||
READER_INCR);
|
||||
POST(cntflag);
|
||||
while (1) {
|
||||
if ((atomic_load_explicit(&rwl->cnt_and_flag, memory_order_relaxed) & WRITER_ACTIVE) == 0)
|
||||
if ((atomic_load_relaxed(&rwl->cnt_and_flag)
|
||||
& WRITER_ACTIVE) == 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
/* A writer is still working */
|
||||
LOCK(&rwl->lock);
|
||||
rwl->readers_waiting++;
|
||||
if ((atomic_load_explicit(&rwl->cnt_and_flag, memory_order_relaxed) & WRITER_ACTIVE) != 0) {
|
||||
if ((atomic_load_relaxed(&rwl->cnt_and_flag)
|
||||
& WRITER_ACTIVE) != 0)
|
||||
{
|
||||
WAIT(&rwl->readable, &rwl->lock);
|
||||
}
|
||||
rwl->readers_waiting--;
|
||||
@@ -277,16 +376,19 @@ isc__rwlock_lock(isc_rwlock_t *rwl, isc_rwlocktype_t type) {
|
||||
* quota, reset the condition (race among readers doesn't
|
||||
* matter).
|
||||
*/
|
||||
rwl->write_granted = 0;
|
||||
atomic_store_relaxed(&rwl->write_granted, 0);
|
||||
} else {
|
||||
int32_t prev_writer;
|
||||
|
||||
/* enter the waiting queue, and wait for our turn */
|
||||
prev_writer = atomic_fetch_add_explicit(&rwl->write_requests, 1,
|
||||
memory_order_relaxed);
|
||||
while (atomic_load_explicit(&rwl->write_completions, memory_order_relaxed) != prev_writer) {
|
||||
prev_writer = atomic_fetch_add_relaxed(&rwl->write_requests, 1);
|
||||
while (atomic_load_relaxed(&rwl->write_completions)
|
||||
!= prev_writer)
|
||||
{
|
||||
LOCK(&rwl->lock);
|
||||
if (atomic_load_explicit(&rwl->write_completions, memory_order_relaxed) != prev_writer) {
|
||||
if (atomic_load_relaxed(&rwl->write_completions)
|
||||
!= prev_writer)
|
||||
{
|
||||
WAIT(&rwl->writeable, &rwl->lock);
|
||||
UNLOCK(&rwl->lock);
|
||||
continue;
|
||||
@@ -297,23 +399,23 @@ isc__rwlock_lock(isc_rwlock_t *rwl, isc_rwlocktype_t type) {
|
||||
|
||||
while (1) {
|
||||
int_fast32_t zero = 0;
|
||||
if (atomic_compare_exchange_strong_explicit
|
||||
(&rwl->cnt_and_flag, &zero, WRITER_ACTIVE,
|
||||
memory_order_relaxed, memory_order_relaxed))
|
||||
if (atomic_compare_exchange_strong_relaxed(
|
||||
&rwl->cnt_and_flag, &zero, WRITER_ACTIVE))
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
/* Another active reader or writer is working. */
|
||||
LOCK(&rwl->lock);
|
||||
if (atomic_load_explicit(&rwl->cnt_and_flag, memory_order_relaxed) != 0) {
|
||||
if (atomic_load_relaxed(&rwl->cnt_and_flag) != 0) {
|
||||
WAIT(&rwl->writeable, &rwl->lock);
|
||||
}
|
||||
UNLOCK(&rwl->lock);
|
||||
}
|
||||
|
||||
INSIST((atomic_load_explicit(&rwl->cnt_and_flag, memory_order_relaxed) & WRITER_ACTIVE));
|
||||
rwl->write_granted++;
|
||||
INSIST((atomic_load_relaxed(&rwl->cnt_and_flag)
|
||||
& WRITER_ACTIVE));
|
||||
atomic_fetch_add_relaxed(&rwl->write_granted, 1);
|
||||
}
|
||||
|
||||
#ifdef ISC_RWLOCK_TRACE
|
||||
@@ -326,12 +428,10 @@ isc__rwlock_lock(isc_rwlock_t *rwl, isc_rwlocktype_t type) {
|
||||
isc_result_t
|
||||
isc_rwlock_lock(isc_rwlock_t *rwl, isc_rwlocktype_t type) {
|
||||
int32_t cnt = 0;
|
||||
int32_t max_cnt = rwl->spins * 2 + 10;
|
||||
int32_t spins = atomic_load_relaxed(&rwl->spins) * 2 + 10;
|
||||
int32_t max_cnt = ISC_MAX(spins, RWLOCK_MAX_ADAPTIVE_COUNT);
|
||||
isc_result_t result = ISC_R_SUCCESS;
|
||||
|
||||
if (max_cnt > RWLOCK_MAX_ADAPTIVE_COUNT)
|
||||
max_cnt = RWLOCK_MAX_ADAPTIVE_COUNT;
|
||||
|
||||
do {
|
||||
if (cnt++ >= max_cnt) {
|
||||
result = isc__rwlock_lock(rwl, type);
|
||||
@@ -340,7 +440,7 @@ isc_rwlock_lock(isc_rwlock_t *rwl, isc_rwlocktype_t type) {
|
||||
isc_rwlock_pause();
|
||||
} while (isc_rwlock_trylock(rwl, type) != ISC_R_SUCCESS);
|
||||
|
||||
rwl->spins += (cnt - rwl->spins) / 8;
|
||||
atomic_fetch_add_relaxed(&rwl->spins, (cnt - spins) / 8);
|
||||
|
||||
return (result);
|
||||
}
|
||||
@@ -357,29 +457,28 @@ isc_rwlock_trylock(isc_rwlock_t *rwl, isc_rwlocktype_t type) {
|
||||
|
||||
if (type == isc_rwlocktype_read) {
|
||||
/* If a writer is waiting or working, we fail. */
|
||||
if (atomic_load_explicit(&rwl->write_requests, memory_order_relaxed) !=
|
||||
atomic_load_explicit(&rwl->write_completions, memory_order_relaxed))
|
||||
if (atomic_load_relaxed(&rwl->write_requests) !=
|
||||
atomic_load_relaxed(&rwl->write_completions))
|
||||
return (ISC_R_LOCKBUSY);
|
||||
|
||||
/* Otherwise, be ready for reading. */
|
||||
cntflag = atomic_fetch_add_explicit(&rwl->cnt_and_flag,
|
||||
READER_INCR,
|
||||
memory_order_relaxed);
|
||||
cntflag = atomic_fetch_add_relaxed(&rwl->cnt_and_flag,
|
||||
READER_INCR);
|
||||
if ((cntflag & WRITER_ACTIVE) != 0) {
|
||||
/*
|
||||
* A writer is working. We lose, and cancel the read
|
||||
* request.
|
||||
*/
|
||||
cntflag = atomic_fetch_sub_explicit
|
||||
(&rwl->cnt_and_flag, READER_INCR,
|
||||
memory_order_relaxed);
|
||||
cntflag = atomic_fetch_sub_relaxed(
|
||||
&rwl->cnt_and_flag, READER_INCR);
|
||||
/*
|
||||
* If no other readers are waiting and we've suspended
|
||||
* new writers in this short period, wake them up.
|
||||
*/
|
||||
if (cntflag == READER_INCR &&
|
||||
atomic_load_explicit(&rwl->write_completions, memory_order_relaxed) !=
|
||||
atomic_load_explicit(&rwl->write_requests, memory_order_relaxed)) {
|
||||
atomic_load_relaxed(&rwl->write_completions) !=
|
||||
atomic_load_relaxed(&rwl->write_requests))
|
||||
{
|
||||
LOCK(&rwl->lock);
|
||||
BROADCAST(&rwl->writeable);
|
||||
UNLOCK(&rwl->lock);
|
||||
@@ -390,9 +489,8 @@ isc_rwlock_trylock(isc_rwlock_t *rwl, isc_rwlocktype_t type) {
|
||||
} else {
|
||||
/* Try locking without entering the waiting queue. */
|
||||
int_fast32_t zero = 0;
|
||||
if (!atomic_compare_exchange_strong_explicit
|
||||
(&rwl->cnt_and_flag, &zero, WRITER_ACTIVE,
|
||||
memory_order_relaxed, memory_order_relaxed))
|
||||
if (!atomic_compare_exchange_strong_relaxed(
|
||||
&rwl->cnt_and_flag, &zero, WRITER_ACTIVE))
|
||||
{
|
||||
return (ISC_R_LOCKBUSY);
|
||||
}
|
||||
@@ -401,10 +499,8 @@ isc_rwlock_trylock(isc_rwlock_t *rwl, isc_rwlocktype_t type) {
|
||||
* XXXJT: jump into the queue, possibly breaking the writer
|
||||
* order.
|
||||
*/
|
||||
atomic_fetch_sub_explicit(&rwl->write_completions, 1,
|
||||
memory_order_relaxed);
|
||||
|
||||
rwl->write_granted++;
|
||||
atomic_fetch_sub_relaxed(&rwl->write_completions, 1);
|
||||
atomic_fetch_add_relaxed(&rwl->write_granted, 1);
|
||||
}
|
||||
|
||||
#ifdef ISC_RWLOCK_TRACE
|
||||
@@ -422,9 +518,8 @@ isc_rwlock_tryupgrade(isc_rwlock_t *rwl) {
|
||||
int_fast32_t reader_incr = READER_INCR;
|
||||
|
||||
/* Try to acquire write access. */
|
||||
atomic_compare_exchange_strong_explicit
|
||||
(&rwl->cnt_and_flag, &reader_incr, WRITER_ACTIVE,
|
||||
memory_order_relaxed, memory_order_relaxed);
|
||||
atomic_compare_exchange_strong_relaxed(
|
||||
&rwl->cnt_and_flag, &reader_incr, WRITER_ACTIVE);
|
||||
/*
|
||||
* There must have been no writer, and there must have
|
||||
* been at least one reader.
|
||||
@@ -437,8 +532,7 @@ isc_rwlock_tryupgrade(isc_rwlock_t *rwl) {
|
||||
* We are the only reader and have been upgraded.
|
||||
* Now jump into the head of the writer waiting queue.
|
||||
*/
|
||||
atomic_fetch_sub_explicit(&rwl->write_completions, 1,
|
||||
memory_order_relaxed);
|
||||
atomic_fetch_sub_relaxed(&rwl->write_completions, 1);
|
||||
} else
|
||||
return (ISC_R_LOCKBUSY);
|
||||
|
||||
@@ -455,17 +549,14 @@ isc_rwlock_downgrade(isc_rwlock_t *rwl) {
|
||||
|
||||
{
|
||||
/* Become an active reader. */
|
||||
prev_readers = atomic_fetch_add_explicit(&rwl->cnt_and_flag,
|
||||
READER_INCR,
|
||||
memory_order_relaxed);
|
||||
prev_readers = atomic_fetch_add_relaxed(&rwl->cnt_and_flag,
|
||||
READER_INCR);
|
||||
/* We must have been a writer. */
|
||||
INSIST((prev_readers & WRITER_ACTIVE) != 0);
|
||||
|
||||
/* Complete write */
|
||||
atomic_fetch_sub_explicit(&rwl->cnt_and_flag, WRITER_ACTIVE,
|
||||
memory_order_relaxed);
|
||||
atomic_fetch_add_explicit(&rwl->write_completions, 1,
|
||||
memory_order_relaxed);
|
||||
atomic_fetch_sub_relaxed(&rwl->cnt_and_flag, WRITER_ACTIVE);
|
||||
atomic_fetch_add_relaxed(&rwl->write_completions, 1);
|
||||
}
|
||||
|
||||
/* Resume other readers */
|
||||
@@ -486,17 +577,16 @@ isc_rwlock_unlock(isc_rwlock_t *rwl, isc_rwlocktype_t type) {
|
||||
#endif
|
||||
|
||||
if (type == isc_rwlocktype_read) {
|
||||
prev_cnt = atomic_fetch_sub_explicit(&rwl->cnt_and_flag,
|
||||
READER_INCR,
|
||||
memory_order_relaxed);
|
||||
prev_cnt = atomic_fetch_sub_relaxed(&rwl->cnt_and_flag,
|
||||
READER_INCR);
|
||||
/*
|
||||
* If we're the last reader and any writers are waiting, wake
|
||||
* them up. We need to wake up all of them to ensure the
|
||||
* FIFO order.
|
||||
*/
|
||||
if (prev_cnt == READER_INCR &&
|
||||
atomic_load_explicit(&rwl->write_completions, memory_order_relaxed) !=
|
||||
atomic_load_explicit(&rwl->write_requests, memory_order_relaxed)) {
|
||||
atomic_load_relaxed(&rwl->write_completions) !=
|
||||
atomic_load_relaxed(&rwl->write_requests)) {
|
||||
LOCK(&rwl->lock);
|
||||
BROADCAST(&rwl->writeable);
|
||||
UNLOCK(&rwl->lock);
|
||||
@@ -508,15 +598,15 @@ isc_rwlock_unlock(isc_rwlock_t *rwl, isc_rwlocktype_t type) {
|
||||
* Reset the flag, and (implicitly) tell other writers
|
||||
* we are done.
|
||||
*/
|
||||
atomic_fetch_sub_explicit(&rwl->cnt_and_flag, WRITER_ACTIVE,
|
||||
memory_order_relaxed);
|
||||
atomic_fetch_add_explicit(&rwl->write_completions, 1,
|
||||
memory_order_relaxed);
|
||||
atomic_fetch_sub_relaxed(&rwl->cnt_and_flag, WRITER_ACTIVE);
|
||||
atomic_fetch_add_relaxed(&rwl->write_completions, 1);
|
||||
|
||||
if (rwl->write_granted >= rwl->write_quota ||
|
||||
(atomic_load_explicit(&rwl->write_requests, memory_order_relaxed) ==
|
||||
atomic_load_explicit(&rwl->write_completions, memory_order_relaxed)) ||
|
||||
(atomic_load_explicit(&rwl->cnt_and_flag, memory_order_relaxed) & ~WRITER_ACTIVE)) {
|
||||
(atomic_load_relaxed(&rwl->write_requests) ==
|
||||
atomic_load_relaxed(&rwl->write_completions)) ||
|
||||
(atomic_load_relaxed(&rwl->cnt_and_flag)
|
||||
& ~WRITER_ACTIVE))
|
||||
{
|
||||
/*
|
||||
* We have passed the write quota, no writer is
|
||||
* waiting, or some readers are almost ready, pending
|
||||
@@ -533,8 +623,8 @@ isc_rwlock_unlock(isc_rwlock_t *rwl, isc_rwlocktype_t type) {
|
||||
UNLOCK(&rwl->lock);
|
||||
}
|
||||
|
||||
if ((atomic_load_explicit(&rwl->write_requests, memory_order_relaxed) !=
|
||||
atomic_load_explicit(&rwl->write_completions, memory_order_relaxed)) &&
|
||||
if ((atomic_load_relaxed(&rwl->write_requests) !=
|
||||
atomic_load_relaxed(&rwl->write_completions)) &&
|
||||
wakeup_writers) {
|
||||
LOCK(&rwl->lock);
|
||||
BROADCAST(&rwl->writeable);
|
||||
@@ -549,3 +639,5 @@ isc_rwlock_unlock(isc_rwlock_t *rwl, isc_rwlocktype_t type) {
|
||||
|
||||
return (ISC_R_SUCCESS);
|
||||
}
|
||||
|
||||
#endif /* USE_PTHREAD_RWLOCK·||·__has_feature(thread_sanitizer)$ */
|
||||
|
||||
+1
-4
@@ -1871,7 +1871,7 @@ isc_taskmgr_renderjson(isc_taskmgr_t *mgr0, json_object *tasks) {
|
||||
|
||||
|
||||
isc_result_t
|
||||
isc_taskmgr_createinctx(isc_mem_t *mctx, isc_appctx_t *actx,
|
||||
isc_taskmgr_createinctx(isc_mem_t *mctx,
|
||||
unsigned int workers, unsigned int default_quantum,
|
||||
isc_taskmgr_t **managerp)
|
||||
{
|
||||
@@ -1880,8 +1880,5 @@ isc_taskmgr_createinctx(isc_mem_t *mctx, isc_appctx_t *actx,
|
||||
result = isc_taskmgr_create(mctx, workers, default_quantum,
|
||||
managerp);
|
||||
|
||||
if (result == ISC_R_SUCCESS)
|
||||
isc_appctx_settaskmgr(actx, *managerp);
|
||||
|
||||
return (result);
|
||||
}
|
||||
|
||||
+1
-5
@@ -784,15 +784,11 @@ isc_timermgr_destroy(isc_timermgr_t **managerp) {
|
||||
}
|
||||
|
||||
isc_result_t
|
||||
isc_timermgr_createinctx(isc_mem_t *mctx, isc_appctx_t *actx,
|
||||
isc_timermgr_t **managerp)
|
||||
isc_timermgr_createinctx(isc_mem_t *mctx, isc_timermgr_t **managerp)
|
||||
{
|
||||
isc_result_t result;
|
||||
|
||||
result = isc_timermgr_create(mctx, managerp);
|
||||
|
||||
if (result == ISC_R_SUCCESS)
|
||||
isc_appctx_settimermgr(actx, *managerp);
|
||||
|
||||
return (result);
|
||||
}
|
||||
|
||||
+159
-340
@@ -27,6 +27,7 @@
|
||||
#endif
|
||||
|
||||
#include <isc/platform.h>
|
||||
#include <isc/atomic.h>
|
||||
#include <isc/app.h>
|
||||
#include <isc/condition.h>
|
||||
#include <isc/mem.h>
|
||||
@@ -48,7 +49,7 @@
|
||||
* as an event loop dispatching various events.
|
||||
*/
|
||||
static pthread_t blockedthread;
|
||||
static bool is_running;
|
||||
static atomic_bool is_running;
|
||||
|
||||
/*
|
||||
* The application context of this module. This implementation actually
|
||||
@@ -57,72 +58,41 @@ static bool is_running;
|
||||
#define APPCTX_MAGIC ISC_MAGIC('A', 'p', 'c', 'x')
|
||||
#define VALID_APPCTX(c) ISC_MAGIC_VALID(c, APPCTX_MAGIC)
|
||||
|
||||
typedef struct isc__appctx {
|
||||
isc_appctx_t common;
|
||||
struct isc_appctx {
|
||||
unsigned int magic;
|
||||
isc_mem_t *mctx;
|
||||
isc_mutex_t lock;
|
||||
isc_eventlist_t on_run;
|
||||
bool shutdown_requested;
|
||||
bool running;
|
||||
|
||||
/*!
|
||||
* We assume that 'want_shutdown' can be read and written atomically.
|
||||
*/
|
||||
bool want_shutdown;
|
||||
/*
|
||||
* We assume that 'want_reload' can be read and written atomically.
|
||||
*/
|
||||
bool want_reload;
|
||||
|
||||
bool blocked;
|
||||
|
||||
isc_taskmgr_t *taskmgr;
|
||||
isc_socketmgr_t *socketmgr;
|
||||
isc_timermgr_t *timermgr;
|
||||
isc_eventlist_t on_run;
|
||||
atomic_bool shutdown_requested;
|
||||
atomic_bool running;
|
||||
atomic_bool want_shutdown;
|
||||
atomic_bool want_reload;
|
||||
atomic_bool blocked;
|
||||
isc_mutex_t readylock;
|
||||
isc_condition_t ready;
|
||||
} isc__appctx_t;
|
||||
isc_condition_t ready;
|
||||
};
|
||||
|
||||
static isc__appctx_t isc_g_appctx;
|
||||
|
||||
#ifndef HAVE_SIGWAIT
|
||||
static void
|
||||
exit_action(int arg) {
|
||||
UNUSED(arg);
|
||||
isc_g_appctx.want_shutdown = true;
|
||||
}
|
||||
static isc_appctx_t isc_g_appctx;
|
||||
|
||||
static void
|
||||
reload_action(int arg) {
|
||||
UNUSED(arg);
|
||||
isc_g_appctx.want_reload = true;
|
||||
}
|
||||
#endif
|
||||
|
||||
static isc_result_t
|
||||
handle_signal(int sig, void (*handler)(int)) {
|
||||
struct sigaction sa;
|
||||
char strbuf[ISC_STRERRORSIZE];
|
||||
|
||||
memset(&sa, 0, sizeof(sa));
|
||||
sa.sa_handler = handler;
|
||||
|
||||
if (sigfillset(&sa.sa_mask) != 0 ||
|
||||
sigaction(sig, &sa, NULL) < 0) {
|
||||
char strbuf[ISC_STRERRORSIZE];
|
||||
strerror_r(errno, strbuf, sizeof(strbuf));
|
||||
UNEXPECTED_ERROR(__FILE__, __LINE__,
|
||||
isc_error_fatal(__FILE__, __LINE__,
|
||||
"handle_signal() %d setup: %s",
|
||||
sig, strbuf);
|
||||
return (ISC_R_UNEXPECTED);
|
||||
}
|
||||
|
||||
return (ISC_R_SUCCESS);
|
||||
}
|
||||
|
||||
isc_result_t
|
||||
isc_app_ctxstart(isc_appctx_t *ctx0) {
|
||||
isc__appctx_t *ctx = (isc__appctx_t *)ctx0;
|
||||
isc_result_t result;
|
||||
isc_app_ctxstart(isc_appctx_t *ctx) {
|
||||
int presult;
|
||||
sigset_t sset;
|
||||
char strbuf[ISC_STRERRORSIZE];
|
||||
@@ -133,64 +103,27 @@ isc_app_ctxstart(isc_appctx_t *ctx0) {
|
||||
* Start an ISC library application.
|
||||
*/
|
||||
|
||||
isc_mutex_init(&ctx->readylock);
|
||||
|
||||
isc_condition_init(&ctx->ready);
|
||||
|
||||
isc_mutex_init(&ctx->lock);
|
||||
|
||||
isc_mutex_init(&ctx->readylock);
|
||||
isc_condition_init(&ctx->ready);
|
||||
|
||||
ISC_LIST_INIT(ctx->on_run);
|
||||
|
||||
ctx->shutdown_requested = false;
|
||||
ctx->running = false;
|
||||
ctx->want_shutdown = false;
|
||||
ctx->want_reload = false;
|
||||
ctx->blocked = false;
|
||||
|
||||
#ifndef HAVE_SIGWAIT
|
||||
/*
|
||||
* Install do-nothing handlers for SIGINT and SIGTERM.
|
||||
*
|
||||
* We install them now because BSDI 3.1 won't block
|
||||
* the default actions, regardless of what we do with
|
||||
* pthread_sigmask().
|
||||
*/
|
||||
result = handle_signal(SIGINT, exit_action);
|
||||
if (result != ISC_R_SUCCESS)
|
||||
goto cleanup;
|
||||
result = handle_signal(SIGTERM, exit_action);
|
||||
if (result != ISC_R_SUCCESS)
|
||||
goto cleanup;
|
||||
#endif
|
||||
atomic_init(&ctx->shutdown_requested, false);
|
||||
atomic_init(&ctx->running, false);
|
||||
atomic_init(&ctx->want_shutdown, false);
|
||||
atomic_init(&ctx->want_reload, false);
|
||||
atomic_init(&ctx->blocked, false);
|
||||
|
||||
/*
|
||||
* Always ignore SIGPIPE.
|
||||
*/
|
||||
result = handle_signal(SIGPIPE, SIG_IGN);
|
||||
if (result != ISC_R_SUCCESS)
|
||||
goto cleanup;
|
||||
handle_signal(SIGPIPE, SIG_IGN);
|
||||
|
||||
/*
|
||||
* On Solaris 2, delivery of a signal whose action is SIG_IGN
|
||||
* will not cause sigwait() to return. We may have inherited
|
||||
* unexpected actions for SIGHUP, SIGINT, and SIGTERM from our parent
|
||||
* process (e.g, Solaris cron). Set an action of SIG_DFL to make
|
||||
* sure sigwait() works as expected. Only do this for SIGTERM and
|
||||
* SIGINT if we don't have sigwait(), since a different handler is
|
||||
* installed above.
|
||||
*/
|
||||
result = handle_signal(SIGHUP, SIG_DFL);
|
||||
if (result != ISC_R_SUCCESS)
|
||||
goto cleanup;
|
||||
|
||||
#ifdef HAVE_SIGWAIT
|
||||
result = handle_signal(SIGTERM, SIG_DFL);
|
||||
if (result != ISC_R_SUCCESS)
|
||||
goto cleanup;
|
||||
result = handle_signal(SIGINT, SIG_DFL);
|
||||
if (result != ISC_R_SUCCESS)
|
||||
goto cleanup;
|
||||
#endif
|
||||
handle_signal(SIGHUP, SIG_DFL);
|
||||
handle_signal(SIGTERM, SIG_DFL);
|
||||
handle_signal(SIGINT, SIG_DFL);
|
||||
|
||||
/*
|
||||
* Block SIGHUP, SIGINT, SIGTERM.
|
||||
@@ -206,61 +139,45 @@ isc_app_ctxstart(isc_appctx_t *ctx0) {
|
||||
sigaddset(&sset, SIGINT) != 0 ||
|
||||
sigaddset(&sset, SIGTERM) != 0) {
|
||||
strerror_r(errno, strbuf, sizeof(strbuf));
|
||||
UNEXPECTED_ERROR(__FILE__, __LINE__,
|
||||
isc_error_fatal(__FILE__, __LINE__,
|
||||
"isc_app_start() sigsetops: %s", strbuf);
|
||||
result = ISC_R_UNEXPECTED;
|
||||
goto cleanup;
|
||||
}
|
||||
presult = pthread_sigmask(SIG_BLOCK, &sset, NULL);
|
||||
if (presult != 0) {
|
||||
strerror_r(presult, strbuf, sizeof(strbuf));
|
||||
UNEXPECTED_ERROR(__FILE__, __LINE__,
|
||||
isc_error_fatal(__FILE__, __LINE__,
|
||||
"isc_app_start() pthread_sigmask: %s",
|
||||
strbuf);
|
||||
result = ISC_R_UNEXPECTED;
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
return (ISC_R_SUCCESS);
|
||||
|
||||
cleanup:
|
||||
(void)isc_condition_destroy(&ctx->ready);
|
||||
(void)isc_mutex_destroy(&ctx->readylock);
|
||||
return (result);
|
||||
}
|
||||
|
||||
isc_result_t
|
||||
isc_app_start(void) {
|
||||
isc_g_appctx.common.impmagic = APPCTX_MAGIC;
|
||||
isc_g_appctx.common.magic = ISCAPI_APPCTX_MAGIC;
|
||||
isc_g_appctx.magic = APPCTX_MAGIC;
|
||||
isc_g_appctx.mctx = NULL;
|
||||
/* The remaining members will be initialized in ctxstart() */
|
||||
|
||||
return (isc_app_ctxstart((isc_appctx_t *)&isc_g_appctx));
|
||||
return (isc_app_ctxstart(&isc_g_appctx));
|
||||
}
|
||||
|
||||
isc_result_t
|
||||
isc_app_onrun(isc_mem_t *mctx, isc_task_t *task, isc_taskaction_t action,
|
||||
void *arg)
|
||||
{
|
||||
return (isc_app_ctxonrun((isc_appctx_t *)&isc_g_appctx, mctx,
|
||||
task, action, arg));
|
||||
return (isc_app_ctxonrun(&isc_g_appctx, mctx, task, action, arg));
|
||||
}
|
||||
|
||||
isc_result_t
|
||||
isc_app_ctxonrun(isc_appctx_t *ctx0, isc_mem_t *mctx, isc_task_t *task,
|
||||
isc_app_ctxonrun(isc_appctx_t *ctx, isc_mem_t *mctx, isc_task_t *task,
|
||||
isc_taskaction_t action, void *arg)
|
||||
{
|
||||
isc__appctx_t *ctx = (isc__appctx_t *)ctx0;
|
||||
isc_event_t *event;
|
||||
isc_task_t *cloned_task = NULL;
|
||||
isc_result_t result;
|
||||
|
||||
LOCK(&ctx->lock);
|
||||
|
||||
if (ctx->running) {
|
||||
result = ISC_R_ALREADYRUNNING;
|
||||
goto unlock;
|
||||
if (atomic_load_acquire(&ctx->running)) {
|
||||
return (ISC_R_ALREADYRUNNING);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -272,42 +189,34 @@ isc_app_ctxonrun(isc_appctx_t *ctx0, isc_mem_t *mctx, isc_task_t *task,
|
||||
action, arg, sizeof(*event));
|
||||
if (event == NULL) {
|
||||
isc_task_detach(&cloned_task);
|
||||
result = ISC_R_NOMEMORY;
|
||||
goto unlock;
|
||||
return (ISC_R_NOMEMORY);
|
||||
}
|
||||
|
||||
LOCK(&ctx->lock);
|
||||
ISC_LIST_APPEND(ctx->on_run, event, ev_link);
|
||||
|
||||
result = ISC_R_SUCCESS;
|
||||
|
||||
unlock:
|
||||
UNLOCK(&ctx->lock);
|
||||
|
||||
return (result);
|
||||
return(ISC_R_SUCCESS);
|
||||
}
|
||||
|
||||
isc_result_t
|
||||
isc_app_ctxrun(isc_appctx_t *ctx0) {
|
||||
isc__appctx_t *ctx = (isc__appctx_t *)ctx0;
|
||||
int result;
|
||||
isc_app_ctxrun(isc_appctx_t *ctx) {
|
||||
isc_event_t *event, *next_event;
|
||||
isc_task_t *task;
|
||||
sigset_t sset;
|
||||
char strbuf[ISC_STRERRORSIZE];
|
||||
#ifdef HAVE_SIGWAIT
|
||||
int sig;
|
||||
#endif /* HAVE_SIGWAIT */
|
||||
bool exp_false = false;
|
||||
bool exp_true = true;
|
||||
|
||||
REQUIRE(VALID_APPCTX(ctx));
|
||||
|
||||
LOCK(&ctx->lock);
|
||||
|
||||
if (!ctx->running) {
|
||||
ctx->running = true;
|
||||
|
||||
if (atomic_compare_exchange_weak_acq_rel(
|
||||
&ctx->running, &exp_false, true) == true)
|
||||
{
|
||||
/*
|
||||
* Post any on-run events (in FIFO order).
|
||||
*/
|
||||
LOCK(&ctx->lock);
|
||||
for (event = ISC_LIST_HEAD(ctx->on_run);
|
||||
event != NULL;
|
||||
event = next_event) {
|
||||
@@ -317,17 +226,15 @@ isc_app_ctxrun(isc_appctx_t *ctx0) {
|
||||
event->ev_sender = NULL;
|
||||
isc_task_sendanddetach(&task, &event);
|
||||
}
|
||||
|
||||
UNLOCK(&ctx->lock);
|
||||
}
|
||||
|
||||
UNLOCK(&ctx->lock);
|
||||
|
||||
/*
|
||||
* BIND9 internal tools using multiple contexts do not
|
||||
* rely on signal.
|
||||
*/
|
||||
if (isc_bind9 && ctx != &isc_g_appctx)
|
||||
* rely on signal. */
|
||||
if (isc_bind9 && ctx != &isc_g_appctx) {
|
||||
return (ISC_R_SUCCESS);
|
||||
}
|
||||
|
||||
/*
|
||||
* There is no danger if isc_app_shutdown() is called before we
|
||||
@@ -335,8 +242,7 @@ isc_app_ctxrun(isc_appctx_t *ctx0) {
|
||||
* simply be made pending and we will get it when we call
|
||||
* sigwait().
|
||||
*/
|
||||
while (!ctx->want_shutdown) {
|
||||
#ifdef HAVE_SIGWAIT
|
||||
while (atomic_load_acquire(&ctx->want_shutdown) == false) {
|
||||
if (isc_bind9) {
|
||||
/*
|
||||
* BIND9 internal; single context:
|
||||
@@ -346,88 +252,56 @@ isc_app_ctxrun(isc_appctx_t *ctx0) {
|
||||
sigaddset(&sset, SIGHUP) != 0 ||
|
||||
sigaddset(&sset, SIGINT) != 0 ||
|
||||
sigaddset(&sset, SIGTERM) != 0) {
|
||||
char strbuf[ISC_STRERRORSIZE];
|
||||
strerror_r(errno, strbuf, sizeof(strbuf));
|
||||
UNEXPECTED_ERROR(__FILE__, __LINE__,
|
||||
"isc_app_run() sigsetops: %s",
|
||||
strbuf);
|
||||
return (ISC_R_UNEXPECTED);
|
||||
isc_error_fatal(__FILE__, __LINE__,
|
||||
"isc_app_run() sigsetops: %s",
|
||||
strbuf);
|
||||
}
|
||||
|
||||
result = sigwait(&sset, &sig);
|
||||
if (result == 0) {
|
||||
if (sig == SIGINT || sig == SIGTERM)
|
||||
ctx->want_shutdown = true;
|
||||
else if (sig == SIGHUP)
|
||||
ctx->want_reload = true;
|
||||
if (sigwait(&sset, &sig) == 0) {
|
||||
switch (sig) {
|
||||
case SIGINT:
|
||||
case SIGTERM:
|
||||
atomic_store_release(
|
||||
&ctx->want_shutdown, true);
|
||||
break;
|
||||
case SIGHUP:
|
||||
atomic_store_release(
|
||||
&ctx->want_reload, true);
|
||||
break;
|
||||
default:
|
||||
INSIST(0);
|
||||
ISC_UNREACHABLE();
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
/*
|
||||
* External, or BIND9 using multiple contexts:
|
||||
* wait until woken up.
|
||||
*/
|
||||
LOCK(&ctx->readylock);
|
||||
if (ctx->want_shutdown) {
|
||||
/* shutdown() won the race. */
|
||||
UNLOCK(&ctx->readylock);
|
||||
if (atomic_load_acquire(&ctx->want_shutdown)) {
|
||||
break;
|
||||
}
|
||||
if (!ctx->want_reload)
|
||||
if (!atomic_load_acquire(&ctx->want_reload)) {
|
||||
LOCK(&ctx->readylock);
|
||||
WAIT(&ctx->ready, &ctx->readylock);
|
||||
UNLOCK(&ctx->readylock);
|
||||
}
|
||||
#else /* Don't have sigwait(). */
|
||||
if (isc_bind9) {
|
||||
/*
|
||||
* BIND9 internal; single context:
|
||||
* Install a signal handler for SIGHUP, then wait for
|
||||
* all signals.
|
||||
*/
|
||||
result = handle_signal(SIGHUP, reload_action);
|
||||
if (result != ISC_R_SUCCESS)
|
||||
return (ISC_R_SUCCESS);
|
||||
|
||||
if (sigemptyset(&sset) != 0) {
|
||||
strerror_r(errno, strbuf, sizeof(strbuf));
|
||||
UNEXPECTED_ERROR(__FILE__, __LINE__,
|
||||
"isc_app_run() sigsetops: %s",
|
||||
strbuf);
|
||||
return (ISC_R_UNEXPECTED);
|
||||
}
|
||||
#ifdef HAVE_GPERFTOOLS_PROFILER
|
||||
if (sigaddset(&sset, SIGALRM) != 0) {
|
||||
strerror_r(errno, strbuf, sizeof(strbuf));
|
||||
UNEXPECTED_ERROR(__FILE__, __LINE__,
|
||||
"isc_app_run() sigsetops: %s",
|
||||
strbuf);
|
||||
return (ISC_R_UNEXPECTED);
|
||||
}
|
||||
#endif
|
||||
(void)sigsuspend(&sset);
|
||||
} else {
|
||||
/*
|
||||
* External, or BIND9 using multiple contexts:
|
||||
* wait until woken up.
|
||||
*/
|
||||
LOCK(&ctx->readylock);
|
||||
if (ctx->want_shutdown) {
|
||||
/* shutdown() won the race. */
|
||||
UNLOCK(&ctx->readylock);
|
||||
break;
|
||||
}
|
||||
if (!ctx->want_reload)
|
||||
WAIT(&ctx->ready, &ctx->readylock);
|
||||
UNLOCK(&ctx->readylock);
|
||||
}
|
||||
#endif /* HAVE_SIGWAIT */
|
||||
|
||||
if (ctx->want_reload) {
|
||||
ctx->want_reload = false;
|
||||
exp_true = true;
|
||||
if (atomic_compare_exchange_weak_acq_rel(&ctx->want_reload,
|
||||
&exp_true,
|
||||
false))
|
||||
{
|
||||
return (ISC_R_RELOAD);
|
||||
}
|
||||
|
||||
if (ctx->want_shutdown && ctx->blocked)
|
||||
if (atomic_load_acquire(&ctx->want_shutdown) &&
|
||||
atomic_load_acquire(&ctx->blocked)) {
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
return (ISC_R_SUCCESS);
|
||||
@@ -436,139 +310,113 @@ isc_app_ctxrun(isc_appctx_t *ctx0) {
|
||||
isc_result_t
|
||||
isc_app_run(void) {
|
||||
isc_result_t result;
|
||||
bool exp_false = false;
|
||||
|
||||
is_running = true;
|
||||
result = isc_app_ctxrun((isc_appctx_t *)&isc_g_appctx);
|
||||
is_running = false;
|
||||
REQUIRE(atomic_compare_exchange_weak_acq_rel(
|
||||
&is_running, &exp_false, true) == true);
|
||||
result = isc_app_ctxrun(&isc_g_appctx);
|
||||
atomic_store_release(&is_running, false);
|
||||
|
||||
return (result);
|
||||
}
|
||||
|
||||
bool
|
||||
isc_app_isrunning() {
|
||||
return (is_running);
|
||||
return (atomic_load_acquire(&is_running));
|
||||
}
|
||||
|
||||
isc_result_t
|
||||
isc_app_ctxshutdown(isc_appctx_t *ctx0) {
|
||||
isc__appctx_t *ctx = (isc__appctx_t *)ctx0;
|
||||
bool want_kill = true;
|
||||
char strbuf[ISC_STRERRORSIZE];
|
||||
void
|
||||
isc_app_ctxshutdown(isc_appctx_t *ctx) {
|
||||
bool exp_false = false;
|
||||
|
||||
REQUIRE(VALID_APPCTX(ctx));
|
||||
|
||||
LOCK(&ctx->lock);
|
||||
REQUIRE(atomic_load_acquire(&ctx->running));
|
||||
|
||||
REQUIRE(ctx->running);
|
||||
|
||||
if (ctx->shutdown_requested)
|
||||
want_kill = false;
|
||||
else
|
||||
ctx->shutdown_requested = true;
|
||||
|
||||
UNLOCK(&ctx->lock);
|
||||
|
||||
if (want_kill) {
|
||||
if (isc_bind9 && ctx != &isc_g_appctx)
|
||||
/* If ctx->shutdown_requested == true, we are already shutting
|
||||
* down and we want to just bail out.
|
||||
*/
|
||||
if (atomic_compare_exchange_weak_acq_rel(
|
||||
&ctx->shutdown_requested,
|
||||
&exp_false,
|
||||
true))
|
||||
{
|
||||
if (isc_bind9 && ctx != &isc_g_appctx) {
|
||||
/* BIND9 internal, but using multiple contexts */
|
||||
ctx->want_shutdown = true;
|
||||
else {
|
||||
if (isc_bind9) {
|
||||
/* BIND9 internal, single context */
|
||||
if (kill(getpid(), SIGTERM) < 0) {
|
||||
strerror_r(errno,
|
||||
strbuf, sizeof(strbuf));
|
||||
UNEXPECTED_ERROR(__FILE__, __LINE__,
|
||||
"isc_app_shutdown() "
|
||||
"kill: %s", strbuf);
|
||||
return (ISC_R_UNEXPECTED);
|
||||
}
|
||||
}
|
||||
else {
|
||||
/* External, multiple contexts */
|
||||
LOCK(&ctx->readylock);
|
||||
ctx->want_shutdown = true;
|
||||
UNLOCK(&ctx->readylock);
|
||||
SIGNAL(&ctx->ready);
|
||||
atomic_store_release(&ctx->want_shutdown, true);
|
||||
} else if (isc_bind9) {
|
||||
/* BIND9 internal, single context */
|
||||
if (kill(getpid(), SIGTERM) < 0) {
|
||||
char strbuf[ISC_STRERRORSIZE];
|
||||
strerror_r(errno,
|
||||
strbuf, sizeof(strbuf));
|
||||
isc_error_fatal(__FILE__, __LINE__,
|
||||
"isc_app_shutdown() "
|
||||
"kill: %s", strbuf);
|
||||
}
|
||||
} else {
|
||||
/* External, multiple contexts */
|
||||
atomic_store_release(&ctx->want_shutdown, true);
|
||||
SIGNAL(&ctx->ready);
|
||||
}
|
||||
}
|
||||
|
||||
return (ISC_R_SUCCESS);
|
||||
}
|
||||
|
||||
isc_result_t
|
||||
void
|
||||
isc_app_shutdown(void) {
|
||||
return (isc_app_ctxshutdown((isc_appctx_t *)&isc_g_appctx));
|
||||
isc_app_ctxshutdown(&isc_g_appctx);
|
||||
}
|
||||
|
||||
isc_result_t
|
||||
isc_app_ctxsuspend(isc_appctx_t *ctx0) {
|
||||
isc__appctx_t *ctx = (isc__appctx_t *)ctx0;
|
||||
bool want_kill = true;
|
||||
char strbuf[ISC_STRERRORSIZE];
|
||||
|
||||
void
|
||||
isc_app_ctxsuspend(isc_appctx_t *ctx) {
|
||||
REQUIRE(VALID_APPCTX(ctx));
|
||||
|
||||
LOCK(&ctx->lock);
|
||||
|
||||
REQUIRE(ctx->running);
|
||||
REQUIRE(atomic_load(&ctx->running));
|
||||
|
||||
/*
|
||||
* Don't send the reload signal if we're shutting down.
|
||||
*/
|
||||
if (ctx->shutdown_requested)
|
||||
want_kill = false;
|
||||
|
||||
UNLOCK(&ctx->lock);
|
||||
|
||||
if (want_kill) {
|
||||
if (isc_bind9 && ctx != &isc_g_appctx)
|
||||
if (atomic_load_acquire(&ctx->shutdown_requested) == false) {
|
||||
if (isc_bind9 && ctx != &isc_g_appctx) {
|
||||
/* BIND9 internal, but using multiple contexts */
|
||||
ctx->want_reload = true;
|
||||
else {
|
||||
ctx->want_reload = true;
|
||||
if (isc_bind9) {
|
||||
/* BIND9 internal, single context */
|
||||
if (kill(getpid(), SIGHUP) < 0) {
|
||||
strerror_r(errno,
|
||||
strbuf, sizeof(strbuf));
|
||||
UNEXPECTED_ERROR(__FILE__, __LINE__,
|
||||
"isc_app_reload() "
|
||||
"kill: %s", strbuf);
|
||||
return (ISC_R_UNEXPECTED);
|
||||
}
|
||||
}
|
||||
else {
|
||||
/* External, multiple contexts */
|
||||
LOCK(&ctx->readylock);
|
||||
ctx->want_reload = true;
|
||||
UNLOCK(&ctx->readylock);
|
||||
SIGNAL(&ctx->ready);
|
||||
atomic_store_release(&ctx->want_reload, true);
|
||||
} else if (isc_bind9) {
|
||||
/* BIND9 internal, single context */
|
||||
if (kill(getpid(), SIGHUP) < 0) {
|
||||
char strbuf[ISC_STRERRORSIZE];
|
||||
strerror_r(errno,
|
||||
strbuf, sizeof(strbuf));
|
||||
isc_error_fatal(__FILE__, __LINE__,
|
||||
"isc_app_reload() "
|
||||
"kill: %s", strbuf);
|
||||
}
|
||||
} else {
|
||||
/* External, multiple contexts */
|
||||
atomic_store_release(&ctx->want_reload, true);
|
||||
SIGNAL(&ctx->ready);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return (ISC_R_SUCCESS);
|
||||
}
|
||||
|
||||
isc_result_t
|
||||
isc_app_reload(void) {
|
||||
return (isc_app_ctxsuspend((isc_appctx_t *)&isc_g_appctx));
|
||||
}
|
||||
|
||||
void
|
||||
isc_app_ctxfinish(isc_appctx_t *ctx0) {
|
||||
isc__appctx_t *ctx = (isc__appctx_t *)ctx0;
|
||||
isc_app_reload(void) {
|
||||
return (isc_app_ctxsuspend(&isc_g_appctx));
|
||||
}
|
||||
|
||||
void
|
||||
isc_app_ctxfinish(isc_appctx_t *ctx) {
|
||||
REQUIRE(VALID_APPCTX(ctx));
|
||||
|
||||
isc_mutex_destroy(&ctx->lock);
|
||||
isc_mutex_destroy(&ctx->readylock);
|
||||
isc_condition_destroy(&ctx->ready);
|
||||
}
|
||||
|
||||
void
|
||||
isc_app_finish(void) {
|
||||
isc_app_ctxfinish((isc_appctx_t *)&isc_g_appctx);
|
||||
isc_app_ctxfinish(&isc_g_appctx);
|
||||
}
|
||||
|
||||
void
|
||||
@@ -577,7 +425,7 @@ isc_app_block(void) {
|
||||
REQUIRE(isc_g_appctx.running);
|
||||
REQUIRE(!isc_g_appctx.blocked);
|
||||
|
||||
isc_g_appctx.blocked = true;
|
||||
atomic_store_release(&isc_g_appctx.blocked, true);
|
||||
blockedthread = pthread_self();
|
||||
RUNTIME_CHECK(sigemptyset(&sset) == 0 &&
|
||||
sigaddset(&sset, SIGINT) == 0 &&
|
||||
@@ -588,11 +436,13 @@ isc_app_block(void) {
|
||||
void
|
||||
isc_app_unblock(void) {
|
||||
sigset_t sset;
|
||||
bool exp_true = true;
|
||||
|
||||
REQUIRE(isc_g_appctx.running);
|
||||
REQUIRE(isc_g_appctx.blocked);
|
||||
|
||||
isc_g_appctx.blocked = false;
|
||||
REQUIRE(atomic_load_acquire(&isc_g_appctx.running));
|
||||
REQUIRE(atomic_compare_exchange_weak_acq_rel(
|
||||
&isc_g_appctx.blocked,
|
||||
&exp_true,
|
||||
false));
|
||||
|
||||
REQUIRE(blockedthread == pthread_self());
|
||||
|
||||
@@ -604,7 +454,7 @@ isc_app_unblock(void) {
|
||||
|
||||
isc_result_t
|
||||
isc_appctx_create(isc_mem_t *mctx, isc_appctx_t **ctxp) {
|
||||
isc__appctx_t *ctx;
|
||||
isc_appctx_t *ctx;
|
||||
|
||||
REQUIRE(mctx != NULL);
|
||||
REQUIRE(ctxp != NULL && *ctxp == NULL);
|
||||
@@ -613,57 +463,26 @@ isc_appctx_create(isc_mem_t *mctx, isc_appctx_t **ctxp) {
|
||||
if (ctx == NULL)
|
||||
return (ISC_R_NOMEMORY);
|
||||
|
||||
ctx->common.impmagic = APPCTX_MAGIC;
|
||||
ctx->common.magic = ISCAPI_APPCTX_MAGIC;
|
||||
ctx->magic = APPCTX_MAGIC;
|
||||
|
||||
ctx->mctx = NULL;
|
||||
isc_mem_attach(mctx, &ctx->mctx);
|
||||
|
||||
ctx->taskmgr = NULL;
|
||||
ctx->socketmgr = NULL;
|
||||
ctx->timermgr = NULL;
|
||||
|
||||
*ctxp = (isc_appctx_t *)ctx;
|
||||
*ctxp = ctx;
|
||||
|
||||
return (ISC_R_SUCCESS);
|
||||
}
|
||||
|
||||
void
|
||||
isc_appctx_destroy(isc_appctx_t **ctxp) {
|
||||
isc__appctx_t *ctx;
|
||||
isc_appctx_t *ctx;
|
||||
|
||||
REQUIRE(ctxp != NULL);
|
||||
ctx = (isc__appctx_t *)*ctxp;
|
||||
ctx = *ctxp;
|
||||
REQUIRE(VALID_APPCTX(ctx));
|
||||
*ctxp = NULL;
|
||||
|
||||
ctx->magic = 0;
|
||||
|
||||
isc_mem_putanddetach(&ctx->mctx, ctx, sizeof(*ctx));
|
||||
|
||||
*ctxp = NULL;
|
||||
}
|
||||
|
||||
void
|
||||
isc_appctx_settaskmgr(isc_appctx_t *ctx0, isc_taskmgr_t *taskmgr) {
|
||||
isc__appctx_t *ctx = (isc__appctx_t *)ctx0;
|
||||
|
||||
REQUIRE(VALID_APPCTX(ctx));
|
||||
|
||||
ctx->taskmgr = taskmgr;
|
||||
}
|
||||
|
||||
void
|
||||
isc_appctx_setsocketmgr(isc_appctx_t *ctx0, isc_socketmgr_t *socketmgr) {
|
||||
isc__appctx_t *ctx = (isc__appctx_t *)ctx0;
|
||||
|
||||
REQUIRE(VALID_APPCTX(ctx));
|
||||
|
||||
ctx->socketmgr = socketmgr;
|
||||
}
|
||||
|
||||
void
|
||||
isc_appctx_settimermgr(isc_appctx_t *ctx0, isc_timermgr_t *timermgr) {
|
||||
isc__appctx_t *ctx = (isc__appctx_t *)ctx0;
|
||||
|
||||
REQUIRE(VALID_APPCTX(ctx));
|
||||
|
||||
ctx->timermgr = timermgr;
|
||||
}
|
||||
|
||||
@@ -5593,15 +5593,11 @@ isc_socketmgr_renderjson(isc_socketmgr_t *mgr0, json_object *stats) {
|
||||
#endif /* HAVE_JSON */
|
||||
|
||||
isc_result_t
|
||||
isc_socketmgr_createinctx(isc_mem_t *mctx, isc_appctx_t *actx,
|
||||
isc_socketmgr_t **managerp)
|
||||
isc_socketmgr_createinctx(isc_mem_t *mctx, isc_socketmgr_t **managerp)
|
||||
{
|
||||
isc_result_t result;
|
||||
|
||||
result = isc_socketmgr_create(mctx, managerp);
|
||||
|
||||
if (result == ISC_R_SUCCESS)
|
||||
isc_appctx_setsocketmgr(actx, *managerp);
|
||||
|
||||
return (result);
|
||||
}
|
||||
|
||||
+20
-67
@@ -50,7 +50,7 @@ enum {
|
||||
SHUTDOWN_EVENT
|
||||
};
|
||||
|
||||
typedef struct isc__appctx {
|
||||
struct isc_appctx {
|
||||
isc_appctx_t common;
|
||||
isc_mem_t *mctx;
|
||||
isc_eventlist_t on_run;
|
||||
@@ -69,13 +69,9 @@ typedef struct isc__appctx {
|
||||
bool blocked;
|
||||
|
||||
HANDLE hEvents[NUM_EVENTS];
|
||||
};
|
||||
|
||||
isc_taskmgr_t *taskmgr;
|
||||
isc_socketmgr_t *socketmgr;
|
||||
isc_timermgr_t *timermgr;
|
||||
} isc__appctx_t;
|
||||
|
||||
static isc__appctx_t isc_g_appctx;
|
||||
static isc_appctx_t isc_g_appctx;
|
||||
|
||||
/*
|
||||
* We need to remember which thread is the main thread...
|
||||
@@ -83,8 +79,7 @@ static isc__appctx_t isc_g_appctx;
|
||||
static isc_thread_t main_thread;
|
||||
|
||||
isc_result_t
|
||||
isc_app_ctxstart(isc_appctx_t *ctx0) {
|
||||
isc__appctx_t *ctx = (isc__appctx_t *)ctx0;
|
||||
isc_app_ctxstart(isc_appctx_t *ctx) {
|
||||
isc_result_t result;
|
||||
|
||||
REQUIRE(VALID_APPCTX(ctx));
|
||||
@@ -115,27 +110,24 @@ isc_app_ctxstart(isc_appctx_t *ctx0) {
|
||||
|
||||
isc_result_t
|
||||
isc_app_start(void) {
|
||||
isc_g_appctx.common.impmagic = APPCTX_MAGIC;
|
||||
isc_g_appctx.common.magic = ISCAPI_APPCTX_MAGIC;
|
||||
isc_g_appctx.magic = APPCTX_MAGIC;
|
||||
isc_g_appctx.mctx = NULL;
|
||||
/* The remaining members will be initialized in ctxstart() */
|
||||
|
||||
return (isc_app_ctxstart((isc_appctx_t *)&isc_g_appctx));
|
||||
return (isc_app_ctxstart(&isc_g_appctx));
|
||||
}
|
||||
|
||||
isc_result_t
|
||||
isc_app_onrun(isc_mem_t *mctx, isc_task_t *task, isc_taskaction_t action,
|
||||
void *arg)
|
||||
{
|
||||
return (isc_app_ctxonrun((isc_appctx_t *)&isc_g_appctx, mctx,
|
||||
task, action, arg));
|
||||
return (isc_app_ctxonrun(&isc_g_appctx, mctx, task, action, arg));
|
||||
}
|
||||
|
||||
isc_result_t
|
||||
isc_app_ctxonrun(isc_appctx_t *ctx0, isc_mem_t *mctx, isc_task_t *task,
|
||||
isc_app_ctxonrun(isc_appctx_t *ctx, isc_mem_t *mctx, isc_task_t *task,
|
||||
isc_taskaction_t action, void *arg)
|
||||
{
|
||||
isc__appctx_t *ctx = (isc__appctx_t *)ctx0;
|
||||
isc_event_t *event;
|
||||
isc_task_t *cloned_task = NULL;
|
||||
isc_result_t result;
|
||||
@@ -171,8 +163,7 @@ isc_app_ctxonrun(isc_appctx_t *ctx0, isc_mem_t *mctx, isc_task_t *task,
|
||||
}
|
||||
|
||||
isc_result_t
|
||||
isc_app_ctxrun(isc_appctx_t *ctx0) {
|
||||
isc__appctx_t *ctx = (isc__appctx_t *)ctx0;
|
||||
isc_app_ctxrun(isc_appctx_t *ctx) {
|
||||
isc_event_t *event, *next_event;
|
||||
isc_task_t *task;
|
||||
HANDLE *pHandles = NULL;
|
||||
@@ -248,7 +239,7 @@ isc_app_run(void) {
|
||||
isc_result_t result;
|
||||
|
||||
is_running = true;
|
||||
result = isc_app_ctxrun((isc_appctx_t *)&isc_g_appctx);
|
||||
result = isc_app_ctxrun(&isc_g_appctx);
|
||||
is_running = false;
|
||||
|
||||
return (result);
|
||||
@@ -260,8 +251,7 @@ isc_app_isrunning() {
|
||||
}
|
||||
|
||||
isc_result_t
|
||||
isc_app_ctxshutdown(isc_appctx_t *ctx0) {
|
||||
isc__appctx_t *ctx = (isc__appctx_t *)ctx0;
|
||||
isc_app_ctxshutdown(isc_appctx_t *ctx) {
|
||||
bool want_kill = true;
|
||||
|
||||
REQUIRE(VALID_APPCTX(ctx));
|
||||
@@ -285,12 +275,11 @@ isc_app_ctxshutdown(isc_appctx_t *ctx0) {
|
||||
|
||||
isc_result_t
|
||||
isc_app_shutdown(void) {
|
||||
return (isc_app_ctxshutdown((isc_appctx_t *)&isc_g_appctx));
|
||||
return (isc_app_ctxshutdown(&isc_g_appctx));
|
||||
}
|
||||
|
||||
isc_result_t
|
||||
isc_app_ctxsuspend(isc_appctx_t *ctx0) {
|
||||
isc__appctx_t *ctx = (isc__appctx_t *)ctx0;
|
||||
isc_app_ctxsuspend(isc_appctx_t *ctx) {
|
||||
bool want_kill = true;
|
||||
|
||||
REQUIRE(VALID_APPCTX(ctx));
|
||||
@@ -315,13 +304,11 @@ isc_app_ctxsuspend(isc_appctx_t *ctx0) {
|
||||
|
||||
isc_result_t
|
||||
isc_app_reload(void) {
|
||||
return (isc_app_ctxsuspend((isc_appctx_t *)&isc_g_appctx));
|
||||
return (isc_app_ctxsuspend(&isc_g_appctx));
|
||||
}
|
||||
|
||||
void
|
||||
isc_app_ctxfinish(isc_appctx_t *ctx0) {
|
||||
isc__appctx_t *ctx = (isc__appctx_t *)ctx0;
|
||||
|
||||
isc_app_ctxfinish(isc_appctx_t *ctx) {
|
||||
REQUIRE(VALID_APPCTX(ctx));
|
||||
|
||||
isc_mutex_destroy(&ctx->lock);
|
||||
@@ -329,7 +316,7 @@ isc_app_ctxfinish(isc_appctx_t *ctx0) {
|
||||
|
||||
void
|
||||
isc_app_finish(void) {
|
||||
isc_app_ctxfinish((isc_appctx_t *)&isc_g_appctx);
|
||||
isc_app_ctxfinish(&isc_g_appctx);
|
||||
}
|
||||
|
||||
void
|
||||
@@ -352,33 +339,26 @@ isc_app_unblock(void) {
|
||||
|
||||
isc_result_t
|
||||
isc_appctx_create(isc_mem_t *mctx, isc_appctx_t **ctxp) {
|
||||
isc__appctx_t *ctx;
|
||||
isc_appctx_t *ctx;
|
||||
|
||||
REQUIRE(mctx != NULL);
|
||||
REQUIRE(ctxp != NULL && *ctxp == NULL);
|
||||
|
||||
ctx = isc_mem_get(mctx, sizeof(*ctx));
|
||||
if (ctx == NULL)
|
||||
return (ISC_R_NOMEMORY);
|
||||
|
||||
ctx->common.impmagic = APPCTX_MAGIC;
|
||||
ctx->common.magic = ISCAPI_APPCTX_MAGIC;
|
||||
ctx->magic = APPCTX_MAGIC;
|
||||
|
||||
ctx->mctx = NULL;
|
||||
isc_mem_attach(mctx, &ctx->mctx);
|
||||
|
||||
ctx->taskmgr = NULL;
|
||||
ctx->socketmgr = NULL;
|
||||
ctx->timermgr = NULL;
|
||||
|
||||
*ctxp = (isc_appctx_t *)ctx;
|
||||
*ctxp = ctx;
|
||||
|
||||
return (ISC_R_SUCCESS);
|
||||
}
|
||||
|
||||
void
|
||||
isc_appctx_destroy(isc_appctx_t **ctxp) {
|
||||
isc__appctx_t *ctx;
|
||||
isc_appctx_t *ctx;
|
||||
|
||||
REQUIRE(ctxp != NULL);
|
||||
ctx = (isc__appctx_t *)*ctxp;
|
||||
@@ -388,30 +368,3 @@ isc_appctx_destroy(isc_appctx_t **ctxp) {
|
||||
|
||||
*ctxp = NULL;
|
||||
}
|
||||
|
||||
void
|
||||
isc_appctx_settaskmgr(isc_appctx_t *ctx0, isc_taskmgr_t *taskmgr) {
|
||||
isc__appctx_t *ctx = (isc__appctx_t *)ctx0;
|
||||
|
||||
REQUIRE(VALID_APPCTX(ctx));
|
||||
|
||||
ctx->taskmgr = taskmgr;
|
||||
}
|
||||
|
||||
void
|
||||
isc_appctx_setsocketmgr(isc_appctx_t *ctx0, isc_socketmgr_t *socketmgr) {
|
||||
isc__appctx_t *ctx = (isc__appctx_t *)ctx0;
|
||||
|
||||
REQUIRE(VALID_APPCTX(ctx));
|
||||
|
||||
ctx->socketmgr = socketmgr;
|
||||
}
|
||||
|
||||
void
|
||||
isc_appctx_settimermgr(isc_appctx_t *ctx0, isc_timermgr_t *timermgr) {
|
||||
isc__appctx_t *ctx = (isc__appctx_t *)ctx0;
|
||||
|
||||
REQUIRE(VALID_APPCTX(ctx));
|
||||
|
||||
ctx->timermgr = timermgr;
|
||||
}
|
||||
|
||||
@@ -24,9 +24,6 @@ isc_app_start
|
||||
isc_app_unblock
|
||||
isc_appctx_create
|
||||
isc_appctx_destroy
|
||||
isc_appctx_setsocketmgr
|
||||
isc_appctx_settaskmgr
|
||||
isc_appctx_settimermgr
|
||||
isc__buffer_activeregion
|
||||
isc__buffer_add
|
||||
isc__buffer_availableregion
|
||||
|
||||
@@ -3872,16 +3872,12 @@ isc_socketmgr_renderjson(isc_socketmgr_t *mgr, json_object *stats) {
|
||||
#endif /* HAVE_JSON */
|
||||
|
||||
isc_result_t
|
||||
isc_socketmgr_createinctx(isc_mem_t *mctx, isc_appctx_t *actx,
|
||||
isc_socketmgr_t **managerp)
|
||||
isc_socketmgr_createinctx(isc_mem_t *mctx, isc_socketmgr_t **managerp)
|
||||
{
|
||||
isc_result_t result;
|
||||
|
||||
result = isc_socketmgr_create(mctx, managerp);
|
||||
|
||||
if (result == ISC_R_SUCCESS)
|
||||
isc_appctx_setsocketmgr(actx, *managerp);
|
||||
|
||||
return (result);
|
||||
}
|
||||
|
||||
|
||||
@@ -223,15 +223,15 @@ ctxs_init(isc_mem_t **mctxp, isc_appctx_t **actxp,
|
||||
if (result != ISC_R_SUCCESS)
|
||||
goto fail;
|
||||
|
||||
result = isc_taskmgr_createinctx(*mctxp, *actxp, 1, 0, taskmgrp);
|
||||
result = isc_taskmgr_createinctx(*mctxp, 1, 0, taskmgrp);
|
||||
if (result != ISC_R_SUCCESS)
|
||||
goto fail;
|
||||
|
||||
result = isc_socketmgr_createinctx(*mctxp, *actxp, socketmgrp);
|
||||
result = isc_socketmgr_createinctx(*mctxp, socketmgrp);
|
||||
if (result != ISC_R_SUCCESS)
|
||||
goto fail;
|
||||
|
||||
result = isc_timermgr_createinctx(*mctxp, *actxp, timermgrp);
|
||||
result = isc_timermgr_createinctx(*mctxp, timermgrp);
|
||||
if (result != ISC_R_SUCCESS)
|
||||
goto fail;
|
||||
|
||||
|
||||
@@ -379,13 +379,13 @@ main(int argc, char *argv[]) {
|
||||
result = isc_app_ctxstart(actx);
|
||||
if (result != ISC_R_SUCCESS)
|
||||
goto cleanup;
|
||||
result = isc_taskmgr_createinctx(mctx, actx, 1, 0, &taskmgr);
|
||||
result = isc_taskmgr_createinctx(mctx, 1, 0, &taskmgr);
|
||||
if (result != ISC_R_SUCCESS)
|
||||
goto cleanup;
|
||||
result = isc_socketmgr_createinctx(mctx, actx, &socketmgr);
|
||||
result = isc_socketmgr_createinctx(mctx, &socketmgr);
|
||||
if (result != ISC_R_SUCCESS)
|
||||
goto cleanup;
|
||||
result = isc_timermgr_createinctx(mctx, actx, &timermgr);
|
||||
result = isc_timermgr_createinctx(mctx, &timermgr);
|
||||
if (result != ISC_R_SUCCESS)
|
||||
goto cleanup;
|
||||
|
||||
|
||||
@@ -105,15 +105,15 @@ ctxs_init(isc_mem_t **mctxp, isc_appctx_t **actxp,
|
||||
if (result != ISC_R_SUCCESS)
|
||||
goto fail;
|
||||
|
||||
result = isc_taskmgr_createinctx(*mctxp, *actxp, 1, 0, taskmgrp);
|
||||
result = isc_taskmgr_createinctx(*mctxp, 1, 0, taskmgrp);
|
||||
if (result != ISC_R_SUCCESS)
|
||||
goto fail;
|
||||
|
||||
result = isc_socketmgr_createinctx(*mctxp, *actxp, socketmgrp);
|
||||
result = isc_socketmgr_createinctx(*mctxp, socketmgrp);
|
||||
if (result != ISC_R_SUCCESS)
|
||||
goto fail;
|
||||
|
||||
result = isc_timermgr_createinctx(*mctxp, *actxp, timermgrp);
|
||||
result = isc_timermgr_createinctx(*mctxp, timermgrp);
|
||||
if (result != ISC_R_SUCCESS)
|
||||
goto fail;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user