diff options
| author | Ralf Jung <post@ralfj.de> | 2018-11-28 09:29:56 +0100 |
|---|---|---|
| committer | Ralf Jung <post@ralfj.de> | 2018-11-28 09:29:56 +0100 |
| commit | 12d90aa949f34712a374984bfaf88a5bf2f08685 (patch) | |
| tree | 84058d85f4269cf4ce2fcb3cf0460dc2fc6eb0ca /src/libstd/sys/windows | |
| parent | a4f12344c68530d1f42c5b00c10ab417137c0491 (diff) | |
| download | rust-12d90aa949f34712a374984bfaf88a5bf2f08685.tar.gz rust-12d90aa949f34712a374984bfaf88a5bf2f08685.zip | |
put the MaybeUninit inside the UnsafeCell
Diffstat (limited to 'src/libstd/sys/windows')
| -rw-r--r-- | src/libstd/sys/windows/mutex.rs | 17 |
1 files changed, 7 insertions, 10 deletions
diff --git a/src/libstd/sys/windows/mutex.rs b/src/libstd/sys/windows/mutex.rs index 0c228f5097e..38ba0c7e035 100644 --- a/src/libstd/sys/windows/mutex.rs +++ b/src/libstd/sys/windows/mutex.rs @@ -157,37 +157,34 @@ fn kind() -> Kind { return ret; } -pub struct ReentrantMutex { inner: MaybeUninit<UnsafeCell<c::CRITICAL_SECTION>> } +pub struct ReentrantMutex { inner: UnsafeCell<MaybeUninit<c::CRITICAL_SECTION>> } unsafe impl Send for ReentrantMutex {} unsafe impl Sync for ReentrantMutex {} impl ReentrantMutex { pub fn uninitialized() -> ReentrantMutex { - ReentrantMutex { inner: MaybeUninit::uninitialized() } + ReentrantMutex { inner: UnsafeCell::new(MaybeUninit::uninitialized()) } } pub unsafe fn init(&mut self) { - // FIXME: Technically, this is calling `get_ref` on an uninitialized - // `MaybeUninit`. Revisit this once we decided whether that is valid - // or not. - c::InitializeCriticalSection(self.inner.get_ref().get()); + c::InitializeCriticalSection(self.inner.get().as_mut_ptr()); } pub unsafe fn lock(&self) { - c::EnterCriticalSection(self.inner.get_ref().get()); + c::EnterCriticalSection(self.inner.get().get_ref()); } #[inline] pub unsafe fn try_lock(&self) -> bool { - c::TryEnterCriticalSection(self.inner.get_ref().get()) != 0 + c::TryEnterCriticalSection(self.inner.get().get_ref()) != 0 } pub unsafe fn unlock(&self) { - c::LeaveCriticalSection(self.inner.get_ref().get()); + c::LeaveCriticalSection(self.inner.get().get_ref()); } pub unsafe fn destroy(&self) { - c::DeleteCriticalSection(self.inner.get_ref().get()); + c::DeleteCriticalSection(self.inner.get().get_ref()); } } |
