fix: save pipeline cache on emulator crash #1312

Open
github-bot wants to merge 5 commits from github-bot/gh-1312 into main AGit
Owner

@⁠gavvahar on GitHub · 2026-10-09 15:37 UTC · original
gavvahar:main → main · +63 −5 · 4 files · 5 commits · open

Problem

Emulator crashes during gameplay (especially heavy loads like cinematics in Astro's Playroom) cause complete loss of the Vulkan pipeline cache. On next launch all shaders must recompile, perpetuating the stutter.

Root cause: PipelineCache::Save() was only called on graceful shutdown (destructor + the explicit WindowRun path). Crashes go through DbgExit() -> std::_Exit(), which skips all C++ destructors, so the cache never reaches disk.

Solution

Add an EmergencyShutdown() callback to the Graphics subsystem Lifecycle, mirroring the existing pattern used by Libs::Controller and Libs::LibKernel::FileSystem. It dumps the in-memory Vulkan pipeline cache to disk during emergency teardown, using TryLock() so a crash on a thread already holding the render mutex skips the save rather than hanging the crash handler.

Graphics is registered last in emulator.cpp, so its emergency callback runs first in the reverse-order teardown, while the FileSystem subsystem is still alive to service the write.

Changes

  • src/libs/agc.cpp: add EmergencyShutdown()
  • src/libs/agc.h: declare it and wire it into Lifecycle::emergency_shutdown

Verification

Full build of the launcher target passes: 1084 objects, 0 errors, 191 warnings (all pre-existing, e.g. deprecated wstring_convert in stringUtils.h).

Scope

This makes the existing cache survive crashes. Predictive/async shader pre-compilation (the broader ask in #1300) is a much larger renderer change and is not attempted here. First-playthrough stutter on genuinely new pipelines remains.

Refs #1300

**@⁠gavvahar** on GitHub · 2026-10-09 15:37 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1312) `gavvahar:main` → `main` · +63 −5 · 4 files · 5 commits · open ## Problem Emulator crashes during gameplay (especially heavy loads like cinematics in Astro's Playroom) cause complete loss of the Vulkan pipeline cache. On next launch all shaders must recompile, perpetuating the stutter. Root cause: `PipelineCache::Save()` was only called on graceful shutdown (destructor + the explicit `WindowRun` path). Crashes go through `DbgExit()` -> `std::_Exit()`, which skips all C++ destructors, so the cache never reaches disk. ## Solution Add an `EmergencyShutdown()` callback to the Graphics subsystem Lifecycle, mirroring the existing pattern used by `Libs::Controller` and `Libs::LibKernel::FileSystem`. It dumps the in-memory Vulkan pipeline cache to disk during emergency teardown, using `TryLock()` so a crash on a thread already holding the render mutex skips the save rather than hanging the crash handler. Graphics is registered last in `emulator.cpp`, so its emergency callback runs first in the reverse-order teardown, while the FileSystem subsystem is still alive to service the write. ## Changes - `src/libs/agc.cpp`: add `EmergencyShutdown()` - `src/libs/agc.h`: declare it and wire it into `Lifecycle::emergency_shutdown` ## Verification Full build of the `launcher` target passes: 1084 objects, 0 errors, 191 warnings (all pre-existing, e.g. deprecated `wstring_convert` in `stringUtils.h`). ## Scope This makes the existing cache survive crashes. Predictive/async shader pre-compilation (the broader ask in #1300) is a much larger renderer change and is not attempted here. First-playthrough stutter on genuinely new pipelines remains. Refs #1300
The pipeline cache (VkPipelineCache serialized to _PipelineCache/{title_id}.bin)
survives crashes only if the graphics subsystem has an emergency_shutdown
callback to flush it to disk before process exit. Currently, the graphics
lifecycle registers only a shutdown callback (runs on clean exit) but no
emergency_shutdown (runs on assertion/EXIT() crashes).

This causes crash scenarios to lose all compiled pipelines: if a game crashes
during initial load (reported in issue #1300), the cache is never persisted,
and the next launch has no warm cache, forcing full recompilation and
perpetuating the stutter the user experienced before the crash.

Add EmergencyShutdown() to Libs::Graphics following the exact pattern of
Libs::Controller and Libs::LibKernel::FileSystem. The function:
- Checks g_renderer != nullptr
- Uses TryLock to avoid deadlock if called from a thread already holding
  the render context mutex (safe no-op if lock fails)
- Calls Save() to persist the pipeline cache to disk

Fixes #1300
fix: save pipeline cache on emulator crash
The graphics mutex is recursive on all platforms (CRITICAL_SECTION on Windows,
std::recursive_mutex on Unix), so TryLock() always succeeds even if the current
thread already holds the lock. The previous code mistakenly relied on TryLock()
failing to detect ownership.

Add explicit owner tracking to MutexPrivate:
- m_owner: atomic thread ID (read by any thread, written only by owner)
- m_depth: recursion depth (read/written only by owner under the lock)

Update Lock/Unlock/TryLock to maintain ownership invariants.

Expose Mutex::IsHeldByCurrentThread() for crash-handler use.

Rewrite Graphics::EmergencyShutdown() to check ownership explicitly and bail out
if the crashing thread already holds the render lock (avoiding recursive Save()
and blocking I/O from within crash handling).

Fixes CodeRabbit finding: Do not use TryLock() as the emergency ownership check.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:52:34 +00:00
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-09 15:40 UTC · original · edited 2026-10-10 02:51 UTC

Review in Change Stack →Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository: KytyPS5/KytyPS5/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 45e07a51-3d20-49df-8372-a16215459b60

📥 Commits

Reviewing files that changed from the base of the PR and between 86a1c609c9 and 769f97289a.


📒 Files selected for processing (1)
  • src/common/threads.h

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.



📝 Walkthrough

Walkthrough

The graphics library adds EmergencyShutdown() and exposes it through Lifecycle::emergency_shutdown. Common::Mutex tracks lock ownership and exposes IsHeldByCurrentThread(). The shutdown function returns if the renderer is absent or the current thread holds the renderer mutex. Otherwise, it saves the pipeline cache only if it acquires the mutex with TryLock(), then unlocks it.

Suggested reviewers: nmzik


Priority: ⬇️ Low

Change: Bug fix

Merge Risk: ⚪ Minimal · up to 769f9

No actionable merge-blocking risk remains in the reviewed changes.

Pre-merge checks | Passed 4 | Failed 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 21.43% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 14 functions across 4 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check Passed The title clearly and concisely describes the main change: saving the pipeline cache when the emulator crashes.
Description check Passed The description directly explains the crash-related cache loss, the emergency shutdown solution, implementation scope, verification, and known limitations.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.


  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

**@⁠coderabbitai[bot]** on GitHub · 2026-10-09 15:40 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1312#issuecomment-6084181085) · edited 2026-10-10 02:51 UTC <!-- This is an auto-generated comment: summarize by coderabbit.ai --> <!-- review_stack_entry_start --> <a href="https://app.coderabbit.ai/change-stack/KytyPS5/KytyPS5/pull/1312?scope=ghh_OusAJGA4HG8ljoOV0wJvVx8NmnZIjc2DdjmxOu0xZWA&amp;cs_source=review_comment"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui.svg?v=3#gh-light-mode-only" alt="Review in Change Stack →" height="32"></a><a href="https://app.coderabbit.ai/change-stack/KytyPS5/KytyPS5/pull/1312?scope=ghh_OusAJGA4HG8ljoOV0wJvVx8NmnZIjc2DdjmxOu0xZWA&amp;cs_source=review_comment"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui-dark.svg?v=3#gh-dark-mode-only" alt="Review in Change Stack →" height="32"></a> <!-- review_stack_entry_end --> <!-- recent_review_start --> No actionable comments were generated in the recent review. 🎉 <details> <summary><strong>ℹ️ Recent review info</strong></summary> <dl> <dd> <details> <summary><strong>⚙️ Run configuration</strong></summary> <dl> <dd> - **Configuration used**: Repository: KytyPS5/KytyPS5/.coderabbit.yaml - **Review profile**: CHILL - **Plan**: Advanced - **Run ID**: `45e07a51-3d20-49df-8372-a16215459b60` <hr> </dd> </dl> </details> <details> <summary><strong>📥 Commits</strong></summary> <dl> <dd> Reviewing files that changed from the base of the PR and between 86a1c609c94852ac622fc4de980b29d0f2a5a503 and 769f97289a262368550e85cefdd4ba87cb40f57f. <hr> </dd> </dl> </details> <details> <summary><strong>📒 Files selected for processing (1)</strong></summary> <dl> <dd> * `src/common/threads.h` <hr> </dd> </dl> </details> **Included review availability:** This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review. <hr> </dd> </dl> </details> --- <!-- recent_review_end --> <!-- walkthrough_start --> <details> <summary><strong>📝 Walkthrough</strong></summary> <dl> <dd> ## Walkthrough The graphics library adds `EmergencyShutdown()` and exposes it through `Lifecycle::emergency_shutdown`. `Common::Mutex` tracks lock ownership and exposes `IsHeldByCurrentThread()`. The shutdown function returns if the renderer is absent or the current thread holds the renderer mutex. Otherwise, it saves the pipeline cache only if it acquires the mutex with `TryLock()`, then unlocks it. **Suggested reviewers:** `nmzik` <hr> </dd> </dl> </details> <!-- walkthrough_end --> <!-- change_assessment_start --> **Priority:** ⬇️ Low <!-- change_assessment_commit:"769f97289a262368550e85cefdd4ba87cb40f57f" --> **Change:** Bug fix <!-- change_assessment_end --> <!-- final_review_risk_start --> **Merge Risk:** **⚪ Minimal** · up to `769f9` <!-- final_review_risk_coverage:{"sourceCommitId":"769f97289a262368550e85cefdd4ba87cb40f57f","coveredCommitId":"769f97289a262368550e85cefdd4ba87cb40f57f","kind":"reviewed"} --> No actionable merge-blocking risk remains in the reviewed changes. <!-- final_review_risk_end --> <!-- pre_merge_checks_walkthrough_start --> <details> <summary><strong>Pre-merge checks | <sup><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-counter-passed-14-v1.svg" width="14" height="17" align="middle" alt="Passed" title="Passed"></picture></sup> 4 | <sup><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-counter-failed-14-v1.svg" width="14" height="17" align="middle" alt="Failed" title="Failed"></picture></sup> 1</strong></summary> <dl> <dd> ### ❌ Failed checks (1 warning) | Check name | Status | Explanation | Resolution | | :---------------- | :----------------------------------------------------------------------------------------------: | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | :--------------------------------------------------------------------------------- | | Docstring Coverage | ![Warning](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-warning.svg) | Docstring coverage is 21.43% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 14 functions across 4 files. | Write docstrings for the functions missing them to satisfy the coverage threshold. | <details> <summary><strong>✅ Passed checks (4 passed)</strong></summary> <dl> <dd> | Check name | Status | Explanation | | :------------------------ | :--------------------------------------------------------------------------------------------: | :---------------------------------------------------------------------------------------------------------------------------------------------------------- | | Title check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | The title clearly and concisely describes the main change: saving the pipeline cache when the emulator crashes. | | Description check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | The description directly explains the crash-related cache loss, the emergency shutdown solution, implementation scope, verification, and known limitations. | | Linked Issues check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | Check skipped because no linked issues were found for this pull request. | | Out of Scope Changes check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | Check skipped because no linked issues were found for this pull request. | <hr> </dd> </dl> </details> <hr> </dd> </dl> </details> <!-- pre_merge_checks_walkthrough_end --> <!-- autopilot:start --> - [ ] <!-- {"checkboxId":"2708ad07-9f24-4260-9c11-7dc76a49f2e3"} --> <strong title="Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts">Autofix</strong> · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts <!-- autopilot:end --> <!-- tips_start --> --- Thanks for using [CodeRabbit](https://coderabbit.ai?utm_source=oss&utm_medium=github&utm_campaign=KytyPS5/KytyPS5&utm_content=1312)! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. <details> <summary><strong>❤️ Share</strong></summary> <dl> <dd> - [X](https://twitter.com/intent/tweet?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A&url=https%3A//coderabbit.ai) - [Mastodon](https://mastodon.social/share?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A%20https%3A%2F%2Fcoderabbit.ai) - [Reddit](https://www.reddit.com/submit?title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&text=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code.%20Check%20it%20out%3A%20https%3A//coderabbit.ai) - [LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fcoderabbit.ai&mini=true&title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&summary=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code) <hr> </dd> </dl> </details> <sub>Comment `@coderabbitai help` to get the list of available commands.</sub> <!-- tips_end -->
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-09 15:40 UTC · original · edited 2026-10-09 17:21 UTC
On src/libs/agc.cpp line 84 (outdated):

@@ -75,6 +75,18 @@ void Shutdown() {
 	g_renderer = nullptr;
 }
 
+void EmergencyShutdown() {
+	if (g_renderer == nullptr) {
+		return;
+	}
+	// A crash on the thread that already holds this mutex would deadlock on Lock(); TryLock()
+	// just skips the save in that case instead of hanging the crash handler.
+	if (g_renderer->GetMutex().TryLock()) {

🩺 Stability & Availability | 🟠 Major | 🏗️ Heavy lift

🔎 Supported by static analysis

🏁 Script executed:

#!/bin/bash
# Inspect the cache save contract and the mutex implementation without running repository code.
rg -n -C 6 'GetPipelineCache\(\)|PipelineCache::Save\(|TryEnterCriticalSection|KYTY_WIN_CS' src

Repository: KytyPS5/KytyPS5

Length of output: 19708


🏁 Script executed:

nl -ba src/graphics/host_gpu/renderer/pipeline/pipelineCache.cpp | sed -n '500,590p'
printf '\n--- Save-related declarations and helpers ---\n'
rg -n -C 5 --glob '*.{cpp,h,hpp}' -e 'PipelineCache::Save|Save\(\).*Pipeline|vkGetPipelineCacheData|WriteFile|fwrite|ofstream|File::Write|WriteAll|SaveFile' src/graphics src/common

Repository: KytyPS5/KytyPS5

Length of output: 8133


🏁 Script executed:

printf '%s\n' '--- emergency shutdown dispatch ---'
rg -n -C 8 --glob '*.{cpp,h,hpp}' -e 'EmergencyShutdown|emergency callback|Emergency' src/libs src/common src/graphics | head -n 240
printf '%s\n' '--- file operations used by PipelineCache::Save ---'
rg -n -C 6 --glob '*.{cpp,h,hpp}' -e 'bool File::(Create|Flush|Close)|File::Flush|File::CreateDirectories|CreateDirectories|RenameFile|SysFileFlush|SysFileRename' src/common src/graphics

Repository: KytyPS5/KytyPS5

Length of output: 29326


Do not use TryLock() as the emergency ownership check.

On Windows, Mutex::TryLock() uses recursive TryEnterCriticalSection. If the fatal path runs on the thread that owns the renderer mutex, it can enter PipelineCache::Save() instead of skipping the save. Save() performs Vulkan cache retrieval and synchronous filesystem operations, including FlushFileBuffers and file renaming. These operations can delay emergency termination.

Use a separate non-recursive, ownership-independent guard for the emergency save. Do not rely on recursively acquiring the renderer mutex to detect whether the save is safe.

✅ Addressed in commit 4df15ef

**@⁠coderabbitai[bot]** on GitHub · 2026-10-09 15:40 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1312#discussion_r4231879552) · edited 2026-10-09 17:21 UTC On `src/libs/agc.cpp` line 84 (outdated): ```diff @@ -75,6 +75,18 @@ void Shutdown() { g_renderer = nullptr; } +void EmergencyShutdown() { + if (g_renderer == nullptr) { + return; + } + // A crash on the thread that already holds this mutex would deadlock on Lock(); TryLock() + // just skips the save in that case instead of hanging the crash handler. + if (g_renderer->GetMutex().TryLock()) { ``` **🩺 Stability & Availability** | **🟠 Major** | **🏗️ Heavy lift** <details> <summary>🔎 Supported by static analysis</summary> 🏁 Script executed: ```bash #!/bin/bash # Inspect the cache save contract and the mutex implementation without running repository code. rg -n -C 6 'GetPipelineCache\(\)|PipelineCache::Save\(|TryEnterCriticalSection|KYTY_WIN_CS' src ``` Repository: KytyPS5/KytyPS5 Length of output: 19708 --- 🏁 Script executed: ```bash nl -ba src/graphics/host_gpu/renderer/pipeline/pipelineCache.cpp | sed -n '500,590p' printf '\n--- Save-related declarations and helpers ---\n' rg -n -C 5 --glob '*.{cpp,h,hpp}' -e 'PipelineCache::Save|Save\(\).*Pipeline|vkGetPipelineCacheData|WriteFile|fwrite|ofstream|File::Write|WriteAll|SaveFile' src/graphics src/common ``` Repository: KytyPS5/KytyPS5 Length of output: 8133 --- 🏁 Script executed: ```bash printf '%s\n' '--- emergency shutdown dispatch ---' rg -n -C 8 --glob '*.{cpp,h,hpp}' -e 'EmergencyShutdown|emergency callback|Emergency' src/libs src/common src/graphics | head -n 240 printf '%s\n' '--- file operations used by PipelineCache::Save ---' rg -n -C 6 --glob '*.{cpp,h,hpp}' -e 'bool File::(Create|Flush|Close)|File::Flush|File::CreateDirectories|CreateDirectories|RenameFile|SysFileFlush|SysFileRename' src/common src/graphics ``` Repository: KytyPS5/KytyPS5 Length of output: 29326 --- </details> **Do not use `TryLock()` as the emergency ownership check.** On Windows, `Mutex::TryLock()` uses recursive `TryEnterCriticalSection`. If the fatal path runs on the thread that owns the renderer mutex, it can enter `PipelineCache::Save()` instead of skipping the save. `Save()` performs Vulkan cache retrieval and synchronous filesystem operations, including `FlushFileBuffers` and file renaming. These operations can delay emergency termination. Use a separate non-recursive, ownership-independent guard for the emergency save. Do not rely on recursively acquiring the renderer mutex to detect whether the save is safe. <!-- fingerprinting:phantom:poseidon:wombat --> <!-- cr-indicator-types:potential_issue --> <!-- cr-comment:v1:6d09727af652402b3bc0b764 --> <!-- This is an auto-generated comment by CodeRabbit --> ✅ Addressed in commit 4df15ef
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-09 15:40 UTC · original · reviewed

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository: KytyPS5/KytyPS5/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 7d6f80ee-e414-439b-bb04-b587810128ba
📥 Commits

Reviewing files that changed from the base of the PR and between 4c8fc53a85 and 3264936f0f.

📒 Files selected for processing (2)
  • src/libs/agc.cpp
  • src/libs/agc.h

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.

**@⁠coderabbitai[bot]** on GitHub · 2026-10-09 15:40 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1312#pullrequestreview-5472222607) · **reviewed** **Actionable comments posted: 1** --- <details> <summary>ℹ️ Review info</summary> <details> <summary>⚙️ Run configuration</summary> - **Configuration used**: Repository: KytyPS5/KytyPS5/.coderabbit.yaml - **Review profile**: CHILL - **Plan**: Advanced - **Run ID**: `7d6f80ee-e414-439b-bb04-b587810128ba` </details> <details> <summary>📥 Commits</summary> Reviewing files that changed from the base of the PR and between 4c8fc53a8582543200caa697acad2a9f09937cec and 3264936f0fa115609cd504f01144e296fbb9a52c. </details> <details> <summary>📒 Files selected for processing (2)</summary> * `src/libs/agc.cpp` * `src/libs/agc.h` </details> **Included review availability:** This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review. </details> <!-- This is an auto-generated comment by CodeRabbit for review status --> <!-- coderabbit-review-publication v1 publication=3f9417c1-d261-438b-99f8-02dc758c5dc8 attempt=bb1ed26f-a43f-422f-b493-c0248261e5b7 batch=1/1 -->
@ -59,2 +59,4 @@
bool TryLock();
// Returns true if the current thread holds this mutex.
bool IsHeldByCurrentThread() const;
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-09 20:26 UTC · original

🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win

🔎 Supported by static analysis

🏁 Script executed:

#!/bin/bash
# Inspect the ownership transitions and condition-variable wait implementations.
ast-grep outline src/common/threads.cpp --match 'Mutex|CondVar|Wait' --view expanded
rg -n -C 12 'CondVar::Wait|CondVar::WaitFor|Mutex::Lock|Mutex::Unlock|Mutex::TryLock|IsHeldByCurrentThread|Acquired\(|Releasing\(' src/common/threads.cpp

Repository: KytyPS5/KytyPS5

Length of output: 4709


🏁 Script executed:

#!/bin/bash
set -eu

printf '%s\n' '--- src/common/threads.cpp:330-400 ---'
nl -ba src/common/threads.cpp | sed -n '330,400p'

printf '%s\n' '--- IsHeldByCurrentThread references ---'
rg -n -C 8 -F -- 'IsHeldByCurrentThread' src || test "$?" -eq 1

Repository: KytyPS5/KytyPS5

Length of output: 5050


Maintain ownership tracking across condition-variable waits.

CondVar::Wait() and CondVar::WaitFor() release and reacquire the underlying mutex without calling Mutex::Releasing() or Mutex::Acquired(). m_owner can therefore remain stale or identify another thread after reacquisition.

EmergencyShutdown() uses IsHeldByCurrentThread() before TryLock(). A stale false result can let the recursive TryLock() succeed while the current thread already holds the mutex, causing Save() to run on partially updated state. A stale true result can also skip a save when the mutex is not held.

Update ownership tracking around every direct release and reacquisition, including the polling callback.

**@⁠coderabbitai[bot]** on GitHub · 2026-10-09 20:26 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1312#discussion_r4234269877) **🩺 Stability & Availability** | **🟡 Minor** | **⚡ Quick win** <details> <summary>🔎 Supported by static analysis</summary> 🏁 Script executed: ```bash #!/bin/bash # Inspect the ownership transitions and condition-variable wait implementations. ast-grep outline src/common/threads.cpp --match 'Mutex|CondVar|Wait' --view expanded rg -n -C 12 'CondVar::Wait|CondVar::WaitFor|Mutex::Lock|Mutex::Unlock|Mutex::TryLock|IsHeldByCurrentThread|Acquired\(|Releasing\(' src/common/threads.cpp ``` Repository: KytyPS5/KytyPS5 Length of output: 4709 --- 🏁 Script executed: ```bash #!/bin/bash set -eu printf '%s\n' '--- src/common/threads.cpp:330-400 ---' nl -ba src/common/threads.cpp | sed -n '330,400p' printf '%s\n' '--- IsHeldByCurrentThread references ---' rg -n -C 8 -F -- 'IsHeldByCurrentThread' src || test "$?" -eq 1 ``` Repository: KytyPS5/KytyPS5 Length of output: 5050 --- </details> **Maintain ownership tracking across condition-variable waits.** `CondVar::Wait()` and `CondVar::WaitFor()` release and reacquire the underlying mutex without calling `Mutex::Releasing()` or `Mutex::Acquired()`. `m_owner` can therefore remain stale or identify another thread after reacquisition. `EmergencyShutdown()` uses `IsHeldByCurrentThread()` before `TryLock()`. A stale `false` result can let the recursive `TryLock()` succeed while the current thread already holds the mutex, causing `Save()` to run on partially updated state. A stale `true` result can also skip a save when the mutex is not held. Update ownership tracking around every direct release and reacquisition, including the polling callback. <!-- fingerprinting:phantom:poseidon:wombat --> <!-- cr-indicator-types:potential_issue --> <!-- cr-comment:v1:7f376fac48c60b3dc2d65508 --> <!-- This is an auto-generated comment by CodeRabbit -->
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-09 20:27 UTC · original · reviewed

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository: KytyPS5/KytyPS5/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 3c284ef5-3dae-44e3-bae0-8d6c773720e9
📥 Commits

Reviewing files that changed from the base of the PR and between 4df15ef266 and 86a1c609c9.

📒 Files selected for processing (2)
  • src/common/threads.h
  • src/libs/agc.cpp

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 6 remain after this review.

**@⁠coderabbitai[bot]** on GitHub · 2026-10-09 20:27 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1312#pullrequestreview-5475029731) · **reviewed** **Actionable comments posted: 1** --- <details> <summary>ℹ️ Review info</summary> <details> <summary>⚙️ Run configuration</summary> - **Configuration used**: Repository: KytyPS5/KytyPS5/.coderabbit.yaml - **Review profile**: CHILL - **Plan**: Advanced - **Run ID**: `3c284ef5-3dae-44e3-bae0-8d6c773720e9` </details> <details> <summary>📥 Commits</summary> Reviewing files that changed from the base of the PR and between 4df15ef2663ccba74aa16f06223c1e366546c1c6 and 86a1c609c94852ac622fc4de980b29d0f2a5a503. </details> <details> <summary>📒 Files selected for processing (2)</summary> * `src/common/threads.h` * `src/libs/agc.cpp` </details> **Included review availability:** This review used your included allowance. Your plan provides up to 8 included reviews per hour; 6 remain after this review. </details> <!-- This is an auto-generated comment by CodeRabbit for review status --> <!-- coderabbit-review-publication v1 publication=719e1e70-0041-4bea-99b8-f7741b844305 attempt=6f8421c7-55e6-4bdf-8492-ef0f5e39bb9c batch=1/1 -->
This pull request has changes conflicting with the target branch.
  • src/common/threads.cpp
  • src/common/threads.h
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/1312/head:github-bot/gh-1312'
git switch 'github-bot/gh-1312'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-1312'
git switch 'github-bot/gh-1312'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-1312'
git switch 'github-bot/gh-1312'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-1312'
git switch 'main'
git merge --squash 'github-bot/gh-1312'
git switch 'main'
git merge --ff-only 'github-bot/gh-1312'
git switch 'main'
git merge 'github-bot/gh-1312'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.