]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Enforce isc_work enqueue loop affinity
authorOndřej Surý <ondrej@isc.org>
Tue, 10 Mar 2026 17:25:37 +0000 (18:25 +0100)
committerOndřej Surý <ondrej@isc.org>
Sat, 14 Mar 2026 06:52:56 +0000 (07:52 +0100)
Add a REQUIRE(isc_loop() == loop) assertion to isc_work_enqueue()
to strictly enforce that work is enqueued from the loop it is
assigned to. This loudly prohibits cross-thread queue manipulation
before it inevitably turns into a concurrency debugging nightmare.

(cherry picked from commit f1311d2d196d381b2170c4b3d54262874a5d424e)

lib/isc/work.c
tests/isc/work_test.c

index 4391b2d2fa12a08596d9c718089e2aa4f4f82944..0b7cdf5743dfc950ea80d20a9e990fa38f4c96e7 100644 (file)
@@ -58,6 +58,7 @@ isc_work_enqueue(isc_loop_t *loop, isc_work_cb work_cb,
        int r;
 
        REQUIRE(VALID_LOOP(loop));
+       REQUIRE(isc_loop() == loop);
        REQUIRE(work_cb != NULL);
        REQUIRE(after_work_cb != NULL);
 
index 3c126ee613e7dc437694d6a3befda2e420a3ffa5..5e0184cd522f649f2fd798a604ce999ef1a055d6 100644 (file)
@@ -56,13 +56,8 @@ after_work_cb(void *arg) {
 }
 
 static void
-work_enqueue_cb(void *arg) {
-       UNUSED(arg);
-       uint32_t tid = isc_loopmgr_nloops(loopmgr) - 1;
-
-       isc_loop_t *loop = isc_loop_get(loopmgr, tid);
-
-       isc_work_enqueue(loop, work_cb, after_work_cb, loopmgr);
+work_enqueue_cb(void *arg ISC_ATTR_UNUSED) {
+       isc_work_enqueue(isc_loop(), work_cb, after_work_cb, NULL);
 }
 
 ISC_RUN_TEST_IMPL(isc_work_enqueue) {