Skip to content

Commit b181f5a

Browse files
committed
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.
1 parent dc81cbd commit b181f5a

File tree

9 files changed

+18
-2
lines changed

9 files changed

+18
-2
lines changed

library/std/src/sys/cloudabi/condvar.rs

+2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ pub struct Condvar {
1515
condvar: UnsafeCell<AtomicU32>,
1616
}
1717

18+
pub type MovableCondvar = Box<Condvar>;
19+
1820
unsafe impl Send for Condvar {}
1921
unsafe impl Sync for Condvar {}
2022

library/std/src/sys/hermit/condvar.rs

+2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ pub struct Condvar {
1414
sem2: *const c_void,
1515
}
1616

17+
pub type MovableCondvar = Box<Condvar>;
18+
1719
unsafe impl Send for Condvar {}
1820
unsafe impl Sync for Condvar {}
1921

library/std/src/sys/sgx/condvar.rs

+2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ pub struct Condvar {
77
inner: SpinMutex<WaitVariable<()>>,
88
}
99

10+
pub type MovableCondvar = Box<Condvar>;
11+
1012
impl Condvar {
1113
pub const fn new() -> Condvar {
1214
Condvar { inner: SpinMutex::new(WaitVariable::new(())) }

library/std/src/sys/unix/condvar.rs

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ pub struct Condvar {
66
inner: UnsafeCell<libc::pthread_cond_t>,
77
}
88

9+
pub type MovableCondvar = Box<Condvar>;
10+
911
unsafe impl Send for Condvar {}
1012
unsafe impl Sync for Condvar {}
1113

library/std/src/sys/unsupported/condvar.rs

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ use crate::time::Duration;
33

44
pub struct Condvar {}
55

6+
pub type MovableCondvar = Box<Condvar>;
7+
68
impl Condvar {
79
pub const fn new() -> Condvar {
810
Condvar {}

library/std/src/sys/vxworks/condvar.rs

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ pub struct Condvar {
66
inner: UnsafeCell<libc::pthread_cond_t>,
77
}
88

9+
pub type MovableCondvar = Box<Condvar>;
10+
911
unsafe impl Send for Condvar {}
1012
unsafe impl Sync for Condvar {}
1113

library/std/src/sys/wasm/condvar_atomics.rs

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ pub struct Condvar {
99
cnt: AtomicUsize,
1010
}
1111

12+
pub type MovableCondvar = Box<Condvar>;
13+
1214
// Condition variables are implemented with a simple counter internally that is
1315
// likely to cause spurious wakeups. Blocking on a condition variable will first
1416
// read the value of the internal counter, unlock the given mutex, and then

library/std/src/sys/windows/condvar.rs

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ pub struct Condvar {
88
inner: UnsafeCell<c::CONDITION_VARIABLE>,
99
}
1010

11+
pub type MovableCondvar = Box<Condvar>;
12+
1113
unsafe impl Send for Condvar {}
1214
unsafe impl Sync for Condvar {}
1315

library/std/src/sys_common/condvar.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ type CondvarCheck = <mutex_imp::MovableMutex as check::CondvarCheck>::Check;
99

1010
/// An OS-based condition variable.
1111
pub struct Condvar {
12-
inner: Box<imp::Condvar>,
12+
inner: imp::MovableCondvar,
1313
check: CondvarCheck,
1414
}
1515

1616
impl Condvar {
1717
/// Creates a new condition variable for use.
1818
pub fn new() -> Self {
19-
let mut c = box imp::Condvar::new();
19+
let mut c = imp::MovableCondvar::from(imp::Condvar::new());
2020
unsafe { c.init() };
2121
Self { inner: c, check: CondvarCheck::new() }
2222
}

0 commit comments

Comments
 (0)