diff options
| author | Valerii Hiora <valerii.hiora@gmail.com> | 2014-05-24 08:01:23 +0300 |
|---|---|---|
| committer | Valerii Hiora <valerii.hiora@gmail.com> | 2014-05-24 08:01:23 +0300 |
| commit | 41b65d39ab5b4fae52cbcc370b464ba370bedb87 (patch) | |
| tree | ecc69ac7e75fd8690ddee152a49fcf53621fa353 /src/libstd/comm/shared.rs | |
| parent | 12e80f1a14195814080300b9ac36e267f8870430 (diff) | |
| download | rust-41b65d39ab5b4fae52cbcc370b464ba370bedb87.tar.gz rust-41b65d39ab5b4fae52cbcc370b464ba370bedb87.zip | |
Fixes problems on systems with opaque mutex
On some systems (iOS for example) mutex is represented by opaque data structure which doesn't play well with simple data copy. Therefore mutex should be initialized from magic static value and filled by OS only when it landed RC.
Diffstat (limited to 'src/libstd/comm/shared.rs')
| -rw-r--r-- | src/libstd/comm/shared.rs | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/src/libstd/comm/shared.rs b/src/libstd/comm/shared.rs index 8aef2ec80a8..3fde584a46f 100644 --- a/src/libstd/comm/shared.rs +++ b/src/libstd/comm/shared.rs @@ -66,7 +66,8 @@ pub enum Failure { } impl<T: Send> Packet<T> { - // Creation of a packet *must* be followed by a call to inherit_blocker + // Creation of a packet *must* be followed by a call to postinit_lock + // and later by inherit_blocker pub fn new() -> Packet<T> { let p = Packet { queue: mpsc::Queue::new(), @@ -78,11 +79,18 @@ impl<T: Send> Packet<T> { sender_drain: atomics::AtomicInt::new(0), select_lock: unsafe { NativeMutex::new() }, }; - // see comments in inherit_blocker about why we grab this lock - unsafe { p.select_lock.lock_noguard() } return p; } + // This function should be used after newly created Packet + // was wrapped with an Arc + // In other case mutex data will be duplicated while clonning + // and that could cause problems on platforms where it is + // represented by opaque data structure + pub fn postinit_lock(&mut self) { + unsafe { self.select_lock.lock_noguard() } + } + // This function is used at the creation of a shared packet to inherit a // previously blocked task. This is done to prevent spurious wakeups of // tasks in select(). |
