diff --git a/mission/freeRTOS_rust_helper.c b/mission/freeRTOS_rust_helper.c index c3814a8..08bd8d3 100644 --- a/mission/freeRTOS_rust_helper.c +++ b/mission/freeRTOS_rust_helper.c @@ -241,7 +241,7 @@ uint8_t freertos_simple_once(uint8_t *once_data) { // TODO assert global_once_mutex != NULL uint8_t result = 0; - + // Todo: Replace Mutex with critical section // This function is basically a flag stored in once_data, protected by the // global_once_mutex if (xSemaphoreTakeRecursive(global_once_mutex, portMAX_DELAY) != pdTRUE) { diff --git a/mission_rust/src/fsrc/osal/sync/static_read_once_lock.rs b/mission_rust/src/fsrc/osal/sync/static_read_once_lock.rs index bf9b38a..c72127e 100644 --- a/mission_rust/src/fsrc/osal/sync/static_read_once_lock.rs +++ b/mission_rust/src/fsrc/osal/sync/static_read_once_lock.rs @@ -26,12 +26,16 @@ impl StaticReadOnceLock { impl StaticReadOnceLock { pub fn take(&'static self) -> Option<&'static mut T> { - let inner = unsafe{&mut *self.inner.get()}; - inner.static_init(); - // Re-Borrow inner. - // TODO Is unsafe by leaking static references via static_init() - self.take_no_init() + + if self.once.once() { + // SAFE: Prozected by once + let inner: &mut T = unsafe{&mut *self.inner.get()}; + inner.static_init(); + // Re-Borrow inner. + // TODO Is unsafe by leaking static references via static_init() + return Some(unsafe{&mut *self.inner.get()}) + } + None } } - unsafe impl Sync for StaticReadOnceLock {} \ No newline at end of file