[PR #1042] frame_pacer: wake blocked waiters on set_uncapped and guard shutdown entry #1079

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

📋 Pull Request Information

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

Base: main ← Head: fix/frame-pacer-shutdown-wakeup


📝 Commits (4)

  • 7d6c7f3 frame_pacer: notify waiters on set_uncapped and hold lock across shutdown notify
  • e26f6c1 frame_pacer_test: verify late waiter during ~FramePacer shutdown returns invalid_state with zero clock reads
  • 4917377 frame_pacer_test: release HoldingClock before asserting late-waiter results
  • 29736be frame_pacer: release waiter registration via RAII on clock exception

📊 Changes

2 files changed (+152 additions, -9 deletions)

View changed files

📝 runtime/src/frame_pacer.h (+19 -9)
📝 runtime/test/frame_pacer_test.cpp (+133 -0)

📄 Description

What and why

Addresses the runtime/src/frame_pacer.h wakeup/shutdown races reported in #14 by @akimfomin:

  • Mode switch wakeup (set_uncapped): set_uncapped(bool) updated uncapped_ under mutex_ without notifying cv_, so a waiter already blocked on the vblank grid missed the mode switch. It now calls cv_.notify_all() after releasing mutex_.
  • Shutdown race (~FramePacer / wait_frame_event): ~FramePacer() now holds mutex_ across setting shutdown_ = true, calling cv_.notify_all(), and entering cv_.wait(lock, ...) (eliminating the unlocked window between shutdown_ = true and cv_.wait), and wait_frame_event returns pacer_hr::invalid_state immediately if shutdown_ is already set before incrementing waiters_.

Testing

  • Added regression tests in runtime/test/frame_pacer_test.cpp covering:
    • Destroying FramePacer with multiple blocked waiters (origin, vblank, flip).
    • Calling set_uncapped(true) while a waiter is blocked on ManualFrameClock.
  • ctest -R frame_pacer --output-on-failure (Wine 11.22, clang-cl + xwin): 1/1 passed (6.69 s).

AI-assisted: yes


🔄 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/1042 **Author:** [@madhyn](https://github.com/madhyn) **Created:** 11/24/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/frame-pacer-shutdown-wakeup` --- ### 📝 Commits (4) - [`7d6c7f3`](https://github.com/ubiquitarianism/leonida/commit/7d6c7f30e12a160e99d9bbb1773dfde3bd15182a) frame_pacer: notify waiters on set_uncapped and hold lock across shutdown notify - [`e26f6c1`](https://github.com/ubiquitarianism/leonida/commit/e26f6c1a68c81aa55a45e00297a864c8da156fc1) frame_pacer_test: verify late waiter during ~FramePacer shutdown returns invalid_state with zero clock reads - [`4917377`](https://github.com/ubiquitarianism/leonida/commit/4917377821aaec14ccaf95634583895d49347ce6) frame_pacer_test: release HoldingClock before asserting late-waiter results - [`29736be`](https://github.com/ubiquitarianism/leonida/commit/29736be5589c2c3d0d2d1cdeaf2c8364ce6d4d41) frame_pacer: release waiter registration via RAII on clock exception ### 📊 Changes **2 files changed** (+152 additions, -9 deletions) <details> <summary>View changed files</summary> 📝 `runtime/src/frame_pacer.h` (+19 -9) 📝 `runtime/test/frame_pacer_test.cpp` (+133 -0) </details> ### 📄 Description ### What and why Addresses the `runtime/src/frame_pacer.h` wakeup/shutdown races reported in #14 by @akimfomin: - **Mode switch wakeup (`set_uncapped`):** `set_uncapped(bool)` updated `uncapped_` under `mutex_` without notifying `cv_`, so a waiter already blocked on the vblank grid missed the mode switch. It now calls `cv_.notify_all()` after releasing `mutex_`. - **Shutdown race (`~FramePacer` / `wait_frame_event`):** `~FramePacer()` now holds `mutex_` across setting `shutdown_ = true`, calling `cv_.notify_all()`, and entering `cv_.wait(lock, ...)` (eliminating the unlocked window between `shutdown_ = true` and `cv_.wait`), and `wait_frame_event` returns `pacer_hr::invalid_state` immediately if `shutdown_` is already set before incrementing `waiters_`. ### Testing - Added regression tests in `runtime/test/frame_pacer_test.cpp` covering: - Destroying `FramePacer` with multiple blocked waiters (`origin`, `vblank`, `flip`). - Calling `set_uncapped(true)` while a waiter is blocked on `ManualFrameClock`. - `ctest -R frame_pacer --output-on-failure` (Wine 11.22, `clang-cl` + `xwin`): **1/1 passed** (6.69 s). AI-assisted: yes --- <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#1079
No description provided.