aboutsummaryrefslogtreecommitdiff
path: root/embassy-executor/src/raw/util.rs
diff options
context:
space:
mode:
authorRasmus Melchior Jacobsen <[email protected]>2023-03-29 13:59:17 +0200
committerGitHub <[email protected]>2023-03-29 13:59:17 +0200
commit0bbc3a3d81f243b0249bf231a5b6cd53772b28e0 (patch)
treee161f3d2c3fa0f4e80785b1730dcf02cb53703d7 /embassy-executor/src/raw/util.rs
parentb7dfc8de10ceddd6c2e8c078e529eb5e266ea7db (diff)
parent7a841b58d127cc6d22c8895197d3f4d4c0974ad7 (diff)
Merge branch 'master' into flash-regions
Diffstat (limited to 'embassy-executor/src/raw/util.rs')
-rw-r--r--embassy-executor/src/raw/util.rs29
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
29unsafe impl<T> Sync for UninitCell<T> {}
30
31#[repr(transparent)]
32pub struct SyncUnsafeCell<T> {
33 value: UnsafeCell<T>,
34}
35
36unsafe impl<T: Sync> Sync for SyncUnsafeCell<T> {}
37
38impl<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}