add mutex in furi_create_deprecated (#242)

This commit is contained in:
DrZlo13
2020-11-16 20:22:28 +03:00
committed by GitHub
parent 3d6af91dd1
commit 2ba3722de2
4 changed files with 30 additions and 3 deletions

View File

@@ -11,6 +11,13 @@
static FuriRecord records[MAX_RECORD_COUNT];
static size_t current_buffer_idx = 0;
osMutexId_t furi_core_mutex;
bool furi_init(void) {
furi_core_mutex = osMutexNew(NULL);
if(furi_core_mutex == NULL) return false;
return true;
}
// find record pointer by name
static FuriRecord* find_record(const char* name) {
@@ -32,6 +39,11 @@ bool furi_create_deprecated(const char* name, void* value, size_t size) {
printf("[FURI] creating %s record\n", name);
#endif
// acquire mutex to prevent simultaneous write to record with same index
if(osMutexAcquire(furi_core_mutex, osWaitForever) != osOK) {
return false;
}
FuriRecord* record = find_record(name);
if(record != NULL) {
@@ -69,6 +81,8 @@ bool furi_create_deprecated(const char* name, void* value, size_t size) {
current_buffer_idx++;
osMutexRelease(furi_core_mutex);
return true;
}