forked from ROMEO/fsw-ws
slightly less unsafe take
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -26,12 +26,16 @@ impl<T: 'static> StaticReadOnceLock<T> {
|
||||
|
||||
impl<T: 'static + StaticInit> StaticReadOnceLock<T> {
|
||||
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<T> Sync for StaticReadOnceLock<T> {}
|
||||
Reference in New Issue
Block a user