diff options
| author | sander <[email protected]> | 2023-03-30 14:37:51 +0200 |
|---|---|---|
| committer | sander <[email protected]> | 2023-03-30 14:37:51 +0200 |
| commit | 6b2aaacf830d69fcb05f9611d3780f56b4ae82bc (patch) | |
| tree | a6e4d7628cd5153bbfd122b902a598b0862feeb9 /embassy-executor/src/raw/util.rs | |
| parent | ba9afbc26d06ab38065cbff5b17a7f76db297ad4 (diff) | |
| parent | 754bb802ba377c19be97d092c4b2afe542de20b5 (diff) | |
Update embassy
Merge commit '9dd3719f09835f646e3a8f3abaa33726a1e3f9ca'
Diffstat (limited to 'embassy-executor/src/raw/util.rs')
| -rw-r--r-- | embassy-executor/src/raw/util.rs | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/embassy-executor/src/raw/util.rs b/embassy-executor/src/raw/util.rs index 2b1f6b6f3..e2e8f4df8 100644 --- a/embassy-executor/src/raw/util.rs +++ b/embassy-executor/src/raw/util.rs | |||
| @@ -25,3 +25,32 @@ impl<T> UninitCell<T> { | |||
| 25 | ptr::drop_in_place(self.as_mut_ptr()) | 25 | ptr::drop_in_place(self.as_mut_ptr()) |
| 26 | } | 26 | } |
| 27 | } | 27 | } |
| 28 | |||
| 29 | unsafe impl<T> Sync for UninitCell<T> {} | ||
| 30 | |||
| 31 | #[repr(transparent)] | ||
| 32 | pub struct SyncUnsafeCell<T> { | ||
| 33 | value: UnsafeCell<T>, | ||
| 34 | } | ||
| 35 | |||
| 36 | unsafe impl<T: Sync> Sync for SyncUnsafeCell<T> {} | ||
| 37 | |||
| 38 | impl<T> SyncUnsafeCell<T> { | ||
| 39 | #[inline] | ||
| 40 | pub const fn new(value: T) -> Self { | ||
| 41 | Self { | ||
| 42 | value: UnsafeCell::new(value), | ||
| 43 | } | ||
| 44 | } | ||
| 45 | |||
| 46 | pub unsafe fn set(&self, value: T) { | ||
| 47 | *self.value.get() = value; | ||
| 48 | } | ||
| 49 | |||
| 50 | pub unsafe fn get(&self) -> T | ||
| 51 | where | ||
| 52 | T: Copy, | ||
| 53 | { | ||
| 54 | *self.value.get() | ||
| 55 | } | ||
| 56 | } | ||
