Skip to content

Commit 21474f2

Browse files
olsonjefferybrson
authored andcommitted
---
yaml --- r: 15577 b: refs/heads/try c: 253fad7 h: refs/heads/master i: 15575: 23b0164 v: v3
1 parent f17fcae commit 21474f2

File tree

6 files changed

+44
-30
lines changed

6 files changed

+44
-30
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: d7a87aa0a1bf6fb2fe2e591d63e48e39799e8437
5+
refs/heads/try: 253fad77883869511e2030352e86904ac2165d7c
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105

branches/try/src/libstd/uv_hl.rs

Lines changed: 36 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@ import ll = uv_ll;
1515

1616
native mod rustrt {
1717
fn rust_uv_get_kernel_global_chan_ptr() -> *libc::uintptr_t;
18-
fn rust_uv_get_kernel_global_async_handle() -> **libc::c_void;
19-
fn rust_uv_set_kernel_global_async_handle(handle: *ll::uv_async_t);
18+
fn rust_uv_get_kernel_global_async_handle() -> *libc::uintptr_t;
19+
fn rust_compare_and_swap_ptr(address: *libc::uintptr_t,
20+
oldval: libc::uintptr_t,
21+
newval: libc::uintptr_t) -> bool;
2022
}
2123

2224
#[doc = "
@@ -75,7 +77,8 @@ fn get_global_loop() -> high_level_loop unsafe {
7577
outer_global_loop_body(port);
7678
};
7779
log(debug, "after priv::chan_from_global_ptr");
78-
let handle = get_global_async_handle();
80+
let handle = get_global_async_handle_native_representation()
81+
as **ll::uv_async_t;
7982
ret { async_handle: handle, op_chan: chan };
8083
}
8184
}
@@ -104,7 +107,7 @@ unsafe fn run_high_level_loop(loop_ptr: *libc::c_void,
104107
msg_po: comm::port<high_level_msg>,
105108
before_run: fn~(*global_loop_data),
106109
before_msg_drain: fn~() -> bool,
107-
before_tear_down: fn~()) {
110+
before_tear_down: fn~(*global_loop_data)) {
108111
// set up the special async handle we'll use to allow multi-task
109112
// communication with this loop
110113
let async = ll::async_t();
@@ -117,7 +120,7 @@ unsafe fn run_high_level_loop(loop_ptr: *libc::c_void,
117120
async_handle: async_handle,
118121
mut active: true,
119122
before_msg_drain: before_msg_drain,
120-
before_tear_down: before_tear_down,
123+
before_tear_down: gdc_callback(before_tear_down),
121124
msg_po_ptr: ptr::addr_of(msg_po),
122125
mut refd_handles: [mut],
123126
mut unrefd_handles: [mut]
@@ -263,7 +266,11 @@ crust fn tear_down_close_cb(handle: *ll::uv_async_t) unsafe {
263266
fn high_level_tear_down(data: *global_loop_data) unsafe {
264267
log(debug, "high_level_tear_down() called, close async_handle");
265268
// call user-suppled before_tear_down cb
266-
(*data).before_tear_down();
269+
alt (*data).before_tear_down {
270+
gdc_callback(cb) {
271+
cb(data);
272+
}
273+
}
267274
let async_handle = (*data).async_handle;
268275
ll::close(async_handle as *libc::c_void, tear_down_close_cb);
269276
}
@@ -330,19 +337,32 @@ enum high_level_msg {
330337
tear_down
331338
}
332339

333-
fn get_global_async_handle() -> **ll::uv_async_t {
334-
ret rustrt::rust_uv_get_kernel_global_async_handle() as **ll::uv_async_t;
340+
unsafe fn get_global_async_handle_native_representation()
341+
-> *libc::uintptr_t {
342+
ret rustrt::rust_uv_get_kernel_global_async_handle();
343+
}
344+
345+
unsafe fn get_global_async_handle() -> *ll::uv_async_t {
346+
ret (*get_global_async_handle_native_representation()) as *ll::uv_async_t;
335347
}
336348

337-
fn set_global_async_handle(handle: *ll::uv_async_t) {
338-
rustrt::rust_uv_set_kernel_global_async_handle(handle);
349+
unsafe fn set_global_async_handle(old: *ll::uv_async_t,
350+
new_ptr: *ll::uv_async_t) {
351+
rustrt::rust_compare_and_swap_ptr(
352+
get_global_async_handle_native_representation(),
353+
old as libc::uintptr_t,
354+
new_ptr as libc::uintptr_t);
355+
}
356+
357+
enum global_data_callback {
358+
gdc_callback(fn~(*global_loop_data))
339359
}
340360

341361
type global_loop_data = {
342362
async_handle: *ll::uv_async_t,
343363
mut active: bool,
344364
before_msg_drain: fn~() -> bool,
345-
before_tear_down: fn~(),
365+
before_tear_down: global_data_callback,
346366
msg_po_ptr: *comm::port<high_level_msg>,
347367
mut refd_handles: [mut *libc::c_void],
348368
mut unrefd_handles: [mut *libc::c_void]
@@ -399,7 +419,8 @@ unsafe fn inner_global_loop_body(weak_exit_po_in: comm::port<()>,
399419
// before_run
400420
{|data|
401421
// set the handle as the global
402-
set_global_async_handle((*data).async_handle);
422+
set_global_async_handle(0u as *ll::uv_async_t,
423+
(*data).async_handle);
403424
// when this is ran, our async_handle is set up, so let's
404425
// do an async_send with it
405426
ll::async_send((*data).async_handle);
@@ -422,8 +443,9 @@ unsafe fn inner_global_loop_body(weak_exit_po_in: comm::port<()>,
422443
}
423444
},
424445
// before_tear_down
425-
{||
426-
set_global_async_handle(0 as *ll::uv_async_t);
446+
{|data|
447+
set_global_async_handle((*data).async_handle,
448+
0 as *ll::uv_async_t);
427449
});
428450
// supposed to return a bool to indicate to the enclosing loop whether
429451
// it should continue or not..

branches/try/src/rt/rust_kernel.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,9 @@ rust_kernel::rust_kernel(rust_env *env) :
2727
// set up storage of pointers needed to
2828
// access the global loop.
2929
global_loop_chan = 0;
30-
int foo = 0;
31-
async_handle_stub = (void*)&foo;
32-
global_async_handle = &async_handle_stub;
33-
*global_async_handle = (void*)0;
30+
async_handle_inner = (uintptr_t)0;
31+
global_async_handle = &async_handle_inner;
32+
*global_async_handle = (uintptr_t)0;
3433

3534
// Create the single threaded scheduler that will run on the platform's
3635
// main thread

branches/try/src/rt/rust_kernel.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ class rust_kernel {
7575

7676
// Used to communicate with the process-side, global libuv loop
7777
uintptr_t global_loop_chan;
78-
void* async_handle_stub;
79-
void** global_async_handle;
78+
uintptr_t async_handle_inner;
79+
uintptr_t* global_async_handle;
8080

8181
public:
8282
struct rust_env *env;
@@ -124,9 +124,7 @@ class rust_kernel {
124124
bool send_to_port(rust_port_id chan, void *sptr);
125125

126126
uintptr_t* get_global_loop() { return &global_loop_chan; }
127-
void** get_global_async_handle() { return global_async_handle; }
128-
void set_global_async_handle(void* handle) {
129-
*global_async_handle = handle; }
127+
uintptr_t* get_global_async_handle() { return global_async_handle; }
130128
};
131129

132130
template <typename T> struct kernel_owned {

branches/try/src/rt/rust_uv.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -446,11 +446,7 @@ rust_uv_get_kernel_global_chan_ptr() {
446446
return result;
447447
}
448448

449-
extern "C" void**
449+
extern "C" uintptr_t*
450450
rust_uv_get_kernel_global_async_handle() {
451451
return rust_get_current_task()->kernel->get_global_async_handle();
452452
}
453-
extern "C" void
454-
rust_uv_set_kernel_global_async_handle(uv_async_t* handle) {
455-
rust_get_current_task()->kernel->set_global_async_handle((void*)handle);
456-
}

branches/try/src/rt/rustrt.def.in

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,6 @@ rust_uv_get_base_from_buf
138138
rust_uv_get_len_from_buf
139139
rust_uv_get_kernel_global_chan_ptr
140140
rust_uv_get_kernel_global_async_handle
141-
rust_uv_set_kernel_global_async_handle
142141
rust_dbg_lock_create
143142
rust_dbg_lock_destroy
144143
rust_dbg_lock_lock

0 commit comments

Comments
 (0)