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 | |
| parent | a4f12344c68530d1f42c5b00c10ab417137c0491 (diff) | |
| download | rust-12d90aa949f34712a374984bfaf88a5bf2f08685.tar.gz rust-12d90aa949f34712a374984bfaf88a5bf2f08685.zip | |
put the MaybeUninit inside the UnsafeCell
| -rw-r--r-- | src/libcore/mem.rs | 3 | ||||
| -rw-r--r-- | src/libstd/sys/windows/mutex.rs | 17 |
2 files changed, 7 insertions, 13 deletions
diff --git a/src/libcore/mem.rs b/src/libcore/mem.rs index 626db7806df..b61a5c973a7 100644 --- a/src/libcore/mem.rs +++ b/src/libcore/mem.rs @@ -1106,9 +1106,6 @@ impl<T> MaybeUninit<T> { /// /// It is up to the caller to guarantee that the `MaybeUninit` really is in an initialized /// state, otherwise this will immediately cause undefined behavior. - // FIXME: We currently rely on the above being incorrect, i.e., we have references - // to uninitialized data (e.g. in `libstd/sys/windows/mutex.rs`). We should make - // a final decision about the rules before stabilization. #[unstable(feature = "maybe_uninit", issue = "53491")] #[inline(always)] pub unsafe fn get_ref(&self) -> &T { 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()); } } |
