Skip to content

Commit 74c5791

Browse files
committed
---
yaml --- r: 13043 b: refs/heads/master c: 78b664f h: refs/heads/master i: 13041: 41cfd97 13039: 2b351b3 v: v3
1 parent abc90fa commit 74c5791

File tree

2 files changed

+23
-24
lines changed

2 files changed

+23
-24
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: 937ef188e3539b4e83af1a0e52b41a2371e8bfd8
2+
refs/heads/master: 78b664fead9530a18f658cf0b7ec6a75adb33134
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 4a81779abd786ff22d71434c6d9a5917ea4cdfff
55
refs/heads/try: 2898dcc5d97da9427ac367542382b6239d9c0bbf

trunk/src/libstd/uv_iotask.rs

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export exit;
1414

1515
import libc::c_void;
1616
import ptr::addr_of;
17-
import comm::{port, chan, methods};
17+
import comm::{port, chan, methods, listen};
1818
import ll = uv_ll;
1919

2020
#[doc = "
@@ -31,9 +31,6 @@ fn spawn_iotask(-builder: task::builder) -> iotask {
3131

3232
import task::{set_opts, get_opts, single_threaded, run};
3333

34-
let iotask_po = port::<iotask>();
35-
let iotask_ch = iotask_po.chan();
36-
3734
set_opts(builder, {
3835
sched: some({
3936
mode: single_threaded,
@@ -42,13 +39,16 @@ fn spawn_iotask(-builder: task::builder) -> iotask {
4239
with get_opts(builder)
4340
});
4441

45-
run(builder) {||
46-
#debug("entering libuv task");
47-
run_loop(iotask_ch);
48-
#debug("libuv task exiting");
49-
};
42+
listen {|iotask_ch|
43+
44+
run(copy(builder)) {||
45+
#debug("entering libuv task");
46+
run_loop(iotask_ch);
47+
#debug("libuv task exiting");
48+
};
5049

51-
iotask_po.recv()
50+
iotask_ch.recv()
51+
}
5252
}
5353

5454

@@ -102,27 +102,29 @@ enum iotask_msg {
102102
Run the loop and begin handling messages
103103
"]
104104
fn run_loop(iotask_ch: chan<iotask>) unsafe {
105-
let msg_po = port::<iotask_msg>();
105+
106106
let loop_ptr = ll::loop_new();
107+
107108
// set up the special async handle we'll use to allow multi-task
108109
// communication with this loop
109110
let async = ll::async_t();
110111
let async_handle = addr_of(async);
112+
111113
// associate the async handle with the loop
112114
ll::async_init(loop_ptr, async_handle, wake_up_cb);
113115

114116
// initialize our loop data and store it in the loop
115117
let data: iotask_loop_data = {
116118
async_handle: async_handle,
117-
msg_po_ptr: addr_of(msg_po)
119+
msg_po: port()
118120
};
119121
ll::set_data_for_uv_handle(async_handle, addr_of(data));
120122

121123
// Send out a handle through which folks can talk to us
122124
// while we dwell in the I/O loop
123125
let iotask = iotask_({
124126
async_handle: async_handle,
125-
op_chan: msg_po.chan()
127+
op_chan: data.msg_po.chan()
126128
});
127129
iotask_ch.send(iotask);
128130

@@ -136,7 +138,7 @@ fn run_loop(iotask_ch: chan<iotask>) unsafe {
136138
// data that lives for the lifetime of the high-evel oo
137139
type iotask_loop_data = {
138140
async_handle: *ll::uv_async_t,
139-
msg_po_ptr: *port<iotask_msg>
141+
msg_po: port<iotask_msg>
140142
};
141143

142144
fn send_msg(iotask: iotask,
@@ -145,21 +147,19 @@ fn send_msg(iotask: iotask,
145147
ll::async_send(iotask.async_handle);
146148
}
147149

148-
// this will be invoked by a call to uv::hl::interact() with
149-
// the high_level_loop corresponding to this async_handle. We
150-
// simply check if the loop is active and, if so, invoke the
151-
// user-supplied on_wake callback that is stored in the loop's
152-
// data member
150+
#[doc ="Dispatch all pending messages"]
153151
crust fn wake_up_cb(async_handle: *ll::uv_async_t,
154152
status: int) unsafe {
153+
155154
log(debug, #fmt("wake_up_cb crust.. handle: %? status: %?",
156155
async_handle, status));
156+
157157
let loop_ptr = ll::get_loop_for_uv_handle(async_handle);
158158
let data = ll::get_data_for_uv_handle(async_handle) as *iotask_loop_data;
159-
let msg_po = *((*data).msg_po_ptr);
159+
let msg_po = (*data).msg_po;
160+
160161
while msg_po.peek() {
161-
let msg = msg_po.recv();
162-
alt msg {
162+
alt msg_po.recv() {
163163
interaction(cb) {
164164
cb(loop_ptr);
165165
}
@@ -172,7 +172,6 @@ crust fn wake_up_cb(async_handle: *ll::uv_async_t,
172172

173173
fn begin_teardown(data: *iotask_loop_data) unsafe {
174174
log(debug, "iotask begin_teardown() called, close async_handle");
175-
// call user-suppled before_tear_down cb
176175
let async_handle = (*data).async_handle;
177176
ll::close(async_handle as *c_void, tear_down_close_cb);
178177
}

0 commit comments

Comments
 (0)