Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
542119f6
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,发现更多精彩内容 >>
提交
542119f6
编写于
3月 01, 2013
作者:
P
Patrick Walton
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
libcore: Remove `fn@`, `fn~`, and `fn&` from libcore. rs=defun
上级
a38cbebd
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
51 addition
and
54 deletion
+51
-54
src/libcore/io.rs
src/libcore/io.rs
+5
-9
src/libcore/pipes.rs
src/libcore/pipes.rs
+8
-10
src/libcore/reflect.rs
src/libcore/reflect.rs
+2
-2
src/libcore/task/mod.rs
src/libcore/task/mod.rs
+16
-15
src/libcore/task/spawn.rs
src/libcore/task/spawn.rs
+14
-11
src/libcore/unstable/finally.rs
src/libcore/unstable/finally.rs
+2
-3
src/libcore/unstable/weak_task.rs
src/libcore/unstable/weak_task.rs
+4
-4
未找到文件。
src/libcore/io.rs
浏览文件 @
542119f6
...
...
@@ -1139,7 +1139,7 @@ pub fn Res<t: Copy>(arg: Arg<t>) -> Res<t>{
pub
struct
Arg
<
t
>
{
val
:
t
,
opt_level
:
Option
<
Level
>
,
fsync_fn
:
fn
@
(
f
:
t
,
Level
)
->
int
,
fsync_fn
:
@
fn
(
f
:
t
,
Level
)
->
int
,
}
// fsync file after executing blk
...
...
@@ -1150,9 +1150,9 @@ pub fn FILE_res_sync(file: &FILERes, opt_level: Option<Level>,
unsafe
{
blk
(
Res
(
Arg
{
val
:
file
.f
,
opt_level
:
opt_level
,
fsync_fn
:
fn
@
(
file
:
*
libc
::
FILE
,
l
:
Level
)
->
int
{
fsync_fn
:
|
file
,
l
|
{
unsafe
{
return
os
::
fsync_fd
(
libc
::
fileno
(
file
),
l
)
as
int
;
os
::
fsync_fd
(
libc
::
fileno
(
file
),
l
)
as
int
}
}
}));
...
...
@@ -1164,9 +1164,7 @@ pub fn fd_res_sync(fd: &FdRes, opt_level: Option<Level>,
blk
:
fn
(
v
:
Res
<
fd_t
>
))
{
blk
(
Res
(
Arg
{
val
:
fd
.fd
,
opt_level
:
opt_level
,
fsync_fn
:
fn
@
(
fd
:
fd_t
,
l
:
Level
)
->
int
{
return
os
::
fsync_fd
(
fd
,
l
)
as
int
;
}
fsync_fn
:
|
fd
,
l
|
os
::
fsync_fd
(
fd
,
l
)
as
int
}));
}
...
...
@@ -1178,9 +1176,7 @@ pub fn obj_sync(o: FSyncable, opt_level: Option<Level>,
blk
:
fn
(
v
:
Res
<
FSyncable
>
))
{
blk
(
Res
(
Arg
{
val
:
o
,
opt_level
:
opt_level
,
fsync_fn
:
fn
@
(
o
:
FSyncable
,
l
:
Level
)
->
int
{
return
o
.fsync
(
l
);
}
fsync_fn
:
|
o
,
l
|
o
.fsync
(
l
)
}));
}
}
...
...
src/libcore/pipes.rs
浏览文件 @
542119f6
...
...
@@ -910,11 +910,10 @@ pub fn entangle<T>() -> (SendPacket<T>, RecvPacket<T>) {
*/
pub
fn
spawn_service
<
T
:
Owned
,
Tb
:
Owned
>
(
init
:
extern
fn
()
->
(
SendPacketBuffered
<
T
,
Tb
>
,
RecvPacketBuffered
<
T
,
Tb
>
),
service
:
fn
~
(
v
:
RecvPacketBuffered
<
T
,
Tb
>
))
->
SendPacketBuffered
<
T
,
Tb
>
{
init
:
extern
fn
()
->
(
SendPacketBuffered
<
T
,
Tb
>
,
RecvPacketBuffered
<
T
,
Tb
>
),
service
:
~
fn
(
v
:
RecvPacketBuffered
<
T
,
Tb
>
))
->
SendPacketBuffered
<
T
,
Tb
>
{
let
(
client
,
server
)
=
init
();
// This is some nasty gymnastics required to safely move the pipe
...
...
@@ -932,11 +931,10 @@ pub fn spawn_service<T:Owned,Tb:Owned>(
*/
pub
fn
spawn_service_recv
<
T
:
Owned
,
Tb
:
Owned
>
(
init
:
extern
fn
()
->
(
RecvPacketBuffered
<
T
,
Tb
>
,
SendPacketBuffered
<
T
,
Tb
>
),
service
:
fn
~
(
v
:
SendPacketBuffered
<
T
,
Tb
>
))
->
RecvPacketBuffered
<
T
,
Tb
>
{
init
:
extern
fn
()
->
(
RecvPacketBuffered
<
T
,
Tb
>
,
SendPacketBuffered
<
T
,
Tb
>
),
service
:
~
fn
(
v
:
SendPacketBuffered
<
T
,
Tb
>
))
->
RecvPacketBuffered
<
T
,
Tb
>
{
let
(
client
,
server
)
=
init
();
// This is some nasty gymnastics required to safely move the pipe
...
...
src/libcore/reflect.rs
浏览文件 @
542119f6
...
...
@@ -489,9 +489,9 @@ fn visit_constr(&self, inner: *TyDesc) -> bool {
}
fn
visit_closure_ptr
(
&
self
,
ck
:
uint
)
->
bool
{
self
.align_to
::
<
fn
@
()
>
();
self
.align_to
::
<
@
fn
()
>
();
if
!
self
.inner
.visit_closure_ptr
(
ck
)
{
return
false
;
}
self
.bump_past
::
<
fn
@
()
>
();
self
.bump_past
::
<
@
fn
()
>
();
true
}
}
src/libcore/task/mod.rs
浏览文件 @
542119f6
...
...
@@ -191,7 +191,7 @@ pub struct TaskOpts {
// FIXME (#3724): Replace the 'consumed' bit with move mode on self
pub
struct
TaskBuilder
{
opts
:
TaskOpts
,
gen_body
:
fn
@
(
v
:
fn
~
())
->
fn
~
(),
gen_body
:
@
fn
(
v
:
~
fn
())
->
~
fn
(),
can_not_copy
:
Option
<
util
::
NonCopyable
>
,
mut
consumed
:
bool
,
}
...
...
@@ -357,7 +357,7 @@ fn sched_mode(mode: SchedMode) -> TaskBuilder {
* generator by applying the task body which results from the
* existing body generator to the new body generator.
*/
fn
add_wrapper
(
wrapper
:
fn
@
(
v
:
fn
~
())
->
fn
~
())
->
TaskBuilder
{
fn
add_wrapper
(
wrapper
:
@
fn
(
v
:
~
fn
())
->
~
fn
())
->
TaskBuilder
{
let
prev_gen_body
=
self
.gen_body
;
let
notify_chan
=
replace
(
&
mut
self
.opts.notify_chan
,
None
);
TaskBuilder
{
...
...
@@ -385,7 +385,7 @@ fn add_wrapper(wrapper: fn@(v: fn~()) -> fn~()) -> TaskBuilder {
* When spawning into a new scheduler, the number of threads requested
* must be greater than zero.
*/
fn
spawn
(
f
:
fn
~
())
{
fn
spawn
(
f
:
~
fn
())
{
let
notify_chan
=
replace
(
&
mut
self
.opts.notify_chan
,
None
);
let
x
=
self
.consume
();
let
opts
=
TaskOpts
{
...
...
@@ -397,7 +397,7 @@ fn spawn(f: fn~()) {
spawn
::
spawn_raw
(
opts
,
(
x
.gen_body
)(
f
));
}
/// Runs a task, while transfering ownership of one argument to the child.
fn
spawn_with
<
A
:
Owned
>
(
arg
:
A
,
f
:
fn
~
(
v
:
A
))
{
fn
spawn_with
<
A
:
Owned
>
(
arg
:
A
,
f
:
~
fn
(
v
:
A
))
{
let
arg
=
Cell
(
arg
);
do
self
.spawn
{
f
(
arg
.take
());
...
...
@@ -417,7 +417,7 @@ fn spawn_with<A:Owned>(arg: A, f: fn~(v: A)) {
* # Failure
* Fails if a future_result was already set for this task.
*/
fn
try
<
T
:
Owned
>
(
f
:
fn
~
()
->
T
)
->
Result
<
T
,()
>
{
fn
try
<
T
:
Owned
>
(
f
:
~
fn
()
->
T
)
->
Result
<
T
,()
>
{
let
(
po
,
ch
)
=
stream
::
<
T
>
();
let
mut
result
=
None
;
...
...
@@ -458,7 +458,7 @@ pub fn default_task_opts() -> TaskOpts {
/* Spawn convenience functions */
pub
fn
spawn
(
f
:
fn
~
())
{
pub
fn
spawn
(
f
:
~
fn
())
{
/*!
* Creates and executes a new child task
*
...
...
@@ -471,7 +471,7 @@ pub fn spawn(f: fn~()) {
task
()
.spawn
(
f
)
}
pub
fn
spawn_unlinked
(
f
:
fn
~
())
{
pub
fn
spawn_unlinked
(
f
:
~
fn
())
{
/*!
* Creates a child task unlinked from the current one. If either this
* task or the child task fails, the other will not be killed.
...
...
@@ -480,7 +480,7 @@ pub fn spawn_unlinked(f: fn~()) {
task
()
.unlinked
()
.spawn
(
f
)
}
pub
fn
spawn_supervised
(
f
:
fn
~
())
{
pub
fn
spawn_supervised
(
f
:
~
fn
())
{
/*!
* Creates a child task unlinked from the current one. If either this
* task or the child task fails, the other will not be killed.
...
...
@@ -489,7 +489,7 @@ pub fn spawn_supervised(f: fn~()) {
task
()
.supervised
()
.spawn
(
f
)
}
pub
fn
spawn_with
<
A
:
Owned
>
(
arg
:
A
,
f
:
fn
~
(
v
:
A
))
{
pub
fn
spawn_with
<
A
:
Owned
>
(
arg
:
A
,
f
:
~
fn
(
v
:
A
))
{
/*!
* Runs a task, while transfering ownership of one argument to the
* child.
...
...
@@ -503,7 +503,7 @@ pub fn spawn_with<A:Owned>(arg: A, f: fn~(v: A)) {
task
()
.spawn_with
(
arg
,
f
)
}
pub
fn
spawn_sched
(
mode
:
SchedMode
,
f
:
fn
~
())
{
pub
fn
spawn_sched
(
mode
:
SchedMode
,
f
:
~
fn
())
{
/*!
* Creates a new task on a new or existing scheduler
...
...
@@ -519,7 +519,7 @@ pub fn spawn_sched(mode: SchedMode, f: fn~()) {
task
()
.sched_mode
(
mode
)
.spawn
(
f
)
}
pub
fn
try
<
T
:
Owned
>
(
f
:
fn
~
()
->
T
)
->
Result
<
T
,()
>
{
pub
fn
try
<
T
:
Owned
>
(
f
:
~
fn
()
->
T
)
->
Result
<
T
,()
>
{
/*!
* Execute a function in another task and return either the return value
* of the function or result::err.
...
...
@@ -840,11 +840,12 @@ fn test_add_wrapper() {
let
ch
=
Wrapper
{
f
:
Some
(
ch
)
};
let
b1
=
do
b0
.add_wrapper
|
body
|
{
let
ch
=
Wrapper
{
f
:
Some
(
ch
.f
.swap_unwrap
())
};
fn
~
()
{
let
result
:
~
fn
()
=
||
{
let
ch
=
ch
.f
.swap_unwrap
();
body
();
ch
.send
(());
}
};
result
};
do
b1
.spawn
{
}
po
.recv
();
...
...
@@ -1015,7 +1016,7 @@ fn pingpong(po: &Port<int>, ch: &Chan<int>) {
}
#[cfg(test)]
fn
avoid_copying_the_body
(
spawnfn
:
fn
(
v
:
fn
~
()))
{
fn
avoid_copying_the_body
(
spawnfn
:
&
fn
(
v
:
~
fn
()))
{
let
(
p
,
ch
)
=
stream
::
<
uint
>
();
let
x
=
~
1
;
...
...
@@ -1164,7 +1165,7 @@ fn test_child_doesnt_ref_parent() {
// (well, it would if the constant were 8000+ - I lowered it to be more
// valgrind-friendly. try this at home, instead..!)
const
generations
:
uint
=
16
;
fn
child_no
(
x
:
uint
)
->
fn
~
()
{
fn
child_no
(
x
:
uint
)
->
~
fn
()
{
return
||
{
if
x
<
generations
{
task
::
spawn
(
child_no
(
x
+
1
));
...
...
src/libcore/task/spawn.rs
浏览文件 @
542119f6
...
...
@@ -173,19 +173,19 @@ fn access_ancestors<U>(x: &unstable::Exclusive<AncestorNode>,
// taskgroups that forward_blk already ran on successfully (Note: bail_blk
// is NOT called on the block that forward_blk broke on!).
// (3) As a bonus, coalesces away all 'dead' taskgroup nodes in the list.
// FIXME(#2190): Change Option<
fn@(...)> to Option<fn&
(...)>, to save on
// FIXME(#2190): Change Option<
@fn(...)> to Option<&fn
(...)>, to save on
// allocations. Once that bug is fixed, changing the sigil should suffice.
fn
each_ancestor
(
list
:
&
mut
AncestorList
,
bail_opt
:
Option
<
fn
@
(
TaskGroupInner
)
>
,
forward_blk
:
fn
(
TaskGroupInner
)
->
bool
)
->
bool
{
bail_opt
:
Option
<@
fn
(
TaskGroupInner
)
>
,
forward_blk
:
fn
(
TaskGroupInner
)
->
bool
)
->
bool
{
// "Kickoff" call - there was no last generation.
return
!
coalesce
(
list
,
bail_opt
,
forward_blk
,
uint
::
max_value
);
// Recursively iterates, and coalesces afterwards if needed. Returns
// whether or not unwinding is needed (i.e., !successful iteration).
fn
coalesce
(
list
:
&
mut
AncestorList
,
bail_opt
:
Option
<
fn
@
(
TaskGroupInner
)
>
,
bail_opt
:
Option
<
@
fn
(
TaskGroupInner
)
>
,
forward_blk
:
fn
(
TaskGroupInner
)
->
bool
,
last_generation
:
uint
)
->
bool
{
// Need to swap the list out to use it, to appease borrowck.
...
...
@@ -213,9 +213,10 @@ fn coalesce(list: &mut AncestorList,
// True if the supplied block did 'break', here or in any recursive
// calls. If so, must call the unwinder on all previous nodes.
fn
iterate
(
ancestors
:
&
AncestorList
,
bail_opt
:
Option
<
fn
@
(
TaskGroupInner
)
>
,
forward_blk
:
fn
(
TaskGroupInner
)
->
bool
,
last_generation
:
uint
)
->
(
Option
<
AncestorList
>
,
bool
)
{
bail_opt
:
Option
<@
fn
(
TaskGroupInner
)
>
,
forward_blk
:
&
fn
(
TaskGroupInner
)
->
bool
,
last_generation
:
uint
)
->
(
Option
<
AncestorList
>
,
bool
)
{
// At each step of iteration, three booleans are at play which govern
// how the iteration should behave.
// 'nobe_is_dead' - Should the list should be coalesced at this point?
...
...
@@ -532,7 +533,7 @@ fn share_ancestors(ancestors: &mut AncestorList) -> AncestorList {
}
}
pub
fn
spawn_raw
(
opts
:
TaskOpts
,
f
:
fn
~
())
{
pub
fn
spawn_raw
(
opts
:
TaskOpts
,
f
:
~
fn
())
{
let
(
child_tg
,
ancestors
,
is_main
)
=
gen_child_taskgroup
(
opts
.linked
,
opts
.supervised
);
...
...
@@ -577,9 +578,10 @@ pub fn spawn_raw(opts: TaskOpts, f: fn~()) {
fn
make_child_wrapper
(
child
:
*
rust_task
,
child_arc
:
TaskGroupArc
,
ancestors
:
AncestorList
,
is_main
:
bool
,
notify_chan
:
Option
<
Chan
<
TaskResult
>>
,
f
:
fn
~
())
->
fn
~
()
{
f
:
~
fn
())
->
~
fn
()
{
let
child_data
=
Cell
((
child_arc
,
ancestors
));
return
fn
~
()
{
let
result
:
~
fn
()
=
||
{
// Agh. Get move-mode items into the closure. FIXME (#2829)
let
mut
(
child_arc
,
ancestors
)
=
child_data
.take
();
// Child task runs this code.
...
...
@@ -613,6 +615,7 @@ fn make_child_wrapper(child: *rust_task, child_arc: TaskGroupArc,
// FIXME #4428: Crashy.
// unsafe { cleanup::annihilate(); }
};
return
result
;
// Set up membership in taskgroup and descendantship in all ancestor
// groups. If any enlistment fails, Some task was already failing, so
...
...
src/libcore/unstable/finally.rs
浏览文件 @
542119f6
...
...
@@ -79,9 +79,8 @@ fn test_fail() {
#[test]
fn
test_retval
()
{
let
i
=
do
(
fn
&
()
->
int
{
10
})
.finally
{
};
let
closure
:
&
fn
()
->
int
=
||
10
;
let
i
=
do
closure
.finally
{
};
assert
i
==
10
;
}
...
...
src/libcore/unstable/weak_task.rs
浏览文件 @
542119f6
...
...
@@ -43,9 +43,9 @@ pub unsafe fn weaken_task(f: &fn(Port<ShutdownMsg>)) {
// Expect the weak task service to be alive
assert
service
.try_send
(
RegisterWeakTask
(
task
,
shutdown_chan
));
unsafe
{
rust_dec_kernel_live_count
();
}
do
fn
&
()
{
do
(||
{
f
(
shutdown_port
.take
())
}
.finally
||
{
}
)
.finally
||
{
unsafe
{
rust_inc_kernel_live_count
();
}
// Service my have already exited
service
.send
(
UnregisterWeakTask
(
task
));
...
...
@@ -74,13 +74,13 @@ fn create_global_service() -> ~WeakTaskService {
do
task
()
.unlinked
()
.spawn
{
debug!
(
"running global weak task service"
);
let
port
=
Cell
(
port
.take
());
do
fn
&
()
{
do
(||
{
let
port
=
port
.take
();
// The weak task service is itself a weak task
debug!
(
"weakening the weak service task"
);
unsafe
{
rust_dec_kernel_live_count
();
}
run_weak_task_service
(
port
);
}
.finally
{
}
)
.finally
{
debug!
(
"unweakening the weak service task"
);
unsafe
{
rust_inc_kernel_live_count
();
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录