From e69812b48b4e2c264307814fb3a4aaf9816afd1e Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Fri, 24 Mar 2023 21:29:13 +0100 Subject: [PATCH] improve sd lock handling again --- bsp_q7s/fs/SdCardManager.cpp | 4 ++-- bsp_q7s/fs/SdCardManager.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/bsp_q7s/fs/SdCardManager.cpp b/bsp_q7s/fs/SdCardManager.cpp index 29225899..89d3aaff 100644 --- a/bsp_q7s/fs/SdCardManager.cpp +++ b/bsp_q7s/fs/SdCardManager.cpp @@ -312,7 +312,6 @@ void SdCardManager::resetState() { ReturnValue_t SdCardManager::updateSdStatePair() { using namespace std; - MutexGuard mg(sdLock, LOCK_TYPE, SD_LOCK_TIMEOUT, LOCK_CTX); std::error_code e; if (not filesystem::exists(SD_STATE_FILE, e)) { return STATUS_FILE_NEXISTS; @@ -362,6 +361,7 @@ void SdCardManager::processSdStatusLine(std::string& line, uint8_t& idx, sd::SdC sdStates.second = sd::SdState::ON; } } else if (word == "off") { + MutexGuard mg(sdLock, LOCK_TYPE, SD_LOCK_TIMEOUT, LOCK_CTX); if (currentSd == sd::SdCard::SLOT_0) { sdStates.first = sd::SdState::OFF; } else { @@ -371,6 +371,7 @@ void SdCardManager::processSdStatusLine(std::string& line, uint8_t& idx, sd::SdC } if (mountLine) { + MutexGuard mg(sdLock, LOCK_TYPE, SD_LOCK_TIMEOUT, LOCK_CTX); if (currentSd == sd::SdCard::SLOT_0) { sdStates.first = sd::SdState::MOUNTED; } else { @@ -409,7 +410,6 @@ ReturnValue_t SdCardManager::updateSdCardStateFile() { if (cmdExecutor.getCurrentState() == CommandExecutor::States::PENDING) { return CommandExecutor::COMMAND_PENDING; } - MutexGuard mg(sdLock, LOCK_TYPE, SD_LOCK_TIMEOUT, LOCK_CTX); // Use q7hw utility and pipe the command output into the state file std::string updateCmd = "q7hw sd info all > " + std::string(SD_STATE_FILE); cmdExecutor.load(updateCmd, true, printCmdOutput); diff --git a/bsp_q7s/fs/SdCardManager.h b/bsp_q7s/fs/SdCardManager.h index cee06894..b7e2a09f 100644 --- a/bsp_q7s/fs/SdCardManager.h +++ b/bsp_q7s/fs/SdCardManager.h @@ -228,7 +228,7 @@ class SdCardManager : public SystemObject, public SdCardMountedIF { MutexIF* prefLock = nullptr; MutexIF* defaultLock = nullptr; static constexpr MutexIF::TimeoutType LOCK_TYPE = MutexIF::TimeoutType::WAITING; - static constexpr uint32_t SD_LOCK_TIMEOUT = 250; + static constexpr uint32_t SD_LOCK_TIMEOUT = 100; static constexpr uint32_t OTHER_TIMEOUT = 20; static constexpr char LOCK_CTX[] = "SdCardManager"; -- 2.43.0