Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
f30c5ea6
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,发现更多精彩内容 >>
提交
f30c5ea6
编写于
1月 09, 2012
作者:
M
Marijn Haverbeke
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Remove leftover comm.rs in std
(The actual comm module lives in core.)
上级
0945fcf1
变更
6
显示空白变更内容
内联
并排
Showing
6 changed file
with
7 addition
and
199 deletion
+7
-199
src/libcore/comm.rs
src/libcore/comm.rs
+0
-2
src/libstd/comm.rs
src/libstd/comm.rs
+0
-186
src/libstd/std.rc
src/libstd/std.rc
+1
-2
src/test/run-pass/sendfn-deep-copy.rs
src/test/run-pass/sendfn-deep-copy.rs
+2
-3
src/test/run-pass/sendfn-generic-fn.rs
src/test/run-pass/sendfn-generic-fn.rs
+2
-3
src/test/run-pass/sendfn-spawn-with-fn-arg.rs
src/test/run-pass/sendfn-spawn-with-fn-arg.rs
+2
-3
未找到文件。
src/libcore/comm.rs
浏览文件 @
f30c5ea6
...
@@ -15,8 +15,6 @@
...
@@ -15,8 +15,6 @@
Example:
Example:
> import std::{task, comm, io};
>
> let p = comm::port();
> let p = comm::port();
> task::spawn(comm::chan(p), fn (c: chan<str>) {
> task::spawn(comm::chan(p), fn (c: chan<str>) {
> comm::send(c, "Hello, World");
> comm::send(c, "Hello, World");
...
...
src/libstd/comm.rs
已删除
100644 → 0
浏览文件 @
0945fcf1
/*
Module: comm
Communication between tasks
Communication between tasks is facilitated by ports (in the receiving task),
and channels (in the sending task). Any number of channels may feed into a
single port.
Ports and channels may only transmit values of unique types; that is,
values that are statically guaranteed to be accessed by a single
'owner' at a time. Unique types include scalars, vectors, strings,
and records, tags, tuples and unique boxes (~T) thereof. Most notably,
shared boxes (@T) may not be transmitted across channels.
Example:
> use std::{task, comm, io};
>
> let p = comm::port();
> task::spawn(comm::chan(p), fn (c: chan<str>) {
> comm::send(c, "Hello, World");
> });
>
> io::println(comm::recv(p));
*/
import
sys
;
import
task
;
import
core
::
ctypes
;
export
send
;
export
recv
;
export
chan
;
export
port
;
#[abi
=
"cdecl"
]
native
mod
rustrt
{
type
void
;
type
rust_port
;
fn
chan_id_send
<
T
:
send
>
(
t
:
*
sys
::
type_desc
,
target_task
:
task
::
task
,
target_port
:
port_id
,
data
:
T
)
->
ctypes
::
uintptr_t
;
fn
new_port
(
unit_sz
:
uint
)
->
*
rust_port
;
fn
del_port
(
po
:
*
rust_port
);
fn
rust_port_detach
(
po
:
*
rust_port
);
fn
get_port_id
(
po
:
*
rust_port
)
->
port_id
;
fn
rust_port_size
(
po
:
*
rust_port
)
->
ctypes
::
size_t
;
fn
port_recv
(
dptr
:
*
uint
,
po
:
*
rust_port
,
yield
:
*
ctypes
::
uintptr_t
,
killed
:
*
ctypes
::
uintptr_t
);
}
#[abi
=
"rust-intrinsic"
]
native
mod
rusti
{
fn
call_with_retptr
<
T
:
send
>
(
&&
f
:
fn
@
(
*
uint
))
->
T
;
}
type
port_id
=
int
;
// It's critical that this only have one variant, so it has a record
// layout, and will work in the rust_task structure in task.rs.
/*
Type: chan
A communication endpoint that can send messages. Channels send
messages to ports.
Each channel is bound to a port when the channel is constructed, so
the destination port for a channel must exist before the channel
itself.
Channels are weak: a channel does not keep the port it is bound to alive.
If a channel attempts to send data to a dead port that data will be silently
dropped.
Channels may be duplicated and themselves transmitted over other channels.
*/
tag
chan
<
T
:
send
>
{
chan_t
(
task
::
task
,
port_id
);
}
resource
port_ptr
<
T
:
send
>
(
po
:
*
rustrt
::
rust_port
)
{
// Once the port is detached it's guaranteed not to receive further
// messages
rustrt
::
rust_port_detach
(
po
);
// Drain the port so that all the still-enqueued items get dropped
while
rustrt
::
rust_port_size
(
po
)
>
0u
{
// FIXME: For some reason if we don't assign to something here
// we end up with invalid reads in the drop glue.
let
_
t
=
recv_
::
<
T
>
(
po
);
}
rustrt
::
del_port
(
po
);
}
/*
Type: port
A communication endpoint that can receive messages. Ports receive
messages from channels.
Each port has a unique per-task identity and may not be replicated or
transmitted. If a port value is copied, both copies refer to the same port.
Ports may be associated with multiple <chan>s.
*/
tag
port
<
T
:
send
>
{
port_t
(
@
port_ptr
<
T
>
);
}
/*
Function: send
Sends data over a channel.
The sent data is moved into the channel, whereupon the caller loses access
to it.
*/
fn
send
<
T
:
send
>
(
ch
:
chan
<
T
>
,
-
data
:
T
)
{
let
chan_t
(
t
,
p
)
=
ch
;
let
res
=
rustrt
::
chan_id_send
(
sys
::
get_type_desc
::
<
T
>
(),
t
,
p
,
data
);
if
res
!=
0u
unsafe
{
// Data sent successfully
unsafe
::
leak
(
data
);
}
task
::
yield
();
}
/*
Function: port
Constructs a port.
*/
fn
port
<
T
:
send
>
()
->
port
<
T
>
{
port_t
(
@
port_ptr
(
rustrt
::
new_port
(
sys
::
size_of
::
<
T
>
())))
}
/*
Function: recv
Receive from a port.
If no data is available on the port then the task will block until data
becomes available.
*/
fn
recv
<
T
:
send
>
(
p
:
port
<
T
>
)
->
T
{
recv_
(
***
p
)
}
// Receive on a raw port pointer
fn
recv_
<
T
:
send
>
(
p
:
*
rustrt
::
rust_port
)
->
T
{
// FIXME: Due to issue 1185 we can't use a return pointer when
// calling C code, and since we can't create our own return
// pointer on the stack, we're going to call a little intrinsic
// that will grab the value of the return pointer, then call this
// function, which we will then use to call the runtime.
fn
recv
(
dptr
:
*
uint
,
port
:
*
rustrt
::
rust_port
,
yield
:
*
ctypes
::
uintptr_t
,
killed
:
*
ctypes
::
uintptr_t
)
unsafe
{
rustrt
::
port_recv
(
dptr
,
port
,
yield
,
killed
);
}
let
yield
=
0u
;
let
yieldp
=
ptr
::
addr_of
(
yield
);
let
killed
=
0u
;
let
killedp
=
ptr
::
addr_of
(
killed
);
let
res
=
rusti
::
call_with_retptr
(
bind
recv
(
_
,
p
,
yieldp
,
killedp
));
if
killed
!=
0u
{
fail
"killed"
;
}
if
yield
!=
0u
{
// Data isn't available yet, so res has not been initialized.
task
::
yield
();
}
ret
res
;
}
/*
Function: chan
Constructs a channel.
The channel is bound to the port used to construct it.
*/
fn
chan
<
T
:
send
>
(
p
:
port
<
T
>
)
->
chan
<
T
>
{
chan_t
(
task
::
get_task
(),
rustrt
::
get_port_id
(
***
p
))
}
src/libstd/std.rc
浏览文件 @
f30c5ea6
...
@@ -7,7 +7,7 @@
...
@@ -7,7 +7,7 @@
#[license = "MIT"];
#[license = "MIT"];
#[crate_type = "lib"];
#[crate_type = "lib"];
export
comm,
fs, io, net, run, uv;
export fs, io, net, run, uv;
export c_vec, four, tri, util;
export c_vec, four, tri, util;
export bitv, deque, fun_treemap, list, map, smallintmap, sort, treemap, ufind;
export bitv, deque, fun_treemap, list, map, smallintmap, sort, treemap, ufind;
export rope;
export rope;
...
@@ -19,7 +19,6 @@ export generic_os, os, os_fs;
...
@@ -19,7 +19,6 @@ export generic_os, os, os_fs;
// General io and system-services modules
// General io and system-services modules
mod comm;
mod fs;
mod fs;
mod io;
mod io;
mod net;
mod net;
...
...
src/test/run-pass/sendfn-deep-copy.rs
浏览文件 @
f30c5ea6
use
std
;
use
std
;
import
std
::
comm
;
import
comm
::
chan
;
import
std
::
comm
::
chan
;
import
comm
::
send
;
import
std
::
comm
::
send
;
fn
main
()
{
test05
();
}
fn
main
()
{
test05
();
}
...
...
src/test/run-pass/sendfn-generic-fn.rs
浏览文件 @
f30c5ea6
use
std
;
use
std
;
import
std
::
comm
;
import
comm
::
chan
;
import
std
::
comm
::
chan
;
import
comm
::
send
;
import
std
::
comm
::
send
;
fn
main
()
{
test05
();
}
fn
main
()
{
test05
();
}
...
...
src/test/run-pass/sendfn-spawn-with-fn-arg.rs
浏览文件 @
f30c5ea6
use
std
;
use
std
;
import
std
::
comm
;
import
comm
::
chan
;
import
std
::
comm
::
chan
;
import
comm
::
send
;
import
std
::
comm
::
send
;
fn
main
()
{
test05
();
}
fn
main
()
{
test05
();
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录