]> git.lizzy.rs Git - rust.git/commitdiff
Make it possible to have unboxed condvars on specific platforms.
authorMara Bos <m-ou.se@m-ou.se>
Wed, 30 Sep 2020 23:13:26 +0000 (01:13 +0200)
committerMara Bos <m-ou.se@m-ou.se>
Fri, 2 Oct 2020 07:47:08 +0000 (09:47 +0200)
This commit keeps all condvars boxed on all platforms, but makes it
trivial to remove the box on some platforms later.

library/std/src/sys/cloudabi/condvar.rs
library/std/src/sys/hermit/condvar.rs
library/std/src/sys/sgx/condvar.rs
library/std/src/sys/unix/condvar.rs
library/std/src/sys/unsupported/condvar.rs
library/std/src/sys/vxworks/condvar.rs
library/std/src/sys/wasm/condvar_atomics.rs
library/std/src/sys/windows/condvar.rs
library/std/src/sys_common/condvar.rs

index dabdc0c9b510af2dbfda6c7b46ded950d0a4fe49..148a684370e09688ec29aab7e5eb32fad5b97689 100644 (file)
@@ -15,6 +15,8 @@ pub struct Condvar {
     condvar: UnsafeCell<AtomicU32>,
 }
 
+pub type MovableCondvar = Box<Condvar>;
+
 unsafe impl Send for Condvar {}
 unsafe impl Sync for Condvar {}
 
index 52c8c3b17e8262571775b4a41b1ab543fbd78b39..b45e8718f088e211a6ebef0f9473054cb70a3470 100644 (file)
@@ -14,6 +14,8 @@ pub struct Condvar {
     sem2: *const c_void,
 }
 
+pub type MovableCondvar = Box<Condvar>;
+
 unsafe impl Send for Condvar {}
 unsafe impl Sync for Condvar {}
 
index ed6dbcf497147f68834e71a85bdad2165fc50f6c..dfe22e6a1b37591e7ab8d6876ff9186074bb2097 100644 (file)
@@ -7,6 +7,8 @@ pub struct Condvar {
     inner: SpinMutex<WaitVariable<()>>,
 }
 
+pub type MovableCondvar = Box<Condvar>;
+
 impl Condvar {
     pub const fn new() -> Condvar {
         Condvar { inner: SpinMutex::new(WaitVariable::new(())) }
index 9f1847943f3262e63cfd43464e2aa91d65853920..e38f91af9f0b9ba6d17543c1a216002092f3e6a6 100644 (file)
@@ -6,6 +6,8 @@ pub struct Condvar {
     inner: UnsafeCell<libc::pthread_cond_t>,
 }
 
+pub type MovableCondvar = Box<Condvar>;
+
 unsafe impl Send for Condvar {}
 unsafe impl Sync for Condvar {}
 
index a578eee8ccce2a121809f814aee7dfadea286f52..e49f21bef785a05feeb033088e4a0bddf3cfb991 100644 (file)
@@ -3,6 +3,8 @@
 
 pub struct Condvar {}
 
+pub type MovableCondvar = Box<Condvar>;
+
 impl Condvar {
     pub const fn new() -> Condvar {
         Condvar {}
index 5a77966d974688ecb1ac2ec70b604f07ca1242ff..b4724be7c7c3b38b31e65fba624978384e98e0d5 100644 (file)
@@ -6,6 +6,8 @@ pub struct Condvar {
     inner: UnsafeCell<libc::pthread_cond_t>,
 }
 
+pub type MovableCondvar = Box<Condvar>;
+
 unsafe impl Send for Condvar {}
 unsafe impl Sync for Condvar {}
 
index d86bb60507be2c0d9bd0f410bd3b8048a4d2f052..304c3bb4c58aa3b0e2d1a5af76bfb62ec1dfdd9d 100644 (file)
@@ -9,6 +9,8 @@ pub struct Condvar {
     cnt: AtomicUsize,
 }
 
+pub type MovableCondvar = Box<Condvar>;
+
 // Condition variables are implemented with a simple counter internally that is
 // 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
index 8f7f6854cc22c83d06f5179670a8d16b82c9cc68..2b2ff13c78b813667714f4540a88284f323dc467 100644 (file)
@@ -8,6 +8,8 @@ pub struct Condvar {
     inner: UnsafeCell<c::CONDITION_VARIABLE>,
 }
 
+pub type MovableCondvar = Box<Condvar>;
+
 unsafe impl Send for Condvar {}
 unsafe impl Sync for Condvar {}
 
index acd8b69e9ac556d6b885acb89be4e2d79733b376..2c02e1cd33c8165209c5b08333bdb0898882bc22 100644 (file)
@@ -9,14 +9,14 @@
 
 /// An OS-based condition variable.
 pub struct Condvar {
-    inner: Box<imp::Condvar>,
+    inner: imp::MovableCondvar,
     check: CondvarCheck,
 }
 
 impl Condvar {
     /// Creates a new condition variable for use.
     pub fn new() -> Self {
-        let mut c = box imp::Condvar::new();
+        let mut c = imp::MovableCondvar::from(imp::Condvar::new());
         unsafe { c.init() };
         Self { inner: c, check: CondvarCheck::new() }
     }