fix: use RAII render lock everywhere#916
Conversation
| // Authenticate | ||
| if (!KOREADER_STORE.hasCredentials()) { | ||
| // Can't authenticate without credentials - just show message briefly | ||
| xSemaphoreGive(renderingMutex); |
There was a problem hiding this comment.
Note: this is a stray mutex unlock, left-over from the original PR
daveallie
left a comment
There was a problem hiding this comment.
Looks good to me, just going to quickly test on device too
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
📝 WalkthroughWalkthroughThe PR systematically replaces explicit semaphore-based locking (xSemaphoreTake/xSemaphoreGive) with RAII-style RenderLock scopes across seven activity files. State updates and rendering-related critical sections now use scoped lock objects instead of manual semaphore management, with one notable exception where a semaphore release was removed. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (3)
src/activities/reader/KOReaderSyncActivity.cpp (1)
203-206: Inconsistent locking pattern: manual semaphore still used here.This code path still uses
xSemaphoreTake/xSemaphoreGivewhile the rest of this file and the PR migrate toRenderLock. For consistency, consider usingRenderLockhere as well.♻️ Suggested refactor for consistency
- xSemaphoreTake(self->renderingMutex, portMAX_DELAY); - self->statusMessage = "Calculating document hash..."; - xSemaphoreGive(self->renderingMutex); + { + RenderLock lock(*self); + self->statusMessage = "Calculating document hash..."; + }src/activities/reader/EpubReaderActivity.cpp (2)
410-431: Consider narrowing the lock scope around I/O operations.The lock is held during
epub->clearCache()andepub->setupCacheDir(), which involve file system I/O. While the atomicity across these operations is desirable, holding the render lock during I/O could potentially cause UI stutter if the render task needs to update. Since this path immediately triggerspendingGoHome, the impact is likely minimal, but it's worth noting.
466-483: Lock scope includes file I/O.The RenderLock is held during
SETTINGS.saveToFile(), which performs file I/O. Similar to the DELETE_CACHE case, this could potentially block the render task. However, the scope ensures that the orientation change, setting persistence, and section reset occur atomically, which may be the intended behavior.
|
@ngxson CodeRabbit found one additional use of semaphores directly in It could be: {
RenderLock lock(*self);
self->statusMessage = "Calculating document hash...";
}right? |
|
yeah good catch, I fixed in the last commit |
## Summary Follow-up to crosspoint-reader#774 --- ### AI Usage While CrossPoint doesn't have restrictions on AI tools in contributing, please be transparent about their usage as it helps set the right context for reviewers. Did you use AI tools to help write this code? **NO** <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit ## Release Notes * **Refactor** * Modernized internal synchronization mechanisms across multiple components to improve code reliability and maintainability. All functionality remains unchanged. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
## Summary Follow-up to crosspoint-reader#774 --- ### AI Usage While CrossPoint doesn't have restrictions on AI tools in contributing, please be transparent about their usage as it helps set the right context for reviewers. Did you use AI tools to help write this code? **NO** <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit ## Release Notes * **Refactor** * Modernized internal synchronization mechanisms across multiple components to improve code reliability and maintainability. All functionality remains unchanged. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
## Summary Follow-up to crosspoint-reader#774 --- ### AI Usage While CrossPoint doesn't have restrictions on AI tools in contributing, please be transparent about their usage as it helps set the right context for reviewers. Did you use AI tools to help write this code? **NO** <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit ## Release Notes * **Refactor** * Modernized internal synchronization mechanisms across multiple components to improve code reliability and maintainability. All functionality remains unchanged. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
Summary
Follow-up to #774
AI Usage
While CrossPoint doesn't have restrictions on AI tools in contributing, please be transparent about their usage as it
helps set the right context for reviewers.
Did you use AI tools to help write this code? NO
Summary by CodeRabbit
Release Notes