Skip to content

Commit fdf935a

Browse files
committed
std,green: Mark some queue types as NoShare
1 parent 54f6eac commit fdf935a

File tree

5 files changed

+26
-16
lines changed

5 files changed

+26
-16
lines changed

src/libgreen/message_queue.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
use alloc::arc::Arc;
1212
use mpsc = std::sync::mpsc_queue;
13+
use std::kinds::marker;
1314

1415
pub enum PopResult<T> {
1516
Inconsistent,
@@ -19,15 +20,18 @@ pub enum PopResult<T> {
1920

2021
pub fn queue<T: Send>() -> (Consumer<T>, Producer<T>) {
2122
let a = Arc::new(mpsc::Queue::new());
22-
(Consumer { inner: a.clone() }, Producer { inner: a })
23+
(Consumer { inner: a.clone(), noshare: marker::NoShare },
24+
Producer { inner: a, noshare: marker::NoShare })
2325
}
2426

2527
pub struct Producer<T> {
2628
inner: Arc<mpsc::Queue<T>>,
29+
noshare: marker::NoShare,
2730
}
2831

2932
pub struct Consumer<T> {
3033
inner: Arc<mpsc::Queue<T>>,
34+
noshare: marker::NoShare,
3135
}
3236

3337
impl<T: Send> Consumer<T> {
@@ -56,6 +60,6 @@ impl<T: Send> Producer<T> {
5660

5761
impl<T: Send> Clone for Producer<T> {
5862
fn clone(&self) -> Producer<T> {
59-
Producer { inner: self.inner.clone() }
63+
Producer { inner: self.inner.clone(), noshare: marker::NoShare }
6064
}
6165
}

src/libnative/io/net.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ impl TcpStream {
326326
fn lock_nonblocking<'a>(&'a self) -> Guard<'a> {
327327
let ret = Guard {
328328
fd: self.fd(),
329-
guard: unsafe { (*self.inner.get()).lock.lock() },
329+
guard: unsafe { self.inner.lock.lock() },
330330
};
331331
assert!(util::set_nonblocking(self.fd(), true).is_ok());
332332
ret
@@ -597,7 +597,7 @@ impl UdpSocket {
597597
fn lock_nonblocking<'a>(&'a self) -> Guard<'a> {
598598
let ret = Guard {
599599
fd: self.fd(),
600-
guard: unsafe { (*self.inner.get()).lock.lock() },
600+
guard: unsafe { self.inner.lock.lock() },
601601
};
602602
assert!(util::set_nonblocking(self.fd(), true).is_ok());
603603
ret

src/libnative/io/pipe_unix.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ impl UnixStream {
138138
fn lock_nonblocking<'a>(&'a self) -> net::Guard<'a> {
139139
let ret = net::Guard {
140140
fd: self.fd(),
141-
guard: self.inner.lock.lock(),
141+
guard: unsafe { self.inner.lock.lock() },
142142
};
143143
assert!(util::set_nonblocking(self.fd(), true).is_ok());
144144
ret

src/libnative/io/pipe_win32.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -320,11 +320,11 @@ impl UnixStream {
320320
fn handle(&self) -> libc::HANDLE { self.inner.handle }
321321

322322
fn read_closed(&self) -> bool {
323-
unsafe { (*self.inner.get()).read_closed.load(atomics::SeqCst) }
323+
self.inner.read_closed.load(atomics::SeqCst)
324324
}
325325

326326
fn write_closed(&self) -> bool {
327-
unsafe { (*self.inner.get()).write_closed.load(atomics::SeqCst) }
327+
self.inner.write_closed.load(atomics::SeqCst)
328328
}
329329

330330
fn cancel_io(&self) -> IoResult<()> {
@@ -353,7 +353,7 @@ impl rtio::RtioPipe for UnixStream {
353353
// acquire the lock.
354354
//
355355
// See comments in close_read() about why this lock is necessary.
356-
let guard = unsafe { (*self.inner.get()).lock.lock() };
356+
let guard = unsafe { self.inner.lock.lock() };
357357
if self.read_closed() {
358358
return Err(io::standard_error(io::EndOfFile))
359359
}
@@ -429,7 +429,7 @@ impl rtio::RtioPipe for UnixStream {
429429
// going after we woke up.
430430
//
431431
// See comments in close_read() about why this lock is necessary.
432-
let guard = unsafe { (*self.inner.get()).lock.lock() };
432+
let guard = unsafe { self.inner.lock.lock() };
433433
if self.write_closed() {
434434
return Err(io::standard_error(io::BrokenPipe))
435435
}
@@ -514,15 +514,15 @@ impl rtio::RtioPipe for UnixStream {
514514
// close_read() between steps 1 and 2. By atomically executing steps 1
515515
// and 2 with a lock with respect to close_read(), we're guaranteed that
516516
// no thread will erroneously sit in a read forever.
517-
let _guard = unsafe { (*self.inner.get()).lock.lock() };
518-
unsafe { (*self.inner.get()).read_closed.store(true, atomics::SeqCst) }
517+
let _guard = unsafe { self.inner.lock.lock() };
518+
self.inner.read_closed.store(true, atomics::SeqCst);
519519
self.cancel_io()
520520
}
521521

522522
fn close_write(&mut self) -> IoResult<()> {
523523
// see comments in close_read() for why this lock is necessary
524-
let _guard = unsafe { (*self.inner.get()).lock.lock() };
525-
unsafe { (*self.inner.get()).write_closed.store(true, atomics::SeqCst) }
524+
let _guard = unsafe { self.inner.lock.lock() };
525+
self.inner.write_closed.store(true, atomics::SeqCst);
526526
self.cancel_io()
527527
}
528528

src/libstd/sync/deque.rs

+9-3
Original file line numberDiff line numberDiff line change
@@ -53,16 +53,17 @@ use alloc::arc::Arc;
5353
use clone::Clone;
5454
use iter::{range, Iterator};
5555
use kinds::Send;
56+
use kinds::marker;
5657
use mem::{forget, min_align_of, size_of, transmute};
5758
use ops::Drop;
5859
use option::{Option, Some, None};
5960
use owned::Box;
6061
use ptr::RawPtr;
6162
use ptr;
63+
use rt::heap::{allocate, deallocate};
6264
use slice::ImmutableVector;
6365
use sync::atomics::{AtomicInt, AtomicPtr, SeqCst};
6466
use unstable::sync::Exclusive;
65-
use rt::heap::{allocate, deallocate};
6667
use vec::Vec;
6768

6869
// Once the queue is less than 1/K full, then it will be downsized. Note that
@@ -89,13 +90,15 @@ struct Deque<T> {
8990
/// There may only be one worker per deque.
9091
pub struct Worker<T> {
9192
deque: Arc<Deque<T>>,
93+
noshare: marker::NoShare,
9294
}
9395

9496
/// The stealing half of the work-stealing deque. Stealers have access to the
9597
/// opposite end of the deque from the worker, and they only have access to the
9698
/// `steal` method.
9799
pub struct Stealer<T> {
98100
deque: Arc<Deque<T>>,
101+
noshare: marker::NoShare,
99102
}
100103

101104
/// When stealing some data, this is an enumeration of the possible outcomes.
@@ -153,7 +156,8 @@ impl<T: Send> BufferPool<T> {
153156
pub fn deque(&self) -> (Worker<T>, Stealer<T>) {
154157
let a = Arc::new(Deque::new(self.clone()));
155158
let b = a.clone();
156-
(Worker { deque: a }, Stealer { deque: b })
159+
(Worker { deque: a, noshare: marker::NoShare },
160+
Stealer { deque: b, noshare: marker::NoShare })
157161
}
158162

159163
fn alloc(&self, bits: int) -> Box<Buffer<T>> {
@@ -219,7 +223,9 @@ impl<T: Send> Stealer<T> {
219223
}
220224

221225
impl<T: Send> Clone for Stealer<T> {
222-
fn clone(&self) -> Stealer<T> { Stealer { deque: self.deque.clone() } }
226+
fn clone(&self) -> Stealer<T> {
227+
Stealer { deque: self.deque.clone(), noshare: marker::NoShare }
228+
}
223229
}
224230

225231
// Almost all of this code can be found directly in the paper so I'm not

0 commit comments

Comments
 (0)