Skip to content

Commit b177a8c

Browse files
committed
---
yaml --- r: 16039 b: refs/heads/try c: 06ff3f8 h: refs/heads/master i: 16037: 961e01f 16035: 28edf48 16031: 9f3029a v: v3
1 parent 08ca4c3 commit b177a8c

File tree

3 files changed

+44
-85
lines changed

3 files changed

+44
-85
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
refs/heads/master: 61b1875c16de39c166b0f4d54bba19f9c6777d1a
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 4a81779abd786ff22d71434c6d9a5917ea4cdfff
5-
refs/heads/try: 77bbd72171631223464057f79fcd82e81787e84c
5+
refs/heads/try: 06ff3f8b4b81dc84721cbddd1f480786f40f43fa
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105

branches/try/src/libstd/uv_global_loop.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ fn get_monitor_task_gl() -> hl::high_level_loop {
5858
let hl_loop_data = spawn_libuv_weak_task();
5959
let hl_loop = alt hl_loop_data {
6060
(async, msg_ch) {
61-
hl::simple_task_loop({async_handle:async, op_chan:msg_ch})
61+
hl::high_level_loop({async_handle:async, op_chan:msg_ch})
6262
}
6363
};
6464
loop {

branches/try/src/libstd/uv_hl.rs

Lines changed: 42 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,18 @@ libuv functionality.
99
export high_level_loop, high_level_msg;
1010
export run_high_level_loop, interact;
1111

12+
import libc::c_void;
13+
import ptr::addr_of;
14+
import comm::{port, chan, methods};
1215
import ll = uv_ll;
1316

14-
// FIXME: Newtype syntax
1517
#[doc = "
1618
Used to abstract-away direct interaction with a libuv loop.
1719
"]
18-
enum high_level_loop {
19-
#[doc="
20-
`high_level_loop` variant that carries a `comm::chan` and
21-
a `*ll::uv_async_t`.
22-
"]
23-
simple_task_loop({
24-
async_handle: *ll::uv_async_t,
25-
op_chan: comm::chan<high_level_msg>
26-
})
27-
}
20+
enum high_level_loop = {
21+
async_handle: *ll::uv_async_t,
22+
op_chan: chan<high_level_msg>
23+
};
2824

2925
#[doc="
3026
Represents the range of interactions with a `high_level_loop`
@@ -64,29 +60,28 @@ the loop's msg port
6460
* before_tear_down - called just before the loop invokes `uv_close()` on the
6561
provided `async_handle`. `uv_run` should return shortly after
6662
"]
67-
unsafe fn run_high_level_loop(loop_ptr: *libc::c_void,
68-
msg_po: comm::port<high_level_msg>,
63+
unsafe fn run_high_level_loop(loop_ptr: *c_void,
64+
msg_po: port<high_level_msg>,
6965
before_run: fn~(*ll::uv_async_t),
7066
before_msg_process:
7167
fn~(*ll::uv_async_t, bool) -> bool,
7268
before_tear_down: fn~(*ll::uv_async_t)) {
7369
// set up the special async handle we'll use to allow multi-task
7470
// communication with this loop
7571
let async = ll::async_t();
76-
let async_handle = ptr::addr_of(async);
72+
let async_handle = addr_of(async);
7773
// associate the async handle with the loop
7874
ll::async_init(loop_ptr, async_handle, high_level_wake_up_cb);
7975

8076
// initialize our loop data and store it in the loop
81-
let data: hl_loop_data = default_gl_data({
77+
let data: hl_loop_data = {
8278
async_handle: async_handle,
8379
mut active: true,
8480
before_msg_process: before_msg_process,
8581
before_tear_down: before_tear_down,
86-
msg_po_ptr: ptr::addr_of(msg_po)
87-
});
88-
let data_ptr = ptr::addr_of(data);
89-
ll::set_data_for_uv_handle(async_handle, data_ptr);
82+
msg_po_ptr: addr_of(msg_po)
83+
};
84+
ll::set_data_for_uv_handle(async_handle, addr_of(data));
9085

9186
// call before_run
9287
before_run(async_handle);
@@ -120,41 +115,25 @@ module. It is not safe to send the `loop_ptr` param to this callback out
120115
via ports/chans.
121116
"]
122117
unsafe fn interact(hl_loop: high_level_loop,
123-
-cb: fn~(*libc::c_void)) {
118+
-cb: fn~(*c_void)) {
124119
send_high_level_msg(hl_loop, interaction(cb));
125120
}
126121

127122
// INTERNAL API
128123

129-
// FIXME: Newtype syntax
130124
// data that lives for the lifetime of the high-evel oo
131-
enum hl_loop_data {
132-
// FIXME: hl, not gl?
133-
default_gl_data({
134-
async_handle: *ll::uv_async_t,
135-
mut active: bool,
136-
before_msg_process: fn~(*ll::uv_async_t, bool) -> bool,
137-
before_tear_down: fn~(*ll::uv_async_t),
138-
msg_po_ptr: *comm::port<high_level_msg>})
139-
}
125+
type hl_loop_data = {
126+
async_handle: *ll::uv_async_t,
127+
mut active: bool,
128+
before_msg_process: fn~(*ll::uv_async_t, bool) -> bool,
129+
before_tear_down: fn~(*ll::uv_async_t),
130+
msg_po_ptr: *port<high_level_msg>
131+
};
140132

141-
// FIXME: This function can be much simpler
142133
unsafe fn send_high_level_msg(hl_loop: high_level_loop,
143134
-msg: high_level_msg) {
144-
let op_chan = alt hl_loop{simple_task_loop({async_handle, op_chan}){
145-
op_chan}};
146-
comm::send(op_chan, msg);
147-
148-
// if the global async handle == 0, then that means
149-
// the loop isn't active, so we don't need to wake it up,
150-
// (the loop's enclosing task should be blocking on a message
151-
// receive on this port)
152-
alt hl_loop {
153-
simple_task_loop({async_handle, op_chan}) {
154-
log(debug,"simple async handle != 0, waking up loop..");
155-
ll::async_send((async_handle));
156-
}
157-
}
135+
comm::send(hl_loop.op_chan, msg);
136+
ll::async_send(hl_loop.async_handle);
158137
}
159138

160139
// this will be invoked by a call to uv::hl::interact() with
@@ -169,43 +148,27 @@ crust fn high_level_wake_up_cb(async_handle: *ll::uv_async_t,
169148
let loop_ptr = ll::get_loop_for_uv_handle(async_handle);
170149
let data = ll::get_data_for_uv_handle(async_handle) as *hl_loop_data;
171150
// FIXME: What is this checking?
172-
// FIXME: Use if not alt
173-
alt (*data).active {
174-
true {
151+
if (*data).active {
175152
let msg_po = *((*data).msg_po_ptr);
176-
// FIXME: Convert to while loop
177-
alt comm::peek(msg_po) {
178-
true {
179-
loop {
180-
let msg = comm::recv(msg_po);
181-
alt (*data).active {
182-
true {
183-
alt msg {
184-
interaction(cb) {
185-
(*data).before_msg_process(async_handle,
186-
(*data).active);
187-
cb(loop_ptr);
188-
}
189-
teardown_loop {
190-
begin_teardown(data);
191-
}
192-
}
153+
while msg_po.peek() {
154+
let msg = msg_po.recv();
155+
if (*data).active {
156+
alt msg {
157+
interaction(cb) {
158+
(*data).before_msg_process(async_handle,
159+
(*data).active);
160+
cb(loop_ptr);
193161
}
194-
false {
195-
// drop msg ?
162+
teardown_loop {
163+
begin_teardown(data);
196164
}
197165
}
198-
if !comm::peek(msg_po) { break; }
166+
} else {
167+
// FIXME: drop msg ?
199168
}
200-
}
201-
false {
202-
// no pending msgs
203-
}
204169
}
205-
}
206-
false {
170+
} else {
207171
// loop not active
208-
}
209172
}
210173
}
211174

@@ -222,7 +185,7 @@ fn begin_teardown(data: *hl_loop_data) unsafe {
222185
// call user-suppled before_tear_down cb
223186
let async_handle = (*data).async_handle;
224187
(*data).before_tear_down(async_handle);
225-
ll::close(async_handle as *libc::c_void, tear_down_close_cb);
188+
ll::close(async_handle as *c_void, tear_down_close_cb);
226189
}
227190

228191
#[cfg(test)]
@@ -278,7 +241,7 @@ mod test {
278241
async_handle));
279242
// do an async_send with it
280243
ll::async_send(async_handle);
281-
comm::send(hl_loop_ch, simple_task_loop({
244+
comm::send(hl_loop_ch, high_level_loop({
282245
async_handle: async_handle,
283246
op_chan: msg_ch
284247
}));
@@ -339,12 +302,8 @@ mod test {
339302
// anyone rolling their own high_level_loop can decide when to
340303
// send the msg. it's assert and barf, though, if all of your
341304
// handles aren't uv_close'd first
342-
alt hl_loop {
343-
simple_task_loop({async_handle, op_chan}) {
344-
comm::send(op_chan, teardown_loop);
345-
ll::async_send(async_handle);
346-
}
347-
}
305+
comm::send(hl_loop.op_chan, teardown_loop);
306+
ll::async_send(hl_loop.async_handle);
348307
comm::recv(exit_po);
349308
log(debug, "after recv on exit_po.. exiting..");
350309
}

0 commit comments

Comments
 (0)