fix: use RAII render lock everywhere (#916)

## Summary

Follow-up to
https://github.com/crosspoint-reader/crosspoint-reader/pull/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 -->
This commit is contained in:
Xuan-Son Nguyen
2026-02-16 13:53:00 +01:00
committed by GitHub
parent 6702060960
commit 3d47c081f2
7 changed files with 151 additions and 126 deletions

View File

@@ -118,9 +118,10 @@ void ClearCacheActivity::loop() {
if (state == WARNING) {
if (mappedInput.wasPressed(MappedInputManager::Button::Confirm)) {
LOG_DBG("CLEAR_CACHE", "User confirmed, starting cache clear");
xSemaphoreTake(renderingMutex, portMAX_DELAY);
state = CLEARING;
xSemaphoreGive(renderingMutex);
{
RenderLock lock(*this);
state = CLEARING;
}
requestUpdateAndWait();
clearCache();

View File

@@ -14,18 +14,20 @@ void KOReaderAuthActivity::onWifiSelectionComplete(const bool success) {
exitActivity();
if (!success) {
xSemaphoreTake(renderingMutex, portMAX_DELAY);
state = FAILED;
errorMessage = "WiFi connection failed";
xSemaphoreGive(renderingMutex);
{
RenderLock lock(*this);
state = FAILED;
errorMessage = "WiFi connection failed";
}
requestUpdate();
return;
}
xSemaphoreTake(renderingMutex, portMAX_DELAY);
state = AUTHENTICATING;
statusMessage = "Authenticating...";
xSemaphoreGive(renderingMutex);
{
RenderLock lock(*this);
state = AUTHENTICATING;
statusMessage = "Authenticating...";
}
requestUpdate();
performAuthentication();
@@ -34,15 +36,16 @@ void KOReaderAuthActivity::onWifiSelectionComplete(const bool success) {
void KOReaderAuthActivity::performAuthentication() {
const auto result = KOReaderSyncClient::authenticate();
xSemaphoreTake(renderingMutex, portMAX_DELAY);
if (result == KOReaderSyncClient::OK) {
state = SUCCESS;
statusMessage = "Successfully authenticated!";
} else {
state = FAILED;
errorMessage = KOReaderSyncClient::errorString(result);
{
RenderLock lock(*this);
if (result == KOReaderSyncClient::OK) {
state = SUCCESS;
statusMessage = "Successfully authenticated!";
} else {
state = FAILED;
errorMessage = KOReaderSyncClient::errorString(result);
}
}
xSemaphoreGive(renderingMutex);
requestUpdate();
}

View File

@@ -121,7 +121,6 @@ void KOReaderSettingsActivity::handleSelection() {
// Authenticate
if (!KOREADER_STORE.hasCredentials()) {
// Can't authenticate without credentials - just show message briefly
xSemaphoreGive(renderingMutex);
return;
}
exitActivity();

View File

@@ -20,33 +20,37 @@ void OtaUpdateActivity::onWifiSelectionComplete(const bool success) {
LOG_DBG("OTA", "WiFi connected, checking for update");
xSemaphoreTake(renderingMutex, portMAX_DELAY);
state = CHECKING_FOR_UPDATE;
xSemaphoreGive(renderingMutex);
{
RenderLock lock(*this);
state = CHECKING_FOR_UPDATE;
}
requestUpdateAndWait();
const auto res = updater.checkForUpdate();
if (res != OtaUpdater::OK) {
LOG_DBG("OTA", "Update check failed: %d", res);
xSemaphoreTake(renderingMutex, portMAX_DELAY);
state = FAILED;
xSemaphoreGive(renderingMutex);
{
RenderLock lock(*this);
state = FAILED;
}
requestUpdate();
return;
}
if (!updater.isUpdateNewer()) {
LOG_DBG("OTA", "No new update available");
xSemaphoreTake(renderingMutex, portMAX_DELAY);
state = NO_UPDATE;
xSemaphoreGive(renderingMutex);
{
RenderLock lock(*this);
state = NO_UPDATE;
}
requestUpdate();
return;
}
xSemaphoreTake(renderingMutex, portMAX_DELAY);
state = WAITING_CONFIRMATION;
xSemaphoreGive(renderingMutex);
{
RenderLock lock(*this);
state = WAITING_CONFIRMATION;
}
requestUpdate();
}