Skip to content

Commit abb6e9f

Browse files
toffalettibrson
authored andcommitted
---
yaml --- r: 95676 b: refs/heads/dist-snap c: 89c9120 h: refs/heads/master v: v3
1 parent 84d88a3 commit abb6e9f

File tree

2 files changed

+39
-37
lines changed

2 files changed

+39
-37
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ refs/heads/try: c274a6888410ce3e357e014568b43310ed787d36
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: 147ecfdd8221e4a4d4e090486829a06da1e0ca3c
9-
refs/heads/dist-snap: c372fa55560f1cdfdcb566f3027689ba88c46da5
9+
refs/heads/dist-snap: 89c91208a7e1e2a5ce77dcb2032601393d861128
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503
1212
refs/heads/try3: 9387340aab40a73e8424c48fd42f0c521a4875c0

branches/dist-snap/src/libstd/rt/mpsc_queue.rs

Lines changed: 38 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -83,24 +83,28 @@ impl<T: Send> fmt::Default for Queue<T> {
8383
}
8484
}
8585

86-
impl<T: Send> Queue<T> {
87-
pub fn new() -> Queue<T> {
88-
let mut q = Queue{state: UnsafeArc::new(State {
86+
impl<T: Send> State<T> {
87+
pub fn new() -> State<T> {
88+
let mut state = State {
8989
pad0: [0, ..64],
9090
head: AtomicPtr::new(mut_null()),
9191
pad1: [0, ..64],
9292
stub: Default::default(),
9393
pad2: [0, ..64],
9494
tail: mut_null(),
9595
pad3: [0, ..64],
96-
})};
97-
let stub = q.get_stub_unsafe();
98-
q.get_head().store(stub, Relaxed);
99-
q.set_tail(stub);
100-
q
96+
};
97+
let stub = state.get_stub_unsafe();
98+
state.head.store(stub, Relaxed);
99+
state.tail = stub;
100+
state
101101
}
102102

103-
pub fn push(&mut self, value: T) {
103+
fn get_stub_unsafe(&mut self) -> *mut Node<T> {
104+
unsafe { to_mut_unsafe_ptr(&mut self.stub) }
105+
}
106+
107+
fn push(&mut self, value: T) {
104108
unsafe {
105109
let node = cast::transmute(~Node::new(value));
106110
self.push_node(node);
@@ -110,65 +114,63 @@ impl<T: Send> Queue<T> {
110114
fn push_node(&mut self, node: *mut Node<T>) {
111115
unsafe {
112116
(*node).next.store(mut_null(), Release);
113-
let prev = self.get_head().swap(node, Relaxed);
117+
let prev = self.head.swap(node, Relaxed);
114118
(*prev).next.store(node, Release);
115119
}
116120
}
117121

118-
fn get_stub_unsafe(&mut self) -> *mut Node<T> {
119-
unsafe { to_mut_unsafe_ptr(&mut (*self.state.get()).stub) }
120-
}
121-
122-
fn get_head(&mut self) -> &mut AtomicPtr<Node<T>> {
123-
unsafe { &mut (*self.state.get()).head }
124-
}
125-
126-
fn get_tail(&mut self) -> *mut Node<T> {
127-
unsafe { (*self.state.get()).tail }
128-
}
129-
130-
fn set_tail(&mut self, tail: *mut Node<T>) {
131-
unsafe { (*self.state.get()).tail = tail }
132-
}
133-
134-
pub fn casual_pop(&mut self) -> Option<T> {
135-
self.pop()
136-
}
137-
138-
pub fn pop(&mut self) -> Option<T> {
122+
fn pop(&mut self) -> Option<T> {
139123
unsafe {
140-
let mut tail = self.get_tail();
124+
let mut tail = self.tail;
141125
let mut next = (*tail).next.load(Acquire);
142126
let stub = self.get_stub_unsafe();
143127
if tail == stub {
144128
if mut_null() == next {
145129
return None
146130
}
147-
self.set_tail(next);
131+
self.tail = next;
148132
tail = next;
149133
next = (*next).next.load(Acquire);
150134
}
151135
if next != mut_null() {
152136
let tail: ~Node<T> = cast::transmute(tail);
153-
self.set_tail(next);
137+
self.tail = next;
154138
return tail.value
155139
}
156-
let head = self.get_head().load(Relaxed);
140+
let head = self.head.load(Relaxed);
157141
if tail != head {
158142
return None
159143
}
160144
self.push_node(stub);
161145
next = (*tail).next.load(Acquire);
162146
if next != mut_null() {
163147
let tail: ~Node<T> = cast::transmute(tail);
164-
self.set_tail(next);
148+
self.tail = next;
165149
return tail.value
166150
}
167151
}
168152
None
169153
}
170154
}
171155

156+
impl<T: Send> Queue<T> {
157+
pub fn new() -> Queue<T> {
158+
Queue{state: UnsafeArc::new(State::new())}
159+
}
160+
161+
pub fn push(&mut self, value: T) {
162+
unsafe { (*self.state.get()).push(value) }
163+
}
164+
165+
pub fn casual_pop(&mut self) -> Option<T> {
166+
unsafe { (*self.state.get()).pop() }
167+
}
168+
169+
pub fn pop(&mut self) -> Option<T> {
170+
unsafe{ (*self.state.get()).pop() }
171+
}
172+
}
173+
172174
#[cfg(test)]
173175
mod tests {
174176
use prelude::*;

0 commit comments

Comments
 (0)