add mutex in furi_create_deprecated (#242)
This commit is contained in:
		
							parent
							
								
									3d6af91dd1
								
							
						
					
					
						commit
						2ba3722de2
					
				| @ -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; | ||||
| } | ||||
| @ -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; | ||||
| } | ||||
| 
 | ||||
|  | ||||
| @ -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. | ||||
|  | ||||
| @ -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); | ||||
|             } | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 DrZlo13
						DrZlo13