diff options
| author | jacqueline <me@jacqueline.id.au> | 2023-09-29 15:17:10 +1000 |
|---|---|---|
| committer | jacqueline <me@jacqueline.id.au> | 2023-09-29 15:17:32 +1000 |
| commit | ba940baa0aff05ad26d265f32f1d185a1f410373 (patch) | |
| tree | aca7e4ef8049039b7eb92160732d711db15873cf /src/database | |
| parent | c53802f308f57f0d829f5a02baf9e9fe8219c301 (diff) | |
| download | tangara-fw-ba940baa0aff05ad26d265f32f1d185a1f410373.tar.gz | |
Add a lock around the SPI bus
This seems to have been the cause of recurring deadlocks that have been
difficult to repo.
Diffstat (limited to 'src/database')
| -rw-r--r-- | src/database/tag_parser.cpp | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/src/database/tag_parser.cpp b/src/database/tag_parser.cpp index fe71089d..bec41507 100644 --- a/src/database/tag_parser.cpp +++ b/src/database/tag_parser.cpp @@ -14,6 +14,7 @@ #include "esp_log.h" #include "ff.h" #include "opusfile.h" +#include "spi.hpp" #include "tags.h" #include "memory_resource.hpp" @@ -184,10 +185,14 @@ auto GenericTagParser::ReadAndParseTags(const std::pmr::string& path) libtags::Aux aux; auto out = std::make_shared<TrackTags>(); aux.tags = out.get(); - if (f_stat(path.c_str(), &aux.info) != FR_OK || - f_open(&aux.file, path.c_str(), FA_READ) != FR_OK) { - ESP_LOGW(kTag, "failed to open file %s", path.c_str()); - return {}; + { + auto lock = drivers::acquire_spi(); + + if (f_stat(path.c_str(), &aux.info) != FR_OK || + f_open(&aux.file, path.c_str(), FA_READ) != FR_OK) { + ESP_LOGW(kTag, "failed to open file %s", path.c_str()); + return {}; + } } // Fine to have this on the stack; this is only called on tasks with large // stacks anyway, due to all the string handling. @@ -200,8 +205,13 @@ auto GenericTagParser::ReadAndParseTags(const std::pmr::string& path) ctx.aux = &aux; ctx.buf = buf; ctx.bufsz = kBufSize; - int res = tagsget(&ctx); - f_close(&aux.file); + + int res; + { + auto lock = drivers::acquire_spi(); + res = tagsget(&ctx); + f_close(&aux.file); + } if (res != 0) { // Parsing failed. |
