Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
89bdd481
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,发现更多精彩内容 >>
提交
89bdd481
编写于
7月 02, 2012
作者:
E
Eric Holk
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Port future to pipes. Graph500 is about 21% faster now.
Making all tests pass.
上级
e5c9cb2b
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
112 addition
and
24 deletion
+112
-24
src/libcore/future.rs
src/libcore/future.rs
+78
-19
src/libcore/pipes.rs
src/libcore/pipes.rs
+19
-0
src/libcore/task.rs
src/libcore/task.rs
+15
-5
未找到文件。
src/libcore/future.rs
浏览文件 @
89bdd481
...
...
@@ -22,7 +22,10 @@
export
with
;
export
spawn
;
/// The future type
// for task.rs
export
future_pipe
;
#[doc
=
"The future type"
]
enum
future
<
A
>
=
{
mut
v
:
either
<@
A
,
fn
@
()
->
A
>
};
...
...
@@ -56,16 +59,34 @@ fn from_value<A>(+val: A) -> future<A> {
})
}
fn
from_port
<
A
:
send
>
(
-
port
:
comm
::
port
<
A
>
)
->
future
<
A
>
{
/*!
* Create a future from a port
*
* The first time that the value is requested the task will block
* waiting for the result to be received on the port.
*/
fn
macros
()
{
#
macro
[
[
#
recv
[
chan
],
chan
.recv
()(
chan
)]
];
#
macro
[
[
#
move
[
x
],
unsafe
{
let
y
<-
*
ptr
::
addr_of
(
x
);
y
}]
];
}
do
from_fn
{
comm
::
recv
(
port
)
fn
from_port
<
A
:
send
>
(
-
port
:
future_pipe
::
client
::
waiting
<
A
>
)
->
future
<
A
>
{
#[doc
=
"
Create a future from a port
The first time that the value is requested the task will block
waiting for the result to be received on the port.
"
]
;
import
future_pipe
::
client
::
recv
;
let
port
=
~
mut
some
(
port
);
do
from_fn
|
move
port
|
{
let
mut
port_
=
none
;
port_
<->
*
port
;
let
port
=
option
::
unwrap
(
port_
);
alt
(
#
recv
(
port
))
{
future_pipe
::
completed
(
data
,
_
next
)
{
#
move
(
data
)
}
}
}
}
...
...
@@ -91,12 +112,9 @@ fn spawn<A:send>(+blk: fn~() -> A) -> future<A> {
* value of the future.
*/
let
mut
po
=
comm
::
port
();
let
ch
=
comm
::
chan
(
po
);
do
task
::
spawn
{
comm
::
send
(
ch
,
blk
())
};
from_port
(
po
)
from_port
(
pipes
::
spawn_service_recv
(
future_pipe
::
init
,
|
ch
|
{
future_pipe
::
server
::
completed
(
ch
,
blk
());
}))
}
fn
get
<
A
:
copy
>
(
future
:
future
<
A
>
)
->
A
{
...
...
@@ -119,6 +137,48 @@ fn with<A,B>(future: future<A>, blk: fn(A) -> B) -> B {
blk
(
*
v
)
}
// The pipe protocol, generated by pipec
mod
future_pipe
{
fn
init
<
T
:
send
>
()
->
(
client
::
waiting
<
T
>
,
server
::
waiting
<
T
>
)
{
{
let
(
s
,
c
)
=
pipes
::
entangle
();
(
c
,
s
)
}
}
enum
waiting
<
T
:
send
>
{
completed
(
T
,
client
::
terminated
),
}
enum
terminated
{
}
mod
client
{
impl
recv
<
T
:
send
>
for
waiting
<
T
>
{
fn
recv
()
->
extern
fn
(
+
waiting
<
T
>
)
->
future_pipe
::
waiting
<
T
>
{
fn
recv
<
T
:
send
>
(
+
pipe
:
waiting
<
T
>
)
->
future_pipe
::
waiting
<
T
>
{
option
::
unwrap
(
pipes
::
recv
(
pipe
))
}
recv
}
}
type
waiting
<
T
:
send
>
=
pipes
::
recv_packet
<
future_pipe
::
waiting
<
T
>>
;
type
terminated
=
pipes
::
send_packet
<
future_pipe
::
terminated
>
;
}
mod
server
{
fn
completed
<
T
:
send
>
(
+
pipe
:
waiting
<
T
>
,
+
x_0
:
T
)
->
terminated
{
{
let
(
s
,
c
)
=
pipes
::
entangle
();
let
message
=
future_pipe
::
completed
(
x_0
,
s
);
pipes
::
send
(
pipe
,
message
);
c
}
}
type
waiting
<
T
:
send
>
=
pipes
::
send_packet
<
future_pipe
::
waiting
<
T
>>
;
impl
recv
for
terminated
{
fn
recv
()
->
extern
fn
(
+
terminated
)
->
future_pipe
::
terminated
{
fn
recv
(
+
pipe
:
terminated
)
->
future_pipe
::
terminated
{
option
::
unwrap
(
pipes
::
recv
(
pipe
))
}
recv
}
}
type
terminated
=
pipes
::
recv_packet
<
future_pipe
::
terminated
>
;
}
}
#[test]
fn
test_from_value
()
{
let
f
=
from_value
(
"snail"
);
...
...
@@ -127,9 +187,8 @@ fn test_from_value() {
#[test]
fn
test_from_port
()
{
let
po
=
comm
::
port
();
let
ch
=
comm
::
chan
(
po
);
comm
::
send
(
ch
,
"whale"
);
let
(
po
,
ch
)
=
future_pipe
::
init
();
future_pipe
::
server
::
completed
(
ch
,
"whale"
);
let
f
=
from_port
(
po
);
assert
get
(
f
)
==
"whale"
;
}
...
...
src/libcore/pipes.rs
浏览文件 @
89bdd481
...
...
@@ -239,3 +239,22 @@ fn spawn_service<T: send>(
client
}
fn
spawn_service_recv
<
T
:
send
>
(
init
:
native
fn
()
->
(
recv_packet
<
T
>
,
send_packet
<
T
>
),
+
service
:
fn
~
(
+
send_packet
<
T
>
))
->
recv_packet
<
T
>
{
let
(
client
,
server
)
=
init
();
// This is some nasty gymnastics required to safely move the pipe
// into a new task.
let
server
=
~
mut
some
(
server
);
do
task
::
spawn
|
move
service
|
{
let
mut
server_
=
none
;
server_
<->
*
server
;
service
(
option
::
unwrap
(
server_
))
}
client
}
src/libcore/task.rs
浏览文件 @
89bdd481
...
...
@@ -308,11 +308,21 @@ fn future_result(builder: builder) -> future::future<task_result> {
fn
future_task
(
builder
:
builder
)
->
future
::
future
<
task
>
{
//! Get a future representing the handle to the new task
let
mut
po
=
comm
::
port
();
let
ch
=
comm
::
chan
(
po
);
do
add_wrapper
(
builder
)
|
body
|
{
fn
~
()
{
comm
::
send
(
ch
,
get_task
());
import
future
::
future_pipe
;
let
(
po
,
ch
)
=
future_pipe
::
init
();
let
ch
=
~
mut
some
(
ch
);
do
add_wrapper
(
builder
)
|
body
,
move
ch
|
{
let
ch
=
{
let
mut
t
=
none
;
t
<->
*
ch
;
~
mut
t
};
fn
~
(
move
ch
)
{
let
mut
po
=
none
;
po
<->
*
ch
;
future_pipe
::
server
::
completed
(
option
::
unwrap
(
po
),
get_task
());
body
();
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录