Skip to content

Commit 3542a6f

Browse files
committed
Modify sys_common::Condvar to use parking_lot
1 parent 2df24c7 commit 3542a6f

File tree

2 files changed

+8
-19
lines changed

2 files changed

+8
-19
lines changed

src/libstd/sys_common/condvar.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,38 +10,38 @@
1010

1111
use time::Duration;
1212
use sys_common::mutex::{self, Mutex};
13-
use sys::condvar as imp;
13+
use sys_common::parking_lot::condvar::Condvar as RawCondvar;
1414

1515
/// An OS-based condition variable.
1616
///
1717
/// This structure is the lowest layer possible on top of the OS-provided
1818
/// condition variables. It is consequently entirely unsafe to use. It is
1919
/// recommended to use the safer types at the top level of this crate instead of
2020
/// this type.
21-
pub struct Condvar(imp::Condvar);
21+
pub struct Condvar(RawCondvar);
2222

2323
impl Condvar {
2424
/// Creates a new condition variable for use.
2525
///
2626
/// Behavior is undefined if the condition variable is moved after it is
2727
/// first used with any of the functions below.
2828
#[unstable(feature = "sys_internals", issue = "0")] // FIXME: min_const_fn
29-
pub const fn new() -> Condvar { Condvar(imp::Condvar::new()) }
29+
pub const fn new() -> Condvar { Condvar(RawCondvar::new()) }
3030

3131
/// Prepares the condition variable for use.
3232
///
3333
/// This should be called once the condition variable is at a stable memory
3434
/// address.
3535
#[inline]
36-
pub unsafe fn init(&mut self) { self.0.init() }
36+
pub unsafe fn init(&mut self) { }
3737

3838
/// Signals one waiter on this condition variable to wake up.
3939
#[inline]
40-
pub unsafe fn notify_one(&self) { self.0.notify_one() }
40+
pub unsafe fn notify_one(&self) { self.0.notify_one(); }
4141

4242
/// Awakens all current waiters on this condition variable.
4343
#[inline]
44-
pub unsafe fn notify_all(&self) { self.0.notify_all() }
44+
pub unsafe fn notify_all(&self) { self.0.notify_all(); }
4545

4646
/// Waits for a signal on the specified mutex.
4747
///
@@ -59,13 +59,13 @@ impl Condvar {
5959
/// on this condition variable.
6060
#[inline]
6161
pub unsafe fn wait_timeout(&self, mutex: &Mutex, dur: Duration) -> bool {
62-
self.0.wait_timeout(mutex::raw(mutex), dur)
62+
!self.0.wait_for(mutex::raw(mutex), dur).timed_out()
6363
}
6464

6565
/// Deallocates all resources associated with this condition variable.
6666
///
6767
/// Behavior is undefined if there are current or will be future users of
6868
/// this condition variable.
6969
#[inline]
70-
pub unsafe fn destroy(&self) { self.0.destroy() }
70+
pub unsafe fn destroy(&self) { }
7171
}

src/libstd/sys_common/parking_lot/condvar.rs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -66,24 +66,13 @@ pub struct Condvar {
6666
impl Condvar {
6767
/// Creates a new condition variable which is ready to be waited on and
6868
/// notified.
69-
#[cfg(feature = "nightly")]
7069
#[inline]
7170
pub const fn new() -> Condvar {
7271
Condvar {
7372
state: AtomicPtr::new(ptr::null_mut()),
7473
}
7574
}
7675

77-
/// Creates a new condition variable which is ready to be waited on and
78-
/// notified.
79-
#[cfg(not(feature = "nightly"))]
80-
#[inline]
81-
pub fn new() -> Condvar {
82-
Condvar {
83-
state: AtomicPtr::new(ptr::null_mut()),
84-
}
85-
}
86-
8776
/// Wakes up one blocked thread on this condvar.
8877
///
8978
/// Returns whether a thread was woken up.

0 commit comments

Comments
 (0)