]> 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@sury.org>
Sat, 14 Mar 2026 05:32:50 +0000 (06:32 +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.

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 51ebbe99ae125dc089793237eaacd3cec9866b36..60eb7f6c25cfe2617e5621a064f53bc7de99ee0f 100644 (file)
@@ -54,11 +54,7 @@ after_work_cb(void *arg ISC_ATTR_UNUSED) {
 
 static void
 work_enqueue_cb(void *arg ISC_ATTR_UNUSED) {
-       isc_tid_t tid = isc_loopmgr_nloops() - 1;
-
-       isc_loop_t *loop = isc_loop_get(tid);
-
-       isc_work_enqueue(loop, work_cb, after_work_cb, NULL);
+       isc_work_enqueue(isc_loop(), work_cb, after_work_cb, NULL);
 }
 
 ISC_RUN_TEST_IMPL(isc_work_enqueue) {