Skip to content

Commit caab575

Browse files
committed
rt/std: whitespace cleanup + work on hl/global_loop docs
1 parent 92e88e4 commit caab575

File tree

3 files changed

+41
-25
lines changed

3 files changed

+41
-25
lines changed

src/libstd/uv_global_loop.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ fn get() -> hl::high_level_loop {
2828
ret get_monitor_task_gl();
2929
}
3030

31-
// WARNING: USE ONLY ONE get_*_task_gl fn in the scope of a process lifetime.
3231
#[doc(hidden)]
3332
fn get_monitor_task_gl() -> hl::high_level_loop {
3433
let monitor_loop_chan_ptr =
@@ -100,7 +99,7 @@ unsafe fn spawn_libuv_weak_task() -> (*ll::uv_async_t,
10099
let exit_po = comm::port::<(*ll::uv_async_t,
101100
comm::chan<hl::high_level_msg>)>();
102101
let exit_ch = comm::chan(exit_po);
103-
102+
104103
task::spawn_sched(task::manual_threads(1u)) {||
105104
log(debug, "entering global libuv task");
106105
let loop_ptr = ll::loop_new();

src/libstd/uv_hl.rs

Lines changed: 39 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,12 @@ import ll = uv_ll;
1313

1414
#[doc = "
1515
Used to abstract-away direct interaction with a libuv loop.
16-
17-
# Arguments
18-
19-
* async_handle - a pointer to a pointer to a uv_async_t struct used to 'poke'
20-
the C uv loop to process any pending callbacks
21-
22-
* op_chan - a channel used to send function callbacks to be processed
23-
by the C uv loop
2416
"]
2517
enum high_level_loop {
18+
#[doc="
19+
`high_level_loop` variant that carries a `comm::chan` and
20+
a `*ll::uv_async_t`.
21+
"]
2622
simple_task_loop({
2723
async_handle: *ll::uv_async_t,
2824
op_chan: comm::chan<high_level_msg>
@@ -34,23 +30,36 @@ Represents the range of interactions with a `high_level_loop`
3430
"]
3531
enum high_level_msg {
3632
interaction (fn~(*libc::c_void)),
33+
#[doc="
34+
For use in libraries that roll their own `high_level_loop` (like
35+
`std::uv::global_loop`)
36+
37+
Is used to signal to the loop that it should close the internally-held
38+
async handle and do a sanity check to make sure that all other handles are
39+
closed, causing a failure otherwise. This should not be sent/used from
40+
'normal' user code.
41+
"]
3742
teardown_loop
3843
}
3944

4045
#[doc = "
41-
Given a vanilla `uv_loop_t*`
46+
Useful for anyone who wants to roll their own `high_level_loop`.
4247
4348
# Arguments
4449
4550
* loop_ptr - a pointer to a currently unused libuv loop. Its `data` field
4651
will be overwritten before the loop begins
47-
must be a pointer to a clean rust `uv_async_t` record
48-
* msg_po - an active port that receives `high_level_msg`s
49-
* before_run - a unique closure that is invoked after `uv_async_init` is
50-
called on the `async_handle` passed into this callback, just before `uv_run`
51-
is called on the provided `loop_ptr`
52-
* before_msg_drain - a unique closure that is invoked every time the loop is
53-
awoken, but before the port pointed to in the `msg_po` argument is drained
52+
* msg_po - an active port that receives `high_level_msg`s. You can distribute
53+
a paired channel to users, along with the `async_handle` returned in the
54+
following callback (combine them to make a `hl::simpler_task_loop` varient
55+
of `hl::high_level_loop`)
56+
* before_run - a unique closure that is invoked before `uv_run()` is called
57+
on the provided `loop_ptr`. An `async_handle` is passed in which will be
58+
live for the duration of the loop. You can distribute this to users so that
59+
they can interact with the loop safely.
60+
* before_msg_process - a unique closure that is invoked at least once when
61+
the loop is woken up, and once more for every message that is drained from
62+
the loop's msg port
5463
* before_tear_down - called just before the loop invokes `uv_close()` on the
5564
provided `async_handle`. `uv_run` should return shortly after
5665
"]
@@ -93,17 +102,25 @@ Provide a callback to be processed by `a_loop`
93102
The primary way to do operations again a running `high_level_loop` that
94103
doesn't involve creating a uv handle via `safe_handle`
95104
105+
# Warning
106+
107+
This function is the only safe way to interact with _any_ `high_level_loop`.
108+
Using functions in the `uv::ll` module outside of the `cb` passed into
109+
this function is _very dangerous_.
110+
96111
# Arguments
97112
98-
* a_loop - a `high_level_loop` that you want to do operations against
113+
* hl_loop - a `uv::hl::high_level_loop` that you want to do operations against
99114
* cb - a function callback to be processed on the running loop's
100-
thread. The only parameter is an opaque pointer to the running
101-
uv_loop_t. In the context of this callback, it is safe to use this pointer
102-
to do various uv_* API calls. _DO NOT_ send this pointer out via ports/chans
115+
thread. The only parameter passed in is an opaque pointer representing the
116+
running `uv_loop_t*`. In the context of this callback, it is safe to use
117+
this pointer to do various uv_* API calls contained within the `uv::ll`
118+
module. It is not safe to send the `loop_ptr` param to this callback out
119+
via ports/chans.
103120
"]
104-
unsafe fn interact(a_loop: high_level_loop,
121+
unsafe fn interact(hl_loop: high_level_loop,
105122
-cb: fn~(*libc::c_void)) {
106-
send_high_level_msg(a_loop, interaction(cb));
123+
send_high_level_msg(hl_loop, interaction(cb));
107124
}
108125

109126
// INTERNAL API

src/rt/rust_uv.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ rust_uv_loop_delete(uv_loop_t* loop) {
113113

114114
extern "C" int
115115
rust_uv_loop_refcount(uv_loop_t* loop) {
116-
return uv_loop_refcount(loop);
116+
return uv_loop_refcount(loop);
117117
}
118118

119119
extern "C" void

0 commit comments

Comments
 (0)