Skip to content

Commit 3eb15b8

Browse files
committed
Merge pull request #4190 from brson/oldcomm
Work on removing comm
2 parents c35a858 + e6d1b02 commit 3eb15b8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

83 files changed

+746
-962
lines changed

doc/tutorial-tasks.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,7 @@ and child both need to exchange messages with each other. The
461461
function `std::comm::DuplexStream()` supports this pattern. We'll
462462
look briefly at how to use it.
463463

464-
To see how `spawn_conversation()` works, we will create a child task
464+
To see how `DuplexStream()` works, we will create a child task
465465
that repeatedly receives a `uint` message, converts it to a string, and sends
466466
the string in response. The child terminates when it receives `0`.
467467
Here is the function that implements the child task:

src/libcore/core.rc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ pub mod send_map;
139139

140140
/* Tasks and communication */
141141

142-
pub mod comm;
142+
pub mod oldcomm;
143143
#[path = "task/mod.rs"]
144144
pub mod task;
145145
pub mod pipes;

src/libcore/comm.rs renamed to src/libcore/oldcomm.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ fn PortPtr<T: Owned>(po: *rust_port) -> PortPtr<T> {
144144
* Fails if the port is detached or dead. Fails if the port
145145
* is owned by a different task.
146146
*/
147-
fn as_raw_port<T: Owned, U>(ch: comm::Chan<T>, f: fn(*rust_port) -> U) -> U {
147+
fn as_raw_port<T: Owned, U>(ch: Chan<T>, f: fn(*rust_port) -> U) -> U {
148148

149149
struct PortRef {
150150
p: *rust_port,
@@ -205,11 +205,11 @@ pub fn recv<T: Owned>(p: Port<T>) -> T { recv_((**p).po) }
205205
pub fn peek<T: Owned>(p: Port<T>) -> bool { peek_((**p).po) }
206206

207207
#[doc(hidden)]
208-
pub fn recv_chan<T: Owned>(ch: comm::Chan<T>) -> T {
208+
pub fn recv_chan<T: Owned>(ch: Chan<T>) -> T {
209209
as_raw_port(ch, |x|recv_(x))
210210
}
211211

212-
fn peek_chan<T: Owned>(ch: comm::Chan<T>) -> bool {
212+
fn peek_chan<T: Owned>(ch: Chan<T>) -> bool {
213213
as_raw_port(ch, |x|peek_(x))
214214
}
215215

src/libcore/os.rs

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -133,36 +133,36 @@ mod global_env {
133133
}
134134

135135
enum Msg {
136-
MsgGetEnv(~str, comm::Chan<Option<~str>>),
137-
MsgSetEnv(~str, ~str, comm::Chan<()>),
138-
MsgEnv(comm::Chan<~[(~str,~str)]>)
136+
MsgGetEnv(~str, oldcomm::Chan<Option<~str>>),
137+
MsgSetEnv(~str, ~str, oldcomm::Chan<()>),
138+
MsgEnv(oldcomm::Chan<~[(~str,~str)]>)
139139
}
140140

141141
pub fn getenv(n: &str) -> Option<~str> {
142142
let env_ch = get_global_env_chan();
143-
let po = comm::Port();
144-
comm::send(env_ch, MsgGetEnv(str::from_slice(n),
145-
comm::Chan(&po)));
146-
comm::recv(po)
143+
let po = oldcomm::Port();
144+
oldcomm::send(env_ch, MsgGetEnv(str::from_slice(n),
145+
oldcomm::Chan(&po)));
146+
oldcomm::recv(po)
147147
}
148148

149149
pub fn setenv(n: &str, v: &str) {
150150
let env_ch = get_global_env_chan();
151-
let po = comm::Port();
152-
comm::send(env_ch, MsgSetEnv(str::from_slice(n),
151+
let po = oldcomm::Port();
152+
oldcomm::send(env_ch, MsgSetEnv(str::from_slice(n),
153153
str::from_slice(v),
154-
comm::Chan(&po)));
155-
comm::recv(po)
154+
oldcomm::Chan(&po)));
155+
oldcomm::recv(po)
156156
}
157157

158158
pub fn env() -> ~[(~str,~str)] {
159159
let env_ch = get_global_env_chan();
160-
let po = comm::Port();
161-
comm::send(env_ch, MsgEnv(comm::Chan(&po)));
162-
comm::recv(po)
160+
let po = oldcomm::Port();
161+
oldcomm::send(env_ch, MsgEnv(oldcomm::Chan(&po)));
162+
oldcomm::recv(po)
163163
}
164164

165-
fn get_global_env_chan() -> comm::Chan<Msg> {
165+
fn get_global_env_chan() -> oldcomm::Chan<Msg> {
166166
let global_ptr = rustrt::rust_global_env_chan_ptr();
167167
unsafe {
168168
private::chan_from_global_ptr(global_ptr, || {
@@ -173,19 +173,19 @@ mod global_env {
173173
}
174174
}
175175

176-
fn global_env_task(msg_po: comm::Port<Msg>) {
176+
fn global_env_task(msg_po: oldcomm::Port<Msg>) {
177177
unsafe {
178178
do private::weaken_task |weak_po| {
179179
loop {
180-
match comm::select2(msg_po, weak_po) {
180+
match oldcomm::select2(msg_po, weak_po) {
181181
either::Left(MsgGetEnv(ref n, resp_ch)) => {
182-
comm::send(resp_ch, impl_::getenv(*n))
182+
oldcomm::send(resp_ch, impl_::getenv(*n))
183183
}
184184
either::Left(MsgSetEnv(ref n, ref v, resp_ch)) => {
185-
comm::send(resp_ch, impl_::setenv(*n, *v))
185+
oldcomm::send(resp_ch, impl_::setenv(*n, *v))
186186
}
187187
either::Left(MsgEnv(resp_ch)) => {
188-
comm::send(resp_ch, impl_::env())
188+
oldcomm::send(resp_ch, impl_::env())
189189
}
190190
either::Right(_) => break
191191
}

src/libcore/private.rs

Lines changed: 45 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ fn compare_and_swap(address: &mut int, oldval: int, newval: int) -> bool {
5555
pub unsafe fn chan_from_global_ptr<T: Owned>(
5656
global: GlobalPtr,
5757
task_fn: fn() -> task::TaskBuilder,
58-
f: fn~(comm::Port<T>)
59-
) -> comm::Chan<T> {
58+
f: fn~(oldcomm::Port<T>)
59+
) -> oldcomm::Chan<T> {
6060

6161
enum Msg {
6262
Proceed,
@@ -70,23 +70,29 @@ pub unsafe fn chan_from_global_ptr<T: Owned>(
7070
log(debug,~"is probably zero...");
7171
// There's no global channel. We must make it
7272
73-
let (setup_po, setup_ch) = do task_fn().spawn_conversation
74-
|move f, setup_po, setup_ch| {
75-
let po = comm::Port::<T>();
76-
let ch = comm::Chan(&po);
77-
comm::send(setup_ch, ch);
73+
let (setup1_po, setup1_ch) = pipes::stream();
74+
let (setup2_po, setup2_ch) = pipes::stream();
75+
76+
// XXX: Ugly type inference hints
77+
let setup1_po: pipes::Port<oldcomm::Chan<T>> = setup1_po;
78+
let setup2_po: pipes::Port<Msg> = setup2_po;
79+
80+
do task_fn().spawn |move f, move setup1_ch, move setup2_po| {
81+
let po = oldcomm::Port::<T>();
82+
let ch = oldcomm::Chan(&po);
83+
setup1_ch.send(ch);
7884
7985
// Wait to hear if we are the official instance of
8086
// this global task
81-
match comm::recv::<Msg>(setup_po) {
87+
match setup2_po.recv() {
8288
Proceed => f(move po),
8389
Abort => ()
8490
}
8591
};
8692
8793
log(debug,~"before setup recv..");
8894
// This is the proposed global channel
89-
let ch = comm::recv(setup_po);
95+
let ch = setup1_po.recv();
9096
// 0 is our sentinal value. It is not a valid channel
9197
assert *ch != 0;
9298
@@ -99,11 +105,11 @@ pub unsafe fn chan_from_global_ptr<T: Owned>(
99105

100106
if swapped {
101107
// Success!
102-
comm::send(setup_ch, Proceed);
108+
setup2_ch.send(Proceed);
103109
ch
104110
} else {
105111
// Somebody else got in before we did
106-
comm::send(setup_ch, Abort);
112+
setup2_ch.send(Abort);
107113
cast::reinterpret_cast(&*global)
108114
}
109115
} else {
@@ -124,29 +130,29 @@ pub fn test_from_global_chan1() {
124130
// Create the global channel, attached to a new task
125131
let ch = unsafe {
126132
do chan_from_global_ptr(globchanp, task::task) |po| {
127-
let ch = comm::recv(po);
128-
comm::send(ch, true);
129-
let ch = comm::recv(po);
130-
comm::send(ch, true);
133+
let ch = oldcomm::recv(po);
134+
oldcomm::send(ch, true);
135+
let ch = oldcomm::recv(po);
136+
oldcomm::send(ch, true);
131137
}
132138
};
133139
// Talk to it
134-
let po = comm::Port();
135-
comm::send(ch, comm::Chan(&po));
136-
assert comm::recv(po) == true;
140+
let po = oldcomm::Port();
141+
oldcomm::send(ch, oldcomm::Chan(&po));
142+
assert oldcomm::recv(po) == true;
137143

138144
// This one just reuses the previous channel
139145
let ch = unsafe {
140146
do chan_from_global_ptr(globchanp, task::task) |po| {
141-
let ch = comm::recv(po);
142-
comm::send(ch, false);
147+
let ch = oldcomm::recv(po);
148+
oldcomm::send(ch, false);
143149
}
144150
};
145151

146152
// Talk to the original global task
147-
let po = comm::Port();
148-
comm::send(ch, comm::Chan(&po));
149-
assert comm::recv(po) == true;
153+
let po = oldcomm::Port();
154+
oldcomm::send(ch, oldcomm::Chan(&po));
155+
assert oldcomm::recv(po) == true;
150156
}
151157

152158
#[test]
@@ -157,8 +163,8 @@ pub fn test_from_global_chan2() {
157163
let globchan = 0;
158164
let globchanp = ptr::addr_of(&globchan);
159165

160-
let resultpo = comm::Port();
161-
let resultch = comm::Chan(&resultpo);
166+
let resultpo = oldcomm::Port();
167+
let resultch = oldcomm::Chan(&resultpo);
162168

163169
// Spawn a bunch of tasks that all want to compete to
164170
// create the global channel
@@ -169,23 +175,23 @@ pub fn test_from_global_chan2() {
169175
globchanp, task::task) |po| {
170176

171177
for uint::range(0, 10) |_j| {
172-
let ch = comm::recv(po);
173-
comm::send(ch, {i});
178+
let ch = oldcomm::recv(po);
179+
oldcomm::send(ch, {i});
174180
}
175181
}
176182
};
177-
let po = comm::Port();
178-
comm::send(ch, comm::Chan(&po));
183+
let po = oldcomm::Port();
184+
oldcomm::send(ch, oldcomm::Chan(&po));
179185
// We are The winner if our version of the
180186
// task was installed
181-
let winner = comm::recv(po);
182-
comm::send(resultch, winner == i);
187+
let winner = oldcomm::recv(po);
188+
oldcomm::send(resultch, winner == i);
183189
}
184190
}
185191
// There should be only one winner
186192
let mut winners = 0u;
187193
for uint::range(0u, 10u) |_i| {
188-
let res = comm::recv(resultpo);
194+
let res = oldcomm::recv(resultpo);
189195
if res { winners += 1u };
190196
}
191197
assert winners == 1u;
@@ -211,23 +217,23 @@ pub fn test_from_global_chan2() {
211217
* * Weak tasks must not be supervised. A supervised task keeps
212218
* a reference to its parent, so the parent will not die.
213219
*/
214-
pub unsafe fn weaken_task(f: fn(comm::Port<()>)) {
215-
let po = comm::Port();
216-
let ch = comm::Chan(&po);
220+
pub unsafe fn weaken_task(f: fn(oldcomm::Port<()>)) {
221+
let po = oldcomm::Port();
222+
let ch = oldcomm::Chan(&po);
217223
unsafe {
218224
rustrt::rust_task_weaken(cast::reinterpret_cast(&ch));
219225
}
220226
let _unweaken = Unweaken(ch);
221227
f(po);
222228

223229
struct Unweaken {
224-
ch: comm::Chan<()>,
230+
ch: oldcomm::Chan<()>,
225231
drop unsafe {
226232
rustrt::rust_task_unweaken(cast::reinterpret_cast(&self.ch));
227233
}
228234
}
229235

230-
fn Unweaken(ch: comm::Chan<()>) -> Unweaken {
236+
fn Unweaken(ch: oldcomm::Chan<()>) -> Unweaken {
231237
Unweaken {
232238
ch: ch
233239
}
@@ -249,7 +255,7 @@ pub fn test_weaken_task_wait() {
249255
do task::spawn_unlinked {
250256
unsafe {
251257
do weaken_task |po| {
252-
comm::recv(po);
258+
oldcomm::recv(po);
253259
}
254260
}
255261
}
@@ -269,7 +275,7 @@ pub fn test_weaken_task_stress() {
269275
unsafe {
270276
do weaken_task |po| {
271277
// Wait for it to tell us to die
272-
comm::recv(po);
278+
oldcomm::recv(po);
273279
}
274280
}
275281
}

src/libcore/run.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -307,22 +307,22 @@ pub fn program_output(prog: &str, args: &[~str]) ->
307307
// in parallel so we don't deadlock while blocking on one
308308
// or the other. FIXME (#2625): Surely there's a much more
309309
// clever way to do this.
310-
let p = comm::Port();
311-
let ch = comm::Chan(&p);
310+
let p = oldcomm::Port();
311+
let ch = oldcomm::Chan(&p);
312312
do task::spawn_sched(task::SingleThreaded) {
313313
let errput = readclose(pipe_err.in);
314-
comm::send(ch, (2, move errput));
314+
oldcomm::send(ch, (2, move errput));
315315
};
316316
do task::spawn_sched(task::SingleThreaded) {
317317
let output = readclose(pipe_out.in);
318-
comm::send(ch, (1, move output));
318+
oldcomm::send(ch, (1, move output));
319319
};
320320
let status = run::waitpid(pid);
321321
let mut errs = ~"";
322322
let mut outs = ~"";
323323
let mut count = 2;
324324
while count > 0 {
325-
let stream = comm::recv(p);
325+
let stream = oldcomm::recv(p);
326326
match stream {
327327
(1, copy s) => {
328328
outs = move s;

0 commit comments

Comments
 (0)