Enforce isc_work enqueue loop affinity

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 f1311d2d19)
This commit is contained in:
Ondřej Surý 2026-03-10 18:25:37 +01:00
parent fdd3b36ba3
commit d4b96af062
No known key found for this signature in database
GPG key ID: 2820F37E873DEA41
2 changed files with 3 additions and 7 deletions

View 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);

View 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) {