improve sd lock handling again #523

Merged
muellerr merged 1 commits from another_imrovement_sd_lock_handling into develop 2023-03-24 21:29:41 +01:00
2 changed files with 3 additions and 3 deletions

View File

@ -312,7 +312,6 @@ void SdCardManager::resetState() {
ReturnValue_t SdCardManager::updateSdStatePair() { ReturnValue_t SdCardManager::updateSdStatePair() {
using namespace std; using namespace std;
MutexGuard mg(sdLock, LOCK_TYPE, SD_LOCK_TIMEOUT, LOCK_CTX);
std::error_code e; std::error_code e;
if (not filesystem::exists(SD_STATE_FILE, e)) { if (not filesystem::exists(SD_STATE_FILE, e)) {
return STATUS_FILE_NEXISTS; return STATUS_FILE_NEXISTS;
@ -362,6 +361,7 @@ void SdCardManager::processSdStatusLine(std::string& line, uint8_t& idx, sd::SdC
sdStates.second = sd::SdState::ON; sdStates.second = sd::SdState::ON;
} }
} else if (word == "off") { } else if (word == "off") {
MutexGuard mg(sdLock, LOCK_TYPE, SD_LOCK_TIMEOUT, LOCK_CTX);
if (currentSd == sd::SdCard::SLOT_0) { if (currentSd == sd::SdCard::SLOT_0) {
sdStates.first = sd::SdState::OFF; sdStates.first = sd::SdState::OFF;
} else { } else {
@ -371,6 +371,7 @@ void SdCardManager::processSdStatusLine(std::string& line, uint8_t& idx, sd::SdC
} }
if (mountLine) { if (mountLine) {
MutexGuard mg(sdLock, LOCK_TYPE, SD_LOCK_TIMEOUT, LOCK_CTX);
if (currentSd == sd::SdCard::SLOT_0) { if (currentSd == sd::SdCard::SLOT_0) {
sdStates.first = sd::SdState::MOUNTED; sdStates.first = sd::SdState::MOUNTED;
} else { } else {
@ -409,7 +410,6 @@ ReturnValue_t SdCardManager::updateSdCardStateFile() {
if (cmdExecutor.getCurrentState() == CommandExecutor::States::PENDING) { if (cmdExecutor.getCurrentState() == CommandExecutor::States::PENDING) {
return CommandExecutor::COMMAND_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 // Use q7hw utility and pipe the command output into the state file
std::string updateCmd = "q7hw sd info all > " + std::string(SD_STATE_FILE); std::string updateCmd = "q7hw sd info all > " + std::string(SD_STATE_FILE);
cmdExecutor.load(updateCmd, true, printCmdOutput); cmdExecutor.load(updateCmd, true, printCmdOutput);

View File

@ -228,7 +228,7 @@ class SdCardManager : public SystemObject, public SdCardMountedIF {
MutexIF* prefLock = nullptr; MutexIF* prefLock = nullptr;
MutexIF* defaultLock = nullptr; MutexIF* defaultLock = nullptr;
static constexpr MutexIF::TimeoutType LOCK_TYPE = MutexIF::TimeoutType::WAITING; 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 uint32_t OTHER_TIMEOUT = 20;
static constexpr char LOCK_CTX[] = "SdCardManager"; static constexpr char LOCK_CTX[] = "SdCardManager";