Make it possible to have unboxed condvars on specific platforms.
This commit keeps all condvars boxed on all platforms, but makes it trivial to remove the box on some platforms later.
This commit is contained in:
parent
dc81cbdcb1
commit
b181f5a923
|
@ -15,6 +15,8 @@ pub struct Condvar {
|
||||||
condvar: UnsafeCell<AtomicU32>,
|
condvar: UnsafeCell<AtomicU32>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub type MovableCondvar = Box<Condvar>;
|
||||||
|
|
||||||
unsafe impl Send for Condvar {}
|
unsafe impl Send for Condvar {}
|
||||||
unsafe impl Sync for Condvar {}
|
unsafe impl Sync for Condvar {}
|
||||||
|
|
||||||
|
|
|
@ -14,6 +14,8 @@ pub struct Condvar {
|
||||||
sem2: *const c_void,
|
sem2: *const c_void,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub type MovableCondvar = Box<Condvar>;
|
||||||
|
|
||||||
unsafe impl Send for Condvar {}
|
unsafe impl Send for Condvar {}
|
||||||
unsafe impl Sync for Condvar {}
|
unsafe impl Sync for Condvar {}
|
||||||
|
|
||||||
|
|
|
@ -7,6 +7,8 @@ pub struct Condvar {
|
||||||
inner: SpinMutex<WaitVariable<()>>,
|
inner: SpinMutex<WaitVariable<()>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub type MovableCondvar = Box<Condvar>;
|
||||||
|
|
||||||
impl Condvar {
|
impl Condvar {
|
||||||
pub const fn new() -> Condvar {
|
pub const fn new() -> Condvar {
|
||||||
Condvar { inner: SpinMutex::new(WaitVariable::new(())) }
|
Condvar { inner: SpinMutex::new(WaitVariable::new(())) }
|
||||||
|
|
|
@ -6,6 +6,8 @@ pub struct Condvar {
|
||||||
inner: UnsafeCell<libc::pthread_cond_t>,
|
inner: UnsafeCell<libc::pthread_cond_t>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub type MovableCondvar = Box<Condvar>;
|
||||||
|
|
||||||
unsafe impl Send for Condvar {}
|
unsafe impl Send for Condvar {}
|
||||||
unsafe impl Sync for Condvar {}
|
unsafe impl Sync for Condvar {}
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,8 @@ use crate::time::Duration;
|
||||||
|
|
||||||
pub struct Condvar {}
|
pub struct Condvar {}
|
||||||
|
|
||||||
|
pub type MovableCondvar = Box<Condvar>;
|
||||||
|
|
||||||
impl Condvar {
|
impl Condvar {
|
||||||
pub const fn new() -> Condvar {
|
pub const fn new() -> Condvar {
|
||||||
Condvar {}
|
Condvar {}
|
||||||
|
|
|
@ -6,6 +6,8 @@ pub struct Condvar {
|
||||||
inner: UnsafeCell<libc::pthread_cond_t>,
|
inner: UnsafeCell<libc::pthread_cond_t>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub type MovableCondvar = Box<Condvar>;
|
||||||
|
|
||||||
unsafe impl Send for Condvar {}
|
unsafe impl Send for Condvar {}
|
||||||
unsafe impl Sync for Condvar {}
|
unsafe impl Sync for Condvar {}
|
||||||
|
|
||||||
|
|
|
@ -9,6 +9,8 @@ pub struct Condvar {
|
||||||
cnt: AtomicUsize,
|
cnt: AtomicUsize,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub type MovableCondvar = Box<Condvar>;
|
||||||
|
|
||||||
// Condition variables are implemented with a simple counter internally that is
|
// Condition variables are implemented with a simple counter internally that is
|
||||||
// likely to cause spurious wakeups. Blocking on a condition variable will first
|
// likely to cause spurious wakeups. Blocking on a condition variable will first
|
||||||
// read the value of the internal counter, unlock the given mutex, and then
|
// read the value of the internal counter, unlock the given mutex, and then
|
||||||
|
|
|
@ -8,6 +8,8 @@ pub struct Condvar {
|
||||||
inner: UnsafeCell<c::CONDITION_VARIABLE>,
|
inner: UnsafeCell<c::CONDITION_VARIABLE>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub type MovableCondvar = Box<Condvar>;
|
||||||
|
|
||||||
unsafe impl Send for Condvar {}
|
unsafe impl Send for Condvar {}
|
||||||
unsafe impl Sync for Condvar {}
|
unsafe impl Sync for Condvar {}
|
||||||
|
|
||||||
|
|
|
@ -9,14 +9,14 @@ type CondvarCheck = <mutex_imp::MovableMutex as check::CondvarCheck>::Check;
|
||||||
|
|
||||||
/// An OS-based condition variable.
|
/// An OS-based condition variable.
|
||||||
pub struct Condvar {
|
pub struct Condvar {
|
||||||
inner: Box<imp::Condvar>,
|
inner: imp::MovableCondvar,
|
||||||
check: CondvarCheck,
|
check: CondvarCheck,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Condvar {
|
impl Condvar {
|
||||||
/// Creates a new condition variable for use.
|
/// Creates a new condition variable for use.
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
let mut c = box imp::Condvar::new();
|
let mut c = imp::MovableCondvar::from(imp::Condvar::new());
|
||||||
unsafe { c.init() };
|
unsafe { c.init() };
|
||||||
Self { inner: c, check: CondvarCheck::new() }
|
Self { inner: c, check: CondvarCheck::new() }
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue