Skip to content

Commit d6b3f1f

Browse files
committed
sync: Move the concurrent queue to using &self
This commit also lifts it up a level in the module hierarchy in the soon-to-come reorganization of libsync.
1 parent dd64bd8 commit d6b3f1f

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

src/etc/licenseck.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
"libstd/sync/mpsc_queue.rs", # BSD
4242
"libstd/sync/spsc_queue.rs", # BSD
4343
"libstd/sync/mpmc_bounded_queue.rs", # BSD
44-
"libsync/sync/mpsc_intrusive.rs", # BSD
44+
"libsync/mpsc_intrusive.rs", # BSD
4545
]
4646

4747
def check_license(name, contents):

src/libsync/sync/mpsc_intrusive.rs renamed to src/libsync/mpsc_intrusive.rs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535

3636
use std::cast;
3737
use std::sync::atomics;
38+
use std::ty::Unsafe;
3839

3940
// NB: all links are done as AtomicUint instead of AtomicPtr to allow for static
4041
// initialization.
@@ -50,22 +51,22 @@ pub struct DummyNode {
5051

5152
pub struct Queue<T> {
5253
head: atomics::AtomicUint,
53-
tail: *mut Node<T>,
54+
tail: Unsafe<*mut Node<T>>,
5455
stub: DummyNode,
5556
}
5657

5758
impl<T: Send> Queue<T> {
5859
pub fn new() -> Queue<T> {
5960
Queue {
6061
head: atomics::AtomicUint::new(0),
61-
tail: 0 as *mut Node<T>,
62+
tail: Unsafe::new(0 as *mut Node<T>),
6263
stub: DummyNode {
6364
next: atomics::AtomicUint::new(0),
6465
},
6566
}
6667
}
6768

68-
pub unsafe fn push(&mut self, node: *mut Node<T>) {
69+
pub unsafe fn push(&self, node: *mut Node<T>) {
6970
(*node).next.store(0, atomics::Release);
7071
let prev = self.head.swap(node as uint, atomics::AcqRel);
7172

@@ -93,8 +94,8 @@ impl<T: Send> Queue<T> {
9394
/// Right now consumers of this queue must be ready for this fact. Just
9495
/// because `pop` returns `None` does not mean that there is not data
9596
/// on the queue.
96-
pub unsafe fn pop(&mut self) -> Option<*mut Node<T>> {
97-
let tail = self.tail;
97+
pub unsafe fn pop(&self) -> Option<*mut Node<T>> {
98+
let tail = *self.tail.get();
9899
let mut tail = if !tail.is_null() {tail} else {
99100
cast::transmute(&self.stub)
100101
};
@@ -103,12 +104,12 @@ impl<T: Send> Queue<T> {
103104
if next.is_null() {
104105
return None;
105106
}
106-
self.tail = next;
107+
*self.tail.get() = next;
107108
tail = next;
108109
next = (*next).next(atomics::Relaxed);
109110
}
110111
if !next.is_null() {
111-
self.tail = next;
112+
*self.tail.get() = next;
112113
return Some(tail);
113114
}
114115
let head = self.head.load(atomics::Acquire) as *mut Node<T>;
@@ -119,7 +120,7 @@ impl<T: Send> Queue<T> {
119120
self.push(stub);
120121
next = (*tail).next(atomics::Relaxed);
121122
if !next.is_null() {
122-
self.tail = next;
123+
*self.tail.get() = next;
123124
return Some(tail);
124125
}
125126
return None
@@ -133,7 +134,7 @@ impl<T: Send> Node<T> {
133134
next: atomics::AtomicUint::new(0),
134135
}
135136
}
136-
pub unsafe fn next(&mut self, ord: atomics::Ordering) -> *mut Node<T> {
137+
pub unsafe fn next(&self, ord: atomics::Ordering) -> *mut Node<T> {
137138
cast::transmute::<uint, *mut Node<T>>(self.next.load(ord))
138139
}
139140
}

0 commit comments

Comments
 (0)