Skip to content

Commit f2af41a

Browse files
committed
use MaybeUninit instead of mem::uninitialized for Windows Mutex
1 parent 45205f2 commit f2af41a

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

src/libstd/sys/windows/mutex.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
//! detect recursive locks.
3131
3232
use cell::UnsafeCell;
33-
use mem;
33+
use mem::{self, MaybeUninit};
3434
use sync::atomic::{AtomicUsize, Ordering};
3535
use sys::c;
3636
use sys::compat;
@@ -157,34 +157,34 @@ fn kind() -> Kind {
157157
return ret;
158158
}
159159

160-
pub struct ReentrantMutex { inner: UnsafeCell<c::CRITICAL_SECTION> }
160+
pub struct ReentrantMutex { inner: MaybeUninit<UnsafeCell<c::CRITICAL_SECTION>> }
161161

162162
unsafe impl Send for ReentrantMutex {}
163163
unsafe impl Sync for ReentrantMutex {}
164164

165165
impl ReentrantMutex {
166-
pub unsafe fn uninitialized() -> ReentrantMutex {
167-
mem::uninitialized()
166+
pub fn uninitialized() -> ReentrantMutex {
167+
MaybeUninit::uninitialized()
168168
}
169169

170170
pub unsafe fn init(&mut self) {
171-
c::InitializeCriticalSection(self.inner.get());
171+
c::InitializeCriticalSection(self.inner.get_ref().get());
172172
}
173173

174174
pub unsafe fn lock(&self) {
175-
c::EnterCriticalSection(self.inner.get());
175+
c::EnterCriticalSection(self.inner.get_ref().get());
176176
}
177177

178178
#[inline]
179179
pub unsafe fn try_lock(&self) -> bool {
180-
c::TryEnterCriticalSection(self.inner.get()) != 0
180+
c::TryEnterCriticalSection(self.inner.get_ref().get()) != 0
181181
}
182182

183183
pub unsafe fn unlock(&self) {
184-
c::LeaveCriticalSection(self.inner.get());
184+
c::LeaveCriticalSection(self.inner.get_ref().get());
185185
}
186186

187187
pub unsafe fn destroy(&self) {
188-
c::DeleteCriticalSection(self.inner.get());
188+
c::DeleteCriticalSection(self.inner.get_ref().get());
189189
}
190190
}

0 commit comments

Comments
 (0)