[PR #680] queue_holds: scope in_pump per instance with RAII and allow re-entrant detach/cancel_after (RT-QUEUE-HOLDS-REENTRY) #720

Open
opened 2026-11-26 20:18:50 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/680
Author: @hamdog0203
Created: 11/24/2026
Status: 🔄 Open

Base: main ← Head: fix/rt-queue-holds-reentry


📝 Commits (1)

  • d705fc9 queue_holds: scope in_pump per instance with RAII and allow re-entrant detach/cancel_after (RT-QUEUE-HOLDS-REENTRY)

📊 Changes

3 files changed (+371 additions, -28 deletions)

View changed files

📝 runtime/CMakeLists.txt (+3 -0)
📝 runtime/src/queue_holds.h (+86 -28)
➕ runtime/test/queue_holds_test.cpp (+282 -0)

📄 Description

Claimed in the coordination issue as: RT-QUEUE-HOLDS-REENTRY (https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7130376907)

AI-assisted: yes
No game files touched or included.

Summary

Fixes three re-entrancy and lifetime bugs in runtime/src/queue_holds.h and adds standalone unit tests in runtime/test/queue_holds_test.cpp:

  1. Per-instance & exception-safe in_pump() tracking: replaces the single global thread_local bool with a per-QueueHolds* thread-local stack managed by an RAII PumpGuard. Sibling QueueHolds instances running on the same thread no longer suppress each other's pump_ready() / remove_fence() calls, and exceptions thrown from callbacks no longer leave in_pump() stuck true.
  2. Re-entrant detach() and cancel_after(): when called from within an active pump_ready() / remove_fence() pass on the same thread, detach() and cancel_after() update holders_ / barriers_ under mutex_ and set dirty_ without attempting to re-acquire pump_mutex_ (preventing a self-deadlock), while external threads continue waiting on pump_mutex_.
  3. Snapshot iteration guard: loops over snapshot() in pump_ready(), run_barriers(), and remove_fence() re-check is_attached(holder) before invoking callbacks on a holder so a sibling holder detached mid-pass is never called after teardown.

Verification

  • Built full Windows runtime with MSVC 14.44.35207 + Windows SDK 10.0.26100.0 (scripts\build_runtime.ps1): 239/239 affected targets built cleanly with zero new warnings.
  • ctest --test-dir runtime\build --output-on-failure -V -R "^(queue_holds|d3d12_fence_timing|vk_presenter_sync|vk_queue_query_sync|vk_overlapping_occlusion|vk_queue_constructor_oom)$" on Windows 11 + NVIDIA GeForce RTX 4060 (driver 621.35): 6/6 passed (100%), including queue_holds tests passed (5/5).
  • Negative control against unpatched main (runtime/src/queue_holds.h): queue_holds failed immediately (sibling_instance failed, exit code 8).
  • python -I scripts/check_no_game_data.py runtime/src/queue_holds.h runtime/test/queue_holds_test.cpp runtime/CMakeLists.txt -> exit 0; git diff --check clean.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ubiquitarianism/leonida/pull/680 **Author:** [@hamdog0203](https://github.com/hamdog0203) **Created:** 11/24/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/rt-queue-holds-reentry` --- ### 📝 Commits (1) - [`d705fc9`](https://github.com/ubiquitarianism/leonida/commit/d705fc9f245537d7f6a9b31dbe896c569eca182b) queue_holds: scope in_pump per instance with RAII and allow re-entrant detach/cancel_after (RT-QUEUE-HOLDS-REENTRY) ### 📊 Changes **3 files changed** (+371 additions, -28 deletions) <details> <summary>View changed files</summary> 📝 `runtime/CMakeLists.txt` (+3 -0) 📝 `runtime/src/queue_holds.h` (+86 -28) ➕ `runtime/test/queue_holds_test.cpp` (+282 -0) </details> ### 📄 Description Claimed in the coordination issue as: RT-QUEUE-HOLDS-REENTRY (https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7130376907) AI-assisted: yes No game files touched or included. ### Summary Fixes three re-entrancy and lifetime bugs in `runtime/src/queue_holds.h` and adds standalone unit tests in `runtime/test/queue_holds_test.cpp`: 1. **Per-instance & exception-safe `in_pump()` tracking:** replaces the single global `thread_local bool` with a per-`QueueHolds*` thread-local stack managed by an RAII `PumpGuard`. Sibling `QueueHolds` instances running on the same thread no longer suppress each other's `pump_ready()` / `remove_fence()` calls, and exceptions thrown from callbacks no longer leave `in_pump()` stuck `true`. 2. **Re-entrant `detach()` and `cancel_after()`:** when called from within an active `pump_ready()` / `remove_fence()` pass on the same thread, `detach()` and `cancel_after()` update `holders_` / `barriers_` under `mutex_` and set `dirty_` without attempting to re-acquire `pump_mutex_` (preventing a self-deadlock), while external threads continue waiting on `pump_mutex_`. 3. **Snapshot iteration guard:** loops over `snapshot()` in `pump_ready()`, `run_barriers()`, and `remove_fence()` re-check `is_attached(holder)` before invoking callbacks on a holder so a sibling holder detached mid-pass is never called after teardown. ### Verification - Built full Windows runtime with MSVC `14.44.35207` + Windows SDK `10.0.26100.0` (`scripts\build_runtime.ps1`): `239/239` affected targets built cleanly with zero new warnings. - `ctest --test-dir runtime\build --output-on-failure -V -R "^(queue_holds|d3d12_fence_timing|vk_presenter_sync|vk_queue_query_sync|vk_overlapping_occlusion|vk_queue_constructor_oom)$"` on Windows 11 + NVIDIA GeForce RTX 4060 (driver `621.35`): **6/6 passed (`100%`)**, including `queue_holds tests passed (5/5)`. - Negative control against unpatched `main` (`runtime/src/queue_holds.h`): `queue_holds` failed immediately (`sibling_instance failed`, exit code `8`). - `python -I scripts/check_no_game_data.py runtime/src/queue_holds.h runtime/test/queue_holds_test.cpp runtime/CMakeLists.txt` -> exit `0`; `git diff --check` clean. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No labels
bug
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
starred/leonida#720
No description provided.