Kaynağa Gözat

add mutex in furi_create_deprecated (#242)

DrZlo13 5 yıl önce
ebeveyn
işleme
2ba3722de2
4 değiştirilmiş dosya ile 30 ekleme ve 3 silme
  1. 11 1
      core/flipper_v2.c
  2. 14 0
      core/furi-deprecated.c
  3. 3 0
      core/furi-deprecated.h
  4. 2 2
      core/furi_ac.c

+ 11 - 1
core/flipper_v2.c

@@ -1,5 +1,15 @@
 #include "flipper_v2.h"
 
 bool init_flipper_api(void) {
-    return gpio_api_init();
+    bool no_errors = true;
+
+    if(!furi_init()) {
+        no_errors = false;
+    }
+
+    if(!gpio_api_init()) {
+        no_errors = false;
+    }
+
+    return no_errors;
 }

+ 14 - 0
core/furi-deprecated.c

@@ -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;
 }
 

+ 3 - 0
core/furi-deprecated.h

@@ -87,6 +87,9 @@ typedef struct {
     FlipperAppLibrary libs;
 } FlipperStartupApp;
 
+// Init core
+bool furi_init(void);
+
 /*!
 Simply starts application.
 It call app entrypoint with param passed as argument.

+ 2 - 2
core/furi_ac.c

@@ -31,12 +31,12 @@ void furiac_wait_libs(const FlipperAppLibrary* libs) {
 
         if(app_id == INVALID_TASK_ID) {
 #ifdef FURI_DEBUG
-            printf("[FURIAC] Invalid library name %s\n", lib_name);
+            printf("[FURIAC] Invalid library name %s\n", libs->name[i]);
 #endif
         } else {
             while(!task_buffer[app_id].ready) {
 #ifdef FURI_DEBUG
-                printf("[FURIAC] waiting for library \"%s\"\n", lib_name);
+                printf("[FURIAC] waiting for library \"%s\"\n", libs->name[i]);
 #endif
                 osDelay(50);
             }