lock context for sd card manager
Some checks are pending
EIVE/eive-obsw/pipeline/head Build started...

This commit is contained in:
Robin Müller 2023-03-02 15:41:09 +01:00
parent 7b571bc007
commit ad4ab98356
No known key found for this signature in database
GPG Key ID: 11D4952C8CCEF814
2 changed files with 12 additions and 11 deletions

View File

@ -195,7 +195,7 @@ ReturnValue_t SdCardManager::setSdCardState(sd::SdCard sdCard, bool on) {
ReturnValue_t SdCardManager::getSdCardsStatus(SdStatePair& active) { ReturnValue_t SdCardManager::getSdCardsStatus(SdStatePair& active) {
using namespace std; using namespace std;
MutexGuard mg(sdLock, lockType, lockTimeout); MutexGuard mg(sdLock, LOCK_TYPE, LOCK_TIMEOUT, LOCK_CTX);
if (not filesystem::exists(SD_STATE_FILE)) { if (not filesystem::exists(SD_STATE_FILE)) {
return STATUS_FILE_NEXISTS; return STATUS_FILE_NEXISTS;
} }
@ -378,7 +378,7 @@ void SdCardManager::processSdStatusLine(std::pair<sd::SdState, sd::SdState>& act
} }
std::optional<sd::SdCard> SdCardManager::getPreferredSdCard() const { std::optional<sd::SdCard> SdCardManager::getPreferredSdCard() const {
MutexGuard mg(sdLock, lockType, lockTimeout); MutexGuard mg(sdLock, LOCK_TYPE, LOCK_TIMEOUT, LOCK_CTX);
auto res = mg.getLockResult(); auto res = mg.getLockResult();
if (res != returnvalue::OK) { if (res != returnvalue::OK) {
sif::error << "SdCardManager::getPreferredSdCard: Lock error" << std::endl; sif::error << "SdCardManager::getPreferredSdCard: Lock error" << std::endl;
@ -387,7 +387,7 @@ std::optional<sd::SdCard> SdCardManager::getPreferredSdCard() const {
} }
ReturnValue_t SdCardManager::setPreferredSdCard(sd::SdCard sdCard) { ReturnValue_t SdCardManager::setPreferredSdCard(sd::SdCard sdCard) {
MutexGuard mg(sdLock, lockType, lockTimeout); MutexGuard mg(sdLock, LOCK_TYPE, LOCK_TIMEOUT, LOCK_CTX);
if (sdCard == sd::SdCard::BOTH) { if (sdCard == sd::SdCard::BOTH) {
return returnvalue::FAILED; return returnvalue::FAILED;
} }
@ -399,7 +399,7 @@ 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, lockType, lockTimeout); MutexGuard mg(sdLock, LOCK_TYPE, 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, blocking, printCmdOutput); cmdExecutor.load(updateCmd, blocking, printCmdOutput);
@ -411,7 +411,7 @@ ReturnValue_t SdCardManager::updateSdCardStateFile() {
} }
const char* SdCardManager::getCurrentMountPrefix() const { const char* SdCardManager::getCurrentMountPrefix() const {
MutexGuard mg(sdLock, lockType, lockTimeout); MutexGuard mg(sdLock, LOCK_TYPE, LOCK_TIMEOUT, LOCK_CTX);
if (currentPrefix.has_value()) { if (currentPrefix.has_value()) {
return currentPrefix.value().c_str(); return currentPrefix.value().c_str();
} }
@ -464,7 +464,7 @@ void SdCardManager::setPrintCommandOutput(bool print) { this->printCmdOutput = p
bool SdCardManager::isSdCardUsable(std::optional<sd::SdCard> sdCard) { bool SdCardManager::isSdCardUsable(std::optional<sd::SdCard> sdCard) {
{ {
MutexGuard mg(sdLock, lockType, lockTimeout); MutexGuard mg(sdLock, LOCK_TYPE, LOCK_TIMEOUT, LOCK_CTX);
if (markedUnusable) { if (markedUnusable) {
return false; return false;
} }
@ -560,7 +560,7 @@ ReturnValue_t SdCardManager::performFsck(sd::SdCard sdcard, bool printOutput, in
} }
void SdCardManager::setActiveSdCard(sd::SdCard sdCard) { void SdCardManager::setActiveSdCard(sd::SdCard sdCard) {
MutexGuard mg(sdLock, lockType, lockTimeout); MutexGuard mg(sdLock, LOCK_TYPE, LOCK_TIMEOUT, LOCK_CTX);
sdInfo.active = sdCard; sdInfo.active = sdCard;
if (sdInfo.active == sd::SdCard::SLOT_0) { if (sdInfo.active == sd::SdCard::SLOT_0) {
currentPrefix = config::SD_0_MOUNT_POINT; currentPrefix = config::SD_0_MOUNT_POINT;
@ -570,7 +570,7 @@ void SdCardManager::setActiveSdCard(sd::SdCard sdCard) {
} }
std::optional<sd::SdCard> SdCardManager::getActiveSdCard() const { std::optional<sd::SdCard> SdCardManager::getActiveSdCard() const {
MutexGuard mg(sdLock, lockType, lockTimeout); MutexGuard mg(sdLock, LOCK_TYPE, LOCK_TIMEOUT, LOCK_CTX);
if (markedUnusable) { if (markedUnusable) {
return std::nullopt; return std::nullopt;
} }
@ -578,6 +578,6 @@ std::optional<sd::SdCard> SdCardManager::getActiveSdCard() const {
} }
void SdCardManager::markUnusable() { void SdCardManager::markUnusable() {
MutexGuard mg(sdLock, lockType, lockTimeout); MutexGuard mg(sdLock, LOCK_TYPE, LOCK_TIMEOUT, LOCK_CTX);
markedUnusable = true; markedUnusable = true;
} }

View File

@ -224,8 +224,9 @@ class SdCardManager : public SystemObject, public SdCardMountedIF {
bool printCmdOutput = true; bool printCmdOutput = true;
bool markedUnusable = false; bool markedUnusable = false;
MutexIF* sdLock = nullptr; MutexIF* sdLock = nullptr;
MutexIF::TimeoutType lockType = MutexIF::TimeoutType::WAITING; static constexpr MutexIF::TimeoutType LOCK_TYPE = MutexIF::TimeoutType::WAITING;
uint32_t lockTimeout = 40; static constexpr uint32_t LOCK_TIMEOUT = 40;
static constexpr char LOCK_CTX[] = "SdCardManager";
SdCardManager(); SdCardManager();