From 3d42592590c69595e396fe21760213a4f2561f7a Mon Sep 17 00:00:00 2001 From: Daniel Schloms Date: Sat, 6 Jul 2024 16:50:45 +0200 Subject: [PATCH] Use tryEnter for LfsFlash lock --- Sts1CobcSw/FileSystem/LfsFlash.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Sts1CobcSw/FileSystem/LfsFlash.cpp b/Sts1CobcSw/FileSystem/LfsFlash.cpp index 247ddea1..ec3f186c 100644 --- a/Sts1CobcSw/FileSystem/LfsFlash.cpp +++ b/Sts1CobcSw/FileSystem/LfsFlash.cpp @@ -34,6 +34,8 @@ auto readBuffer = flash::Page{}; auto programBuffer = decltype(readBuffer){}; auto lookaheadBuffer = flash::Page{}; +auto mutex = RODOS::Semaphore(); + lfs_config const lfsConfig = lfs_config{.context = nullptr, .read = &Read, .prog = &Program, @@ -137,12 +139,16 @@ auto Sync([[maybe_unused]] lfs_config const * config) -> int auto Lock(const struct lfs_config * config) -> int { - return 0; + if (mutex.tryEnter()){ + return 0; + } + return -99; } auto Unlock(const struct lfs_config * config) -> int { + mutex.leave(); return 0; } }