Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
a045e636
R
Rust
项目概览
int
/
Rust
大约 1 年 前同步成功
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
Rust
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
a045e636
编写于
4月 18, 2012
作者:
J
Jeff Olson
提交者:
Brian Anderson
4月 20, 2012
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
std: get_monitor_task_gl() is global_loop::get() default
上级
e15f1d5c
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
120 addition
and
10 deletion
+120
-10
src/libstd/uv_global_loop.rs
src/libstd/uv_global_loop.rs
+103
-4
src/libstd/uv_hl.rs
src/libstd/uv_hl.rs
+11
-6
src/rt/rust_uv.cpp
src/rt/rust_uv.cpp
+5
-0
src/rt/rustrt.def.in
src/rt/rustrt.def.in
+1
-0
未找到文件。
src/libstd/uv_global_loop.rs
浏览文件 @
a045e636
#[doc=
"
Process-wide, lazily started/stopped libuv event loop interaction
.
A process-wide libuv event loop for library use
.
"
]
;
import
ll
=
uv_ll
;
import
hl
=
uv_hl
;
import
get_gl
=
get
;
export
get
,
get_single_task_gl
;
export
get
,
get_single_task_gl
,
get_monitor_task_gl
;
native
mod
rustrt
{
fn
rust_uv_get_kernel_global_chan_ptr
()
->
*
libc
::
uintptr_t
;
fn
rust_uv_get_kernel_monitor_global_chan_ptr
()
->
*
libc
::
uintptr_t
;
fn
rust_uv_get_kernel_global_async_handle
()
->
*
libc
::
uintptr_t
;
fn
rust_compare_and_swap_ptr
(
address
:
*
libc
::
uintptr_t
,
oldval
:
libc
::
uintptr_t
,
...
...
@@ -20,13 +21,34 @@ fn rust_compare_and_swap_ptr(address: *libc::uintptr_t,
Race-free helper to get access to a global task where a libuv
loop is running.
Use `uv::hl::interact`, `uv::hl::ref_handle` and `uv::hl::unref_handle` to
do operations against the global loop that this function returns.
# Return
* A `hl::high_level_loop` that encapsulates communication with the global
loop.
"
]
fn
get
()
->
hl
::
high_level_loop
{
ret
get_single_task_gl
();
ret
get_monitor_task_gl
();
}
#[doc(hidden)]
fn
get_monitor_task_gl
()
->
hl
::
high_level_loop
{
let
monitor_loop_chan
=
rustrt
::
rust_uv_get_kernel_monitor_global_chan_ptr
();
ret
spawn_global_weak_task
(
monitor_loop_chan
,
{|
weak_exit_po
,
msg_po
,
loop_ptr
,
first_msg
|
log
(
debug
,
"monitor gl: entering inner loop"
);
unsafe
{
monitor_task_loop_body
(
weak_exit_po
,
msg_po
,
loop_ptr
,
copy
(
first_msg
))
}
},
{|
msg_ch
|
hl
::
monitor_task_loop
({
op_chan
:
msg_ch
})
});
}
#[doc(hidden)]
...
...
@@ -35,7 +57,7 @@ fn get_single_task_gl() -> hl::high_level_loop {
ret
spawn_global_weak_task
(
global_loop_chan_ptr
,
{|
weak_exit_po
,
msg_po
,
loop_ptr
,
first_msg
|
log
(
debug
,
"about to enter inner loop"
);
log
(
debug
,
"
single-task gl:
about to enter inner loop"
);
unsafe
{
single_task_loop_body
(
weak_exit_po
,
msg_po
,
loop_ptr
,
copy
(
first_msg
))
...
...
@@ -135,6 +157,83 @@ unsafe fn outer_global_loop_body(
ll
::
loop_delete
(
loop_ptr
);
}
unsafe
fn
monitor_task_loop_body
(
weak_exit_po_in
:
comm
::
port
<
()
>
,
msg_po_in
:
comm
::
port
<
hl
::
high_level_msg
>
,
loop_ptr
:
*
libc
::
c_void
,
-
first_interaction
:
hl
::
high_level_msg
)
->
bool
{
// resend the msg to be handled in the select2 loop below..
comm
::
send
(
comm
::
chan
(
msg_po_in
),
first_interaction
);
// our async_handle
let
async_handle_po
=
comm
::
port
::
<*
ll
::
uv_async_t
>
();
let
async_handle_ch
=
comm
::
chan
(
async_handle_po
);
// the msg_po that libuv will be receiving on..
let
loop_msg_po
=
comm
::
port
::
<
hl
::
high_level_msg
>
();
let
loop_msg_po_ptr
=
ptr
::
addr_of
(
loop_msg_po
);
let
loop_msg_ch
=
comm
::
chan
(
loop_msg_po
);
// the question of whether unsupervising this will even do any
// good is there.. but since this'll go into blocking in libuv with
// a quickness.. any errors that occur (including inside crust) will
// be segfaults.. so yeah.
task
::
spawn_sched
(
task
::
manual_threads
(
1u
))
{||
let
loop_msg_po_in
=
*
loop_msg_po_ptr
;
hl
::
run_high_level_loop
(
loop_ptr
,
loop_msg_po_in
,
// here the loop gets handed a different message
// port, as we'll be receiving all of the messages
// initially and then passing them on..
// before_run
{|
async_handle
|
log
(
debug
,
#
fmt
(
"monitor gl: before_run: async_handle %?"
,
async_handle
));
// when this is ran, our async_handle is set up, so let's
// do an async_send with it.. letting the loop know, once it
// starts, that is has work
ll
::
async_send
(
async_handle
);
comm
::
send
(
async_handle_ch
,
copy
(
async_handle
));
},
// before_msg_drain
{|
async_handle
|
log
(
debug
,
#
fmt
(
"monitor gl: b4_msg_drain: async_handle %?"
,
async_handle
));
true
},
// before_tear_down
{|
async_handle
|
log
(
debug
,
#
fmt
(
"monitor gl: b4_tear_down: async_handle %?"
,
async_handle
));
});
};
// our loop is set up, so let's emit the handle back out to our users..
let
async_handle
=
comm
::
recv
(
async_handle_po
);
// supposed to return a bool to indicate to the enclosing loop whether
// it should continue or not..
let
mut
continue_inner_loop
=
true
;
let
mut
didnt_get_hl_bailout
=
true
;
while
continue_inner_loop
{
log
(
debug
,
"monitor task inner loop.. about to block on select2"
);
continue_inner_loop
=
either
::
either
(
{|
left_val
|
// bail out..
log
(
debug
,
#
fmt
(
"monitor inner weak_exit_po recv'd msg: %?"
,
left_val
));
// TODO: make loop bail out
didnt_get_hl_bailout
=
false
;
false
},
{|
right_val
|
// wake up our inner loop and pass it a msg..
comm
::
send
(
loop_msg_ch
,
copy
(
right_val
));
ll
::
async_send
(
async_handle
);
true
},
comm
::
select2
(
weak_exit_po_in
,
msg_po_in
)
)
}
didnt_get_hl_bailout
}
unsafe
fn
single_task_loop_body
(
weak_exit_po_in
:
comm
::
port
<
()
>
,
msg_po_in
:
comm
::
port
<
hl
::
high_level_msg
>
,
...
...
src/libstd/uv_hl.rs
浏览文件 @
a045e636
...
...
@@ -193,12 +193,17 @@ unsafe fn send_high_level_msg(hl_loop: high_level_loop,
// the loop isn't active, so we don't need to wake it up,
// (the loop's enclosing task should be blocking on a message
// receive on this port)
if
(
*
(
hl_loop
.async_handle
())
!=
0
as
*
ll
::
uv_async_t
)
{
log
(
debug
,
"global async handle != 0, waking up loop.."
);
ll
::
async_send
(
*
(
hl_loop
.async_handle
()));
}
else
{
log
(
debug
,
"GLOBAL ASYNC handle == 0"
);
alt
hl_loop
{
single_task_loop
({
async_handle
,
op_chan
})
{
if
((
*
async_handle
)
!=
0
as
*
ll
::
uv_async_t
)
{
log
(
debug
,
"global async handle != 0, waking up loop.."
);
ll
::
async_send
((
*
async_handle
));
}
else
{
log
(
debug
,
"GLOBAL ASYNC handle == 0"
);
}
}
_
{}
}
}
...
...
src/rt/rust_uv.cpp
浏览文件 @
a045e636
...
...
@@ -446,6 +446,11 @@ rust_uv_get_kernel_global_chan_ptr() {
return
result
;
}
extern
"C"
uintptr_t
*
rust_uv_get_kernel_monitor_global_chan_ptr
()
{
return
rust_uv_get_kernel_global_chan_ptr
();
}
extern
"C"
uintptr_t
*
rust_uv_get_kernel_global_async_handle
()
{
return
rust_get_current_task
()
->
kernel
->
get_global_async_handle
();
...
...
src/rt/rustrt.def.in
浏览文件 @
a045e636
...
...
@@ -138,6 +138,7 @@ rust_uv_set_data_for_req
rust_uv_get_base_from_buf
rust_uv_get_len_from_buf
rust_uv_get_kernel_global_chan_ptr
rust_uv_get_kernel_monitor_global_chan_ptr
rust_uv_get_kernel_global_async_handle
rust_dbg_lock_create
rust_dbg_lock_destroy
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录