diff options
| author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2022-08-17 23:22:52 +0000 |
|---|---|---|
| committer | GitHub <[email protected]> | 2022-08-17 23:22:52 +0000 |
| commit | be55d2a39eb399d693d11f37dfa4b87cd2bd3c7a (patch) | |
| tree | 2ef0b4d6f9b1c02dac2589e7b57982c20cbc0e66 /embassy-executor/src/raw/util.rs | |
| parent | 1c5b54a4823d596db730eb476c3ab78110557214 (diff) | |
| parent | 5daa173ce4b153a532b4daa9e94c7a248231f25b (diff) | |
Merge #909
909: Split embassy-time from embassy-executor. r=Dirbaio a=Dirbaio
For now this will fail to link unless you enable `embassy-executor/integrated-timers`. i'll add an executor-independent timer queue to `embassy-time` later.
Co-authored-by: Dario Nieuwenhuis <[email protected]>
Diffstat (limited to 'embassy-executor/src/raw/util.rs')
| -rw-r--r-- | embassy-executor/src/raw/util.rs | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/embassy-executor/src/raw/util.rs b/embassy-executor/src/raw/util.rs new file mode 100644 index 000000000..ed5822188 --- /dev/null +++ b/embassy-executor/src/raw/util.rs | |||
| @@ -0,0 +1,33 @@ | |||
| 1 | use core::cell::UnsafeCell; | ||
| 2 | use core::mem::MaybeUninit; | ||
| 3 | use core::ptr; | ||
| 4 | |||
| 5 | pub(crate) struct UninitCell<T>(MaybeUninit<UnsafeCell<T>>); | ||
| 6 | impl<T> UninitCell<T> { | ||
| 7 | pub const fn uninit() -> Self { | ||
| 8 | Self(MaybeUninit::uninit()) | ||
| 9 | } | ||
| 10 | |||
| 11 | pub unsafe fn as_mut_ptr(&self) -> *mut T { | ||
| 12 | (*self.0.as_ptr()).get() | ||
| 13 | } | ||
| 14 | |||
| 15 | #[allow(clippy::mut_from_ref)] | ||
| 16 | pub unsafe fn as_mut(&self) -> &mut T { | ||
| 17 | &mut *self.as_mut_ptr() | ||
| 18 | } | ||
| 19 | |||
| 20 | pub unsafe fn write(&self, val: T) { | ||
| 21 | ptr::write(self.as_mut_ptr(), val) | ||
| 22 | } | ||
| 23 | |||
| 24 | pub unsafe fn drop_in_place(&self) { | ||
| 25 | ptr::drop_in_place(self.as_mut_ptr()) | ||
| 26 | } | ||
| 27 | } | ||
| 28 | |||
| 29 | impl<T: Copy> UninitCell<T> { | ||
| 30 | pub unsafe fn read(&self) -> T { | ||
| 31 | ptr::read(self.as_mut_ptr()) | ||
| 32 | } | ||
| 33 | } | ||
