diff options
| author | Niko Matsakis <niko@alum.mit.edu> | 2014-01-22 14:03:02 -0500 |
|---|---|---|
| committer | Niko Matsakis <niko@alum.mit.edu> | 2014-01-31 21:18:48 -0500 |
| commit | 81d8328517a6a2830438aaec1d7e747156b13be0 (patch) | |
| tree | 5f3337bdc79406fd7da088d146ad1f64a56ff83b /src/libstd/comm | |
| parent | 83f0f6ef6cb44d9fbba24372f223561a75a50c18 (diff) | |
| download | rust-81d8328517a6a2830438aaec1d7e747156b13be0.tar.gz rust-81d8328517a6a2830438aaec1d7e747156b13be0.zip | |
Introduce marker types for indicating variance and for opting out
of builtin bounds. Fixes #10834. Fixes #11385. cc #5922.
Diffstat (limited to 'src/libstd/comm')
| -rw-r--r-- | src/libstd/comm/mod.rs | 24 | ||||
| -rw-r--r-- | src/libstd/comm/select.rs | 7 |
2 files changed, 22 insertions, 9 deletions
diff --git a/src/libstd/comm/mod.rs b/src/libstd/comm/mod.rs index 7f8f74f1b64..7b1a6055542 100644 --- a/src/libstd/comm/mod.rs +++ b/src/libstd/comm/mod.rs @@ -230,6 +230,7 @@ use clone::Clone; use container::Container; use int; use iter::Iterator; +use kinds::marker; use kinds::Send; use ops::Drop; use option::{Option, Some, None}; @@ -297,9 +298,11 @@ impl<T: Send> Consumer<T>{ /// The receiving-half of Rust's channel type. This half can only be owned by /// one task -#[no_freeze] // can't share ports in an arc pub struct Port<T> { priv queue: Consumer<T>, + + // can't share in an arc + priv marker: marker::NoFreeze, } /// An iterator over messages received on a port, this iterator will block @@ -311,17 +314,22 @@ pub struct Messages<'a, T> { /// The sending-half of Rust's channel type. This half can only be owned by one /// task -#[no_freeze] // can't share chans in an arc pub struct Chan<T> { priv queue: spsc::Producer<T, Packet>, + + // can't share in an arc + priv marker: marker::NoFreeze, } /// The sending-half of Rust's channel type. This half can be shared among many /// tasks by creating copies of itself through the `clone` method. -#[no_freeze] // technically this implementation is shareable, but it shouldn't - // be required to be shareable in an arc pub struct SharedChan<T> { priv queue: mpsc::Producer<T, Packet>, + + // can't share in an arc -- technically this implementation is + // shareable, but it shouldn't be required to be shareable in an + // arc + priv marker: marker::NoFreeze, } /// This enumeration is the list of the possible reasons that try_recv could not @@ -545,7 +553,8 @@ impl<T: Send> Chan<T> { // maximum buffer size let (c, p) = spsc::queue(128, Packet::new()); let c = SPSC(c); - (Port { queue: c }, Chan { queue: p }) + (Port { queue: c, marker: marker::NoFreeze }, + Chan { queue: p, marker: marker::NoFreeze }) } /// Sends a value along this channel to be received by the corresponding @@ -640,7 +649,8 @@ impl<T: Send> SharedChan<T> { pub fn new() -> (Port<T>, SharedChan<T>) { let (c, p) = mpsc::queue(Packet::new()); let c = MPSC(c); - (Port { queue: c }, SharedChan { queue: p }) + (Port { queue: c, marker: marker::NoFreeze }, + SharedChan { queue: p, marker: marker::NoFreeze }) } /// Equivalent method to `send` on the `Chan` type (using the same @@ -706,7 +716,7 @@ impl<T: Send> SharedChan<T> { impl<T: Send> Clone for SharedChan<T> { fn clone(&self) -> SharedChan<T> { unsafe { (*self.queue.packet()).channels.fetch_add(1, SeqCst); } - SharedChan { queue: self.queue.clone() } + SharedChan { queue: self.queue.clone(), marker: marker::NoFreeze } } } diff --git a/src/libstd/comm/select.rs b/src/libstd/comm/select.rs index a0db70117aa..a369ecba86b 100644 --- a/src/libstd/comm/select.rs +++ b/src/libstd/comm/select.rs @@ -47,6 +47,7 @@ use cast; use comm; use iter::Iterator; +use kinds::marker; use kinds::Send; use ops::Drop; use option::{Some, None, Option}; @@ -77,12 +78,12 @@ macro_rules! select { /// The "port set" of the select interface. This structure is used to manage a /// set of ports which are being selected over. -#[no_freeze] -#[no_send] pub struct Select { priv head: *mut Packet, priv tail: *mut Packet, priv next_id: uint, + priv marker1: marker::NoSend, + priv marker2: marker::NoFreeze, } /// A handle to a port which is currently a member of a `Select` set of ports. @@ -108,6 +109,8 @@ impl Select { head: 0 as *mut Packet, tail: 0 as *mut Packet, next_id: 1, + marker1: marker::NoSend, + marker2: marker::NoFreeze, } } |
