summaryrefslogtreecommitdiff
path: root/external/mpl/bind/dist/lib/isc
diff options
context:
space:
mode:
Diffstat (limited to 'external/mpl/bind/dist/lib/isc')
-rw-r--r--external/mpl/bind/dist/lib/isc/include/isc/task.h27
-rw-r--r--external/mpl/bind/dist/lib/isc/include/isc/timer.h38
-rw-r--r--external/mpl/bind/dist/lib/isc/iterated_hash.c60
-rw-r--r--external/mpl/bind/dist/lib/isc/lib.c3
-rw-r--r--external/mpl/bind/dist/lib/isc/log.c21
-rw-r--r--external/mpl/bind/dist/lib/isc/mem.c9
-rw-r--r--external/mpl/bind/dist/lib/isc/netmgr/netmgr.c24
-rw-r--r--external/mpl/bind/dist/lib/isc/ratelimiter.c9
-rw-r--r--external/mpl/bind/dist/lib/isc/task.c38
-rw-r--r--external/mpl/bind/dist/lib/isc/tests/task_test.c22
-rw-r--r--external/mpl/bind/dist/lib/isc/tests/timer_test.c24
-rw-r--r--external/mpl/bind/dist/lib/isc/timer.c137
12 files changed, 210 insertions, 202 deletions
diff --git a/external/mpl/bind/dist/lib/isc/include/isc/task.h b/external/mpl/bind/dist/lib/isc/include/isc/task.h
index 5e7aa9c7c18..19ad13244c1 100644
--- a/external/mpl/bind/dist/lib/isc/include/isc/task.h
+++ b/external/mpl/bind/dist/lib/isc/include/isc/task.h
@@ -1,4 +1,4 @@
-/* $NetBSD: task.h,v 1.7 2022/09/23 12:15:33 christos Exp $ */
+/* $NetBSD: task.h,v 1.8 2023/06/26 22:03:01 christos Exp $ */
/*
* Copyright (C) Internet Systems Consortium, Inc. ("ISC")
@@ -375,27 +375,27 @@ isc_task_unsend(isc_task_t *task, void *sender, isc_eventtype_t type, void *tag,
*
* Notes:
*
- *\li This function is equivalent to
+ *\li This function is equivalent to
*
*\code
- * isc_task_unsendrange(task, sender, type, type, tag, events);
+ * isc_task_unsendrange(task, sender, type, type, tag, events);
*\endcode
*
* Requires:
*
- *\li 'task' is a valid task.
+ *\li 'task' is a valid task.
*
- *\li *events is a valid list.
+ *\li *events is a valid list.
*
* Ensures:
*
- *\li Events in the event queue of 'task' whose sender is 'sender', whose
- * type is 'type', and whose tag is 'tag' will be dequeued and appended
- * to *events.
+ *\li Events in the event queue of 'task' whose sender is 'sender', whose
+ * type is 'type', and whose tag is 'tag' will be dequeued and appended
+ * to *events.
*
* Returns:
*
- *\li The number of events unsent.
+ *\li The number of events unsent.
*/
isc_result_t
@@ -530,6 +530,15 @@ isc_task_gettag(isc_task_t *task);
*\li 'task' is a valid task.
*/
+void
+isc_task_setquantum(isc_task_t *task, unsigned int quantum);
+/*%<
+ * Set future 'task' quantum to 'quantum'. The current 'task' quantum will be
+ * kept for the current isc_task_run() loop, and will be changed for the next
+ * run. Therefore, the function is safe to use from the event callback as it
+ * will not affect the current event loop processing.
+ */
+
isc_result_t
isc_task_beginexclusive(isc_task_t *task);
/*%<
diff --git a/external/mpl/bind/dist/lib/isc/include/isc/timer.h b/external/mpl/bind/dist/lib/isc/include/isc/timer.h
index c6737df9e34..9428f1d9f1d 100644
--- a/external/mpl/bind/dist/lib/isc/include/isc/timer.h
+++ b/external/mpl/bind/dist/lib/isc/include/isc/timer.h
@@ -1,4 +1,4 @@
-/* $NetBSD: timer.h,v 1.7 2022/09/23 12:15:33 christos Exp $ */
+/* $NetBSD: timer.h,v 1.8 2023/06/26 22:03:01 christos Exp $ */
/*
* Copyright (C) Internet Systems Consortium, Inc. ("ISC")
@@ -90,10 +90,13 @@ typedef enum {
isc_timertype_inactive = 3 /*%< Inactive */
} isc_timertype_t;
-typedef struct isc_timerevent {
+typedef struct isc_timerevent isc_timerevent_t;
+
+struct isc_timerevent {
struct isc_event common;
isc_time_t due;
-} isc_timerevent_t;
+ ISC_LINK(isc_timerevent_t) ev_timerlink;
+};
#define ISC_TIMEREVENT_FIRSTEVENT (ISC_EVENTCLASS_TIMER + 0)
#define ISC_TIMEREVENT_TICK (ISC_EVENTCLASS_TIMER + 1)
@@ -225,25 +228,9 @@ isc_timer_touch(isc_timer_t *timer);
*/
void
-isc_timer_attach(isc_timer_t *timer, isc_timer_t **timerp);
-/*%<
- * Attach *timerp to timer.
- *
- * Requires:
- *
- *\li 'timer' is a valid timer.
- *
- *\li 'timerp' points to a NULL timer.
- *
- * Ensures:
- *
- *\li *timerp is attached to timer.
- */
-
-void
-isc_timer_detach(isc_timer_t **timerp);
+isc_timer_destroy(isc_timer_t **timerp);
/*%<
- * Detach *timerp from its timer.
+ * Destroy *timerp.
*
* Requires:
*
@@ -253,9 +240,6 @@ isc_timer_detach(isc_timer_t **timerp);
*
*\li *timerp is NULL.
*
- *\li If '*timerp' is the last reference to the timer,
- * then:
- *
*\code
* The timer will be shutdown
*
@@ -264,9 +248,13 @@ isc_timer_detach(isc_timer_t **timerp);
* All resources used by the timer have been freed
*
* Any events already posted by the timer will be purged.
- * Therefore, if isc_timer_detach() is called in the context
+ * Therefore, if isc_timer_destroy() is called in the context
* of the timer's task, it is guaranteed that no more
* timer event callbacks will run after the call.
+ *
+ * If this function is called from the timer event callback
+ * the event itself must be destroyed before the timer
+ * itself.
*\endcode
*/
diff --git a/external/mpl/bind/dist/lib/isc/iterated_hash.c b/external/mpl/bind/dist/lib/isc/iterated_hash.c
index f8f83910bfc..3a1c41e71d6 100644
--- a/external/mpl/bind/dist/lib/isc/iterated_hash.c
+++ b/external/mpl/bind/dist/lib/isc/iterated_hash.c
@@ -1,4 +1,4 @@
-/* $NetBSD: iterated_hash.c,v 1.6 2022/09/23 12:15:33 christos Exp $ */
+/* $NetBSD: iterated_hash.c,v 1.7 2023/06/26 22:03:01 christos Exp $ */
/*
* Copyright (C) Internet Systems Consortium, Inc. ("ISC")
@@ -15,8 +15,11 @@
#include <stdio.h>
+#include <openssl/opensslv.h>
+#include <openssl/sha.h>
+
#include <isc/iterated_hash.h>
-#include <isc/md.h>
+#include <isc/thread.h>
#include <isc/util.h>
int
@@ -24,55 +27,40 @@ isc_iterated_hash(unsigned char *out, const unsigned int hashalg,
const int iterations, const unsigned char *salt,
const int saltlength, const unsigned char *in,
const int inlength) {
- isc_md_t *md;
- isc_result_t result;
+ REQUIRE(out != NULL);
+
int n = 0;
- unsigned int outlength = 0;
size_t len;
const unsigned char *buf;
-
- REQUIRE(out != NULL);
+ SHA_CTX ctx;
if (hashalg != 1) {
return (0);
}
- if ((md = isc_md_new()) == NULL) {
- return (0);
- }
-
- len = inlength;
buf = in;
+ len = inlength;
+
do {
- result = isc_md_init(md, ISC_MD_SHA1);
- if (result != ISC_R_SUCCESS) {
- goto md_fail;
+ if (SHA1_Init(&ctx) != 1) {
+ return (0);
}
- result = isc_md_update(md, buf, len);
- if (result != ISC_R_SUCCESS) {
- goto md_fail;
- }
- result = isc_md_update(md, salt, saltlength);
- if (result != ISC_R_SUCCESS) {
- goto md_fail;
+
+ if (SHA1_Update(&ctx, buf, len) != 1) {
+ return (0);
}
- result = isc_md_final(md, out, &outlength);
- if (result != ISC_R_SUCCESS) {
- goto md_fail;
+
+ if (SHA1_Update(&ctx, salt, saltlength) != 1) {
+ return (0);
}
- result = isc_md_reset(md);
- if (result != ISC_R_SUCCESS) {
- goto md_fail;
+
+ if (SHA1_Final(out, &ctx) != 1) {
+ return (0);
}
+
buf = out;
- len = outlength;
+ len = SHA_DIGEST_LENGTH;
} while (n++ < iterations);
- isc_md_free(md);
-
- return (outlength);
-md_fail:
- isc_md_free(md);
- return (0);
+ return (SHA_DIGEST_LENGTH);
}
-#undef RETERR
diff --git a/external/mpl/bind/dist/lib/isc/lib.c b/external/mpl/bind/dist/lib/isc/lib.c
index c7ae78d807a..a292064ddb4 100644
--- a/external/mpl/bind/dist/lib/isc/lib.c
+++ b/external/mpl/bind/dist/lib/isc/lib.c
@@ -1,4 +1,4 @@
-/* $NetBSD: lib.c,v 1.9 2022/09/23 12:15:33 christos Exp $ */
+/* $NetBSD: lib.c,v 1.10 2023/06/26 22:03:01 christos Exp $ */
/*
* Copyright (C) Internet Systems Consortium, Inc. ("ISC")
@@ -16,6 +16,7 @@
/*! \file */
#include <isc/bind9.h>
+#include <isc/iterated_hash.h>
#include <isc/lib.h>
#include <isc/mem.h>
#include <isc/util.h>
diff --git a/external/mpl/bind/dist/lib/isc/log.c b/external/mpl/bind/dist/lib/isc/log.c
index a5e4a50e071..468cef1b1db 100644
--- a/external/mpl/bind/dist/lib/isc/log.c
+++ b/external/mpl/bind/dist/lib/isc/log.c
@@ -1,4 +1,4 @@
-/* $NetBSD: log.c,v 1.8 2023/01/25 21:43:31 christos Exp $ */
+/* $NetBSD: log.c,v 1.9 2023/06/26 22:03:01 christos Exp $ */
/*
* Copyright (C) Internet Systems Consortium, Inc. ("ISC")
@@ -1105,7 +1105,7 @@ greatest_version(isc_logfile_t *file, int versions, int *greatestp) {
}
static void
-insert_sort(int64_t to_keep[], int64_t versions, int version) {
+insert_sort(int64_t to_keep[], int64_t versions, int64_t version) {
int i = 0;
while (i < versions && version < to_keep[i]) {
i++;
@@ -1122,12 +1122,13 @@ insert_sort(int64_t to_keep[], int64_t versions, int version) {
static int64_t
last_to_keep(int64_t versions, isc_dir_t *dirp, char *bname, size_t bnamelen) {
+ int64_t to_keep[ISC_LOG_MAX_VERSIONS] = { 0 };
+ int64_t version = 0;
+
if (versions <= 0) {
- return INT64_MAX;
+ return (INT64_MAX);
}
- int64_t to_keep[ISC_LOG_MAX_VERSIONS] = { 0 };
- int64_t version = 0;
if (versions > ISC_LOG_MAX_VERSIONS) {
versions = ISC_LOG_MAX_VERSIONS;
}
@@ -1136,6 +1137,9 @@ last_to_keep(int64_t versions, isc_dir_t *dirp, char *bname, size_t bnamelen) {
*/
memset(to_keep, 0, sizeof(to_keep));
while (isc_dir_read(dirp) == ISC_R_SUCCESS) {
+ char *digit_end = NULL;
+ char *ename = NULL;
+
if (dirp->entry.length <= bnamelen ||
strncmp(dirp->entry.name, bname, bnamelen) != 0 ||
dirp->entry.name[bnamelen] != '.')
@@ -1143,8 +1147,7 @@ last_to_keep(int64_t versions, isc_dir_t *dirp, char *bname, size_t bnamelen) {
continue;
}
- char *digit_end;
- char *ename = &dirp->entry.name[bnamelen + 1];
+ ename = &dirp->entry.name[bnamelen + 1];
version = strtoull(ename, &digit_end, 10);
if (*digit_end == '\0') {
insert_sort(to_keep, versions, version);
@@ -1162,8 +1165,8 @@ last_to_keep(int64_t versions, isc_dir_t *dirp, char *bname, size_t bnamelen) {
static isc_result_t
remove_old_tsversions(isc_logfile_t *file, int versions) {
isc_result_t result;
- char *bname, *digit_end;
- const char *dirname;
+ char *bname = NULL, *digit_end = NULL;
+ const char *dirname = NULL;
int64_t version, last = INT64_MAX;
size_t bnamelen;
isc_dir_t dir;
diff --git a/external/mpl/bind/dist/lib/isc/mem.c b/external/mpl/bind/dist/lib/isc/mem.c
index bbbe329fb72..1813de183bb 100644
--- a/external/mpl/bind/dist/lib/isc/mem.c
+++ b/external/mpl/bind/dist/lib/isc/mem.c
@@ -1,4 +1,4 @@
-/* $NetBSD: mem.c,v 1.13 2023/01/25 21:43:31 christos Exp $ */
+/* $NetBSD: mem.c,v 1.14 2023/06/26 22:03:01 christos Exp $ */
/*
* Copyright (C) Internet Systems Consortium, Inc. ("ISC")
@@ -60,9 +60,10 @@ LIBISC_EXTERNAL_DATA unsigned int isc_mem_defaultflags = ISC_MEMFLAG_DEFAULT;
* Constants.
*/
-#define DEF_MAX_SIZE 1100
-#define DEF_MEM_TARGET 4096
-#define ALIGNMENT_SIZE 8U /*%< must be a power of 2 */
+#define DEF_MAX_SIZE 1100
+#define DEF_MEM_TARGET 4096
+#define ALIGNMENT_SIZE \
+ 8U /*%< must be a power of 2, also update lib/dns/rbt.c */
#define NUM_BASIC_BLOCKS 64 /*%< must be > 1 */
#define TABLE_INCREMENT 1024
#define DEBUG_TABLE_COUNT 512U
diff --git a/external/mpl/bind/dist/lib/isc/netmgr/netmgr.c b/external/mpl/bind/dist/lib/isc/netmgr/netmgr.c
index b2b8a9cc2da..a20236d6187 100644
--- a/external/mpl/bind/dist/lib/isc/netmgr/netmgr.c
+++ b/external/mpl/bind/dist/lib/isc/netmgr/netmgr.c
@@ -1,4 +1,4 @@
-/* $NetBSD: netmgr.c,v 1.9 2023/01/25 21:43:31 christos Exp $ */
+/* $NetBSD: netmgr.c,v 1.10 2023/06/26 22:03:01 christos Exp $ */
/*
* Copyright (C) Internet Systems Consortium, Inc. ("ISC")
@@ -243,15 +243,15 @@ isc__nm_threadpool_initialize(uint32_t workers) {
}
}
-#if HAVE_DECL_UV_UDP_LINUX_RECVERR
-#define MINIMAL_UV_VERSION UV_VERSION(1, 42, 0)
-#elif HAVE_DECL_UV_UDP_MMSG_FREE
+#if HAVE_DECL_UV_UDP_MMSG_FREE
#define MINIMAL_UV_VERSION UV_VERSION(1, 40, 0)
#elif HAVE_DECL_UV_UDP_RECVMMSG
+#define MAXIMAL_UV_VERSION UV_VERSION(1, 39, 99)
#define MINIMAL_UV_VERSION UV_VERSION(1, 37, 0)
-#elif HAVE_DECL_UV_UDP_MMSG_CHUNK
-#define MINIMAL_UV_VERSION UV_VERSION(1, 35, 0)
+#elif _WIN32
+#define MINIMAL_UV_VERSION UV_VERSION(1, 0, 0)
#else
+#define MAXIMAL_UV_VERSION UV_VERSION(1, 34, 99)
#define MINIMAL_UV_VERSION UV_VERSION(1, 0, 0)
#endif
@@ -262,11 +262,21 @@ isc__netmgr_create(isc_mem_t *mctx, uint32_t workers, isc_nm_t **netmgrp) {
REQUIRE(workers > 0);
+#ifdef MAXIMAL_UV_VERSION
+ if (uv_version() > MAXIMAL_UV_VERSION) {
+ isc_error_fatal(__FILE__, __LINE__,
+ "libuv version too new: running with libuv %s "
+ "when compiled with libuv %s will lead to "
+ "libuv failures",
+ uv_version_string(), UV_VERSION_STRING);
+ }
+#endif /* MAXIMAL_UV_VERSION */
+
if (uv_version() < MINIMAL_UV_VERSION) {
isc_error_fatal(__FILE__, __LINE__,
"libuv version too old: running with libuv %s "
"when compiled with libuv %s will lead to "
- "libuv failures because of unknown flags",
+ "libuv failures",
uv_version_string(), UV_VERSION_STRING);
}
diff --git a/external/mpl/bind/dist/lib/isc/ratelimiter.c b/external/mpl/bind/dist/lib/isc/ratelimiter.c
index cfd920e51b2..73c29ef834d 100644
--- a/external/mpl/bind/dist/lib/isc/ratelimiter.c
+++ b/external/mpl/bind/dist/lib/isc/ratelimiter.c
@@ -1,4 +1,4 @@
-/* $NetBSD: ratelimiter.c,v 1.7 2022/09/23 12:15:33 christos Exp $ */
+/* $NetBSD: ratelimiter.c,v 1.8 2023/06/26 22:03:01 christos Exp $ */
/*
* Copyright (C) Internet Systems Consortium, Inc. ("ISC")
@@ -244,6 +244,7 @@ void
isc_ratelimiter_shutdown(isc_ratelimiter_t *rl) {
isc_event_t *ev;
isc_task_t *task;
+ isc_result_t result;
REQUIRE(rl != NULL);
@@ -259,7 +260,11 @@ isc_ratelimiter_shutdown(isc_ratelimiter_t *rl) {
}
task = NULL;
isc_task_attach(rl->task, &task);
- isc_timer_detach(&rl->timer);
+
+ result = isc_timer_reset(rl->timer, isc_timertype_inactive, NULL, NULL,
+ false);
+ RUNTIME_CHECK(result == ISC_R_SUCCESS);
+ isc_timer_destroy(&rl->timer);
/*
* Send an event to our task. The delivery of this event
diff --git a/external/mpl/bind/dist/lib/isc/task.c b/external/mpl/bind/dist/lib/isc/task.c
index 339170e3707..c591d3c517a 100644
--- a/external/mpl/bind/dist/lib/isc/task.c
+++ b/external/mpl/bind/dist/lib/isc/task.c
@@ -1,4 +1,4 @@
-/* $NetBSD: task.c,v 1.17 2023/01/25 21:43:31 christos Exp $ */
+/* $NetBSD: task.c,v 1.18 2023/06/26 22:03:01 christos Exp $ */
/*
* Copyright (C) Internet Systems Consortium, Inc. ("ISC")
@@ -622,12 +622,10 @@ isc_task_purge(isc_task_t *task, void *sender, isc_eventtype_t type,
bool
isc_task_purgeevent(isc_task_t *task, isc_event_t *event) {
- isc_event_t *curr_event, *next_event;
+ bool found = false;
/*
* Purge 'event' from a task's event queue.
- *
- * XXXRTH: WARNING: This method may be removed before beta.
*/
REQUIRE(VALID_TASK(task));
@@ -643,23 +641,18 @@ isc_task_purgeevent(isc_task_t *task, isc_event_t *event) {
*/
LOCK(&task->lock);
- for (curr_event = HEAD(task->events); curr_event != NULL;
- curr_event = next_event)
- {
- next_event = NEXT(curr_event, ev_link);
- if (curr_event == event && PURGE_OK(event)) {
- DEQUEUE(task->events, curr_event, ev_link);
- task->nevents--;
- break;
- }
+ if (ISC_LINK_LINKED(event, ev_link)) {
+ DEQUEUE(task->events, event, ev_link);
+ task->nevents--;
+ found = true;
}
UNLOCK(&task->lock);
- if (curr_event == NULL) {
+ if (!found) {
return (false);
}
- isc_event_free(&curr_event);
+ isc_event_free(&event);
return (true);
}
@@ -809,6 +802,16 @@ isc_task_getnetmgr(isc_task_t *task) {
return (task->manager->netmgr);
}
+void
+isc_task_setquantum(isc_task_t *task, unsigned int quantum) {
+ REQUIRE(VALID_TASK(task));
+
+ LOCK(&task->lock);
+ task->quantum = (quantum > 0) ? quantum
+ : task->manager->default_quantum;
+ UNLOCK(&task->lock);
+}
+
/***
*** Task Manager.
***/
@@ -819,10 +822,13 @@ task_run(isc_task_t *task) {
bool finished = false;
isc_event_t *event = NULL;
isc_result_t result = ISC_R_SUCCESS;
+ uint32_t quantum;
REQUIRE(VALID_TASK(task));
LOCK(&task->lock);
+ quantum = task->quantum;
+
/*
* It is possible because that we have a paused task in the queue - it
* might have been paused in the meantime and we never hold both queue
@@ -914,7 +920,7 @@ task_run(isc_task_t *task) {
XTRACE("pausing");
task->state = task_state_paused;
break;
- } else if (dispatch_count >= task->quantum) {
+ } else if (dispatch_count >= quantum) {
/*
* Our quantum has expired, but there is more work to be
* done. We'll requeue it to the ready queue later.
diff --git a/external/mpl/bind/dist/lib/isc/tests/task_test.c b/external/mpl/bind/dist/lib/isc/tests/task_test.c
index 180e979f192..65fb6779d80 100644
--- a/external/mpl/bind/dist/lib/isc/tests/task_test.c
+++ b/external/mpl/bind/dist/lib/isc/tests/task_test.c
@@ -1,4 +1,4 @@
-/* $NetBSD: task_test.c,v 1.11 2023/01/25 21:43:31 christos Exp $ */
+/* $NetBSD: task_test.c,v 1.12 2023/06/26 22:03:01 christos Exp $ */
/*
* Copyright (C) Internet Systems Consortium, Inc. ("ISC")
@@ -633,8 +633,8 @@ basic(void **state) {
#else /* ifndef WIN32 */
Sleep(10000);
#endif /* ifndef WIN32 */
- isc_timer_detach(&ti1);
- isc_timer_detach(&ti2);
+ isc_timer_destroy(&ti1);
+ isc_timer_destroy(&ti2);
}
/*
@@ -1521,20 +1521,6 @@ purgeevent(void **state) {
try_purgeevent(true);
}
-/*
- * Purge event not purgeable test:
- * When the event is not marked as purgable, a call to
- * isc_task_purgeevent(task, event) does not purge the event
- * 'event' from the task's queue and returns false.
- */
-
-static void
-purgeevent_notpurge(void **state) {
- UNUSED(state);
-
- try_purgeevent(false);
-}
-
int
main(int argc, char **argv) {
const struct CMUnitTest tests[] = {
@@ -1552,8 +1538,6 @@ main(int argc, char **argv) {
_teardown),
cmocka_unit_test_setup_teardown(purge, _setup2, _teardown),
cmocka_unit_test_setup_teardown(purgeevent, _setup2, _teardown),
- cmocka_unit_test_setup_teardown(purgeevent_notpurge, _setup,
- _teardown),
cmocka_unit_test_setup_teardown(purgerange, _setup, _teardown),
cmocka_unit_test_setup_teardown(task_shutdown, _setup4,
_teardown),
diff --git a/external/mpl/bind/dist/lib/isc/tests/timer_test.c b/external/mpl/bind/dist/lib/isc/tests/timer_test.c
index be11e5c001d..b3e5a89b51a 100644
--- a/external/mpl/bind/dist/lib/isc/tests/timer_test.c
+++ b/external/mpl/bind/dist/lib/isc/tests/timer_test.c
@@ -1,4 +1,4 @@
-/* $NetBSD: timer_test.c,v 1.9 2022/09/23 12:15:34 christos Exp $ */
+/* $NetBSD: timer_test.c,v 1.10 2023/06/26 22:03:01 christos Exp $ */
/*
* Copyright (C) Internet Systems Consortium, Inc. ("ISC")
@@ -246,14 +246,14 @@ ticktock(isc_task_t *task, isc_event_t *event) {
isc_mutex_unlock(&lasttime_mx);
subthread_assert_result_equal(result, ISC_R_SUCCESS);
+ isc_event_free(&event);
+
if (atomic_load(&eventcnt) == nevents) {
result = isc_time_now(&endtime);
subthread_assert_result_equal(result, ISC_R_SUCCESS);
- isc_timer_detach(&timer);
+ isc_timer_destroy(&timer);
isc_task_shutdown(task);
}
-
- isc_event_free(&event);
}
/*
@@ -341,9 +341,10 @@ test_idle(isc_task_t *task, isc_event_t *event) {
subthread_assert_int_equal(event->ev_type, ISC_TIMEREVENT_IDLE);
- isc_timer_detach(&timer);
- isc_task_shutdown(task);
isc_event_free(&event);
+
+ isc_timer_destroy(&timer);
+ isc_task_shutdown(task);
}
/* timer type once idles out */
@@ -428,14 +429,15 @@ test_reset(isc_task_t *task, isc_event_t *event) {
&expires, &interval, false);
subthread_assert_result_equal(result, ISC_R_SUCCESS);
}
+
+ isc_event_free(&event);
} else {
subthread_assert_int_equal(event->ev_type, ISC_TIMEREVENT_LIFE);
- isc_timer_detach(&timer);
+ isc_event_free(&event);
+ isc_timer_destroy(&timer);
isc_task_shutdown(task);
}
-
- isc_event_free(&event);
}
static void
@@ -593,8 +595,8 @@ purge(void **state) {
assert_int_equal(atomic_load(&eventcnt), 1);
- isc_timer_detach(&tickertimer);
- isc_timer_detach(&oncetimer);
+ isc_timer_destroy(&tickertimer);
+ isc_timer_destroy(&oncetimer);
isc_task_destroy(&task1);
isc_task_destroy(&task2);
}
diff --git a/external/mpl/bind/dist/lib/isc/timer.c b/external/mpl/bind/dist/lib/isc/timer.c
index e55aca6245b..198e8813bf9 100644
--- a/external/mpl/bind/dist/lib/isc/timer.c
+++ b/external/mpl/bind/dist/lib/isc/timer.c
@@ -1,4 +1,4 @@
-/* $NetBSD: timer.c,v 1.11 2023/01/25 21:43:31 christos Exp $ */
+/* $NetBSD: timer.c,v 1.12 2023/06/26 22:03:01 christos Exp $ */
/*
* Copyright (C) Internet Systems Consortium, Inc. ("ISC")
@@ -64,9 +64,9 @@ struct isc_timer {
unsigned int magic;
isc_timermgr_t *manager;
isc_mutex_t lock;
- isc_refcount_t references;
/*! Locked by timer lock. */
isc_time_t idle;
+ ISC_LIST(isc_timerevent_t) active;
/*! Locked by manager lock. */
isc_timertype_t type;
isc_time_t expires;
@@ -210,26 +210,36 @@ deschedule(isc_timer_t *timer) {
}
static void
-destroy(isc_timer_t *timer) {
- isc_timermgr_t *manager = timer->manager;
-
- /*
- * The caller must ensure it is safe to destroy the timer.
- */
+timerevent_unlink(isc_timer_t *timer, isc_timerevent_t *event) {
+ REQUIRE(ISC_LINK_LINKED(event, ev_timerlink));
+ ISC_LIST_UNLINK(timer->active, event, ev_timerlink);
+}
- LOCK(&manager->lock);
+static void
+timerevent_destroy(isc_event_t *event0) {
+ isc_timer_t *timer = event0->ev_destroy_arg;
+ isc_timerevent_t *event = (isc_timerevent_t *)event0;
- (void)isc_task_purgerange(timer->task, timer, ISC_TIMEREVENT_FIRSTEVENT,
- ISC_TIMEREVENT_LASTEVENT, NULL);
- deschedule(timer);
- UNLINK(manager->timers, timer, link);
+ LOCK(&timer->lock);
+ if (ISC_LINK_LINKED(event, ev_timerlink)) {
+ /* The event was unlinked via timer_purge() */
+ timerevent_unlink(timer, event);
+ }
+ UNLOCK(&timer->lock);
- UNLOCK(&manager->lock);
+ isc_mem_put(timer->manager->mctx, event, event0->ev_size);
+}
- isc_task_detach(&timer->task);
- isc_mutex_destroy(&timer->lock);
- timer->magic = 0;
- isc_mem_put(manager->mctx, timer, sizeof(*timer));
+static void
+timer_purge(isc_timer_t *timer) {
+ isc_timerevent_t *event = NULL;
+
+ while ((event = ISC_LIST_HEAD(timer->active)) != NULL) {
+ timerevent_unlink(timer, event);
+ UNLOCK(&timer->lock);
+ (void)isc_task_purgeevent(timer->task, (isc_event_t *)event);
+ LOCK(&timer->lock);
+ }
}
isc_result_t
@@ -281,7 +291,6 @@ isc_timer_create(isc_timermgr_t *manager, isc_timertype_t type,
timer = isc_mem_get(manager->mctx, sizeof(*timer));
timer->manager = manager;
- isc_refcount_init(&timer->references, 1);
if (type == isc_timertype_once && !isc_interval_iszero(interval)) {
result = isc_time_add(&now, interval, &timer->idle);
@@ -313,6 +322,9 @@ isc_timer_create(isc_timermgr_t *manager, isc_timertype_t type,
timer->index = 0;
isc_mutex_init(&timer->lock);
ISC_LINK_INIT(timer, link);
+
+ ISC_LIST_INIT(timer->active);
+
timer->magic = TIMER_MAGIC;
LOCK(&manager->lock);
@@ -392,9 +404,7 @@ isc_timer_reset(isc_timer_t *timer, isc_timertype_t type,
LOCK(&timer->lock);
if (purge) {
- (void)isc_task_purgerange(timer->task, timer,
- ISC_TIMEREVENT_FIRSTEVENT,
- ISC_TIMEREVENT_LASTEVENT, NULL);
+ timer_purge(timer);
}
timer->type = type;
timer->expires = *expires;
@@ -465,41 +475,60 @@ isc_timer_touch(isc_timer_t *timer) {
}
void
-isc_timer_attach(isc_timer_t *timer, isc_timer_t **timerp) {
- /*
- * Attach *timerp to timer.
- */
+isc_timer_destroy(isc_timer_t **timerp) {
+ isc_timer_t *timer = NULL;
+ isc_timermgr_t *manager = NULL;
- REQUIRE(VALID_TIMER(timer));
- REQUIRE(timerp != NULL && *timerp == NULL);
- isc_refcount_increment(&timer->references);
+ REQUIRE(timerp != NULL && VALID_TIMER(*timerp));
+
+ timer = *timerp;
+ *timerp = NULL;
- *timerp = timer;
+ manager = timer->manager;
+
+ LOCK(&manager->lock);
+
+ LOCK(&timer->lock);
+ timer_purge(timer);
+ deschedule(timer);
+ UNLOCK(&timer->lock);
+
+ UNLINK(manager->timers, timer, link);
+
+ UNLOCK(&manager->lock);
+
+ isc_task_detach(&timer->task);
+ isc_mutex_destroy(&timer->lock);
+ timer->magic = 0;
+ isc_mem_put(manager->mctx, timer, sizeof(*timer));
}
-void
-isc_timer_detach(isc_timer_t **timerp) {
- isc_timer_t *timer;
+static void
+timer_post_event(isc_timermgr_t *manager, isc_timer_t *timer,
+ isc_eventtype_t type) {
+ isc_timerevent_t *event;
+ XTRACEID("posting", timer);
- /*
- * Detach *timerp from its timer.
- */
+ event = (isc_timerevent_t *)isc_event_allocate(
+ manager->mctx, timer, type, timer->action, timer->arg,
+ sizeof(*event));
- REQUIRE(timerp != NULL);
- timer = *timerp;
- REQUIRE(VALID_TIMER(timer));
+ ISC_LINK_INIT(event, ev_timerlink);
+ ((isc_event_t *)event)->ev_destroy = timerevent_destroy;
+ ((isc_event_t *)event)->ev_destroy_arg = timer;
- if (isc_refcount_decrement(&timer->references) == 1) {
- destroy(timer);
- }
+ event->due = timer->due;
- *timerp = NULL;
+ LOCK(&timer->lock);
+ ISC_LIST_APPEND(timer->active, event, ev_timerlink);
+ UNLOCK(&timer->lock);
+
+ isc_task_send(timer->task, ISC_EVENT_PTR(&event));
}
static void
dispatch(isc_timermgr_t *manager, isc_time_t *now) {
bool done = false, post_event, need_schedule;
- isc_timerevent_t *event;
isc_eventtype_t type = 0;
isc_timer_t *timer;
isc_result_t result;
@@ -561,25 +590,7 @@ dispatch(isc_timermgr_t *manager, isc_time_t *now) {
}
if (post_event) {
- XTRACEID("posting", timer);
- /*
- * XXX We could preallocate this event.
- */
- event = (isc_timerevent_t *)isc_event_allocate(
- manager->mctx, timer, type,
- timer->action, timer->arg,
- sizeof(*event));
-
- if (event != NULL) {
- event->due = timer->due;
- isc_task_send(timer->task,
- ISC_EVENT_PTR(&event));
- } else {
- UNEXPECTED_ERROR(__FILE__, __LINE__,
- "%s",
- "couldn't allocate "
- "event");
- }
+ timer_post_event(manager, timer, type);
}
timer->index = 0;