Skip to content

Commit 1ca49bf

Browse files
committed
---
yaml --- r: 10617 b: refs/heads/snap-stage3 c: 1b642bf h: refs/heads/master i: 10615: db2d6eb v: v3
1 parent 4778fe8 commit 1ca49bf

File tree

2 files changed

+31
-22
lines changed

2 files changed

+31
-22
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
refs/heads/master: 2898dcc5d97da9427ac367542382b6239d9c0bbf
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4-
refs/heads/snap-stage3: b02172971fa658f2e6d3cdb3cbf3bf663801d656
4+
refs/heads/snap-stage3: 1b642bf02f23d48c93047ae2fca9ebd7c2bdc518
55
refs/heads/try: 2898dcc5d97da9427ac367542382b6239d9c0bbf
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105

branches/snap-stage3/src/libcore/comm.rs

Lines changed: 30 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -94,27 +94,31 @@ fn listen<T: send, U>(f: fn(chan<T>) -> U) -> U {
9494
f(po.chan())
9595
}
9696

97-
resource port_ptr<T: send>(po: *rust_port) unsafe {
97+
class port_ptr<T:send> {
98+
let po: *rust_port;
99+
new(po: *rust_port) { self.po = po; }
100+
drop unsafe {
98101
task::unkillable {||
99102
// Once the port is detached it's guaranteed not to receive further
100103
// messages
101104
let yield = 0u;
102105
let yieldp = ptr::addr_of(yield);
103-
rustrt::rust_port_begin_detach(po, yieldp);
106+
rustrt::rust_port_begin_detach(self.po, yieldp);
104107
if yield != 0u {
105108
// Need to wait for the port to be detached
106109
// FIXME: If this fails then we're going to leave our port
107110
// in a bogus state. (Issue #1988)
108111
task::yield();
109112
}
110-
rustrt::rust_port_end_detach(po);
113+
rustrt::rust_port_end_detach(self.po);
111114

112115
// Drain the port so that all the still-enqueued items get dropped
113-
while rustrt::rust_port_size(po) > 0u as size_t {
114-
recv_::<T>(po);
116+
while rustrt::rust_port_size(self.po) > 0u as size_t {
117+
recv_::<T>(self.po);
115118
}
116-
rustrt::del_port(po);
119+
rustrt::del_port(self.po);
117120
}
121+
}
118122
}
119123

120124
#[doc = "
@@ -126,29 +130,34 @@ Fails if the port is detached or dead. Fails if the port
126130
is owned by a different task.
127131
"]
128132
fn as_raw_port<T: send, U>(ch: comm::chan<T>, f: fn(*rust_port) -> U) -> U {
129-
resource portref(p: *rust_port) {
130-
if !ptr::is_null(p) {
131-
rustrt::rust_port_drop(p);
132-
}
133+
134+
class portref {
135+
let p: *rust_port;
136+
new(p: *rust_port) { self.p = p; }
137+
drop {
138+
if !ptr::is_null(self.p) {
139+
rustrt::rust_port_drop(self.p);
140+
}
141+
}
133142
}
134143

135144
let p = portref(rustrt::rust_port_take(*ch));
136145

137-
if ptr::is_null(*p) {
146+
if ptr::is_null(p.p) {
138147
fail "unable to locate port for channel"
139-
} else if rustrt::get_task_id() != rustrt::rust_port_task(*p) {
148+
} else if rustrt::get_task_id() != rustrt::rust_port_task(p.p) {
140149
fail "unable to access unowned port"
141150
}
142151

143-
f(*p)
152+
f(p.p)
144153
}
145154

146155
#[doc = "
147156
Constructs a channel. The channel is bound to the port used to
148157
construct it.
149158
"]
150159
fn chan<T: send>(p: port<T>) -> chan<T> {
151-
chan_t(rustrt::get_port_id(***p))
160+
chan_t(rustrt::get_port_id((**p).po))
152161
}
153162

154163
#[doc = "
@@ -170,10 +179,10 @@ fn send<T: send>(ch: chan<T>, -data: T) {
170179
Receive from a port. If no data is available on the port then the
171180
task will block until data becomes available.
172181
"]
173-
fn recv<T: send>(p: port<T>) -> T { recv_(***p) }
182+
fn recv<T: send>(p: port<T>) -> T { recv_((**p).po) }
174183

175184
#[doc = "Returns true if there are messages available"]
176-
fn peek<T: send>(p: port<T>) -> bool { peek_(***p) }
185+
fn peek<T: send>(p: port<T>) -> bool { peek_((**p).po) }
177186

178187
#[doc(hidden)]
179188
fn recv_chan<T: send>(ch: comm::chan<T>) -> T {
@@ -196,7 +205,7 @@ fn recv_<T: send>(p: *rust_port) -> T {
196205
// Data isn't available yet, so res has not been initialized.
197206
task::yield();
198207
} else {
199-
// In the absense of compiler-generated preemption points
208+
// In the absence of compiler-generated preemption points
200209
// this is a good place to yield
201210
task::yield();
202211
}
@@ -210,7 +219,7 @@ fn peek_(p: *rust_port) -> bool unsafe {
210219
#[doc = "Receive on one of two ports"]
211220
fn select2<A: send, B: send>(p_a: port<A>, p_b: port<B>)
212221
-> either<A, B> unsafe {
213-
let ports = [***p_a, ***p_b];
222+
let ports = [(**p_a).po, (**p_b).po];
214223
let n_ports = 2 as libc::size_t;
215224
let yield = 0u, yieldp = ptr::addr_of(yield);
216225

@@ -233,9 +242,9 @@ fn select2<A: send, B: send>(p_a: port<A>, p_b: port<B>)
233242
// Now we know the port we're supposed to receive from
234243
assert resport != ptr::null();
235244

236-
if resport == ***p_a {
245+
if resport == (**p_a).po {
237246
either::left(recv(p_a))
238-
} else if resport == ***p_b {
247+
} else if resport == (**p_b).po {
239248
either::right(recv(p_b))
240249
} else {
241250
fail "unexpected result from rust_port_select";
@@ -482,4 +491,4 @@ fn test_port_detach_fail() {
482491
}
483492
}
484493
}
485-
}
494+
}

0 commit comments

Comments
 (0)