Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
d35ebcb4
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,发现更多精彩内容 >>
提交
d35ebcb4
编写于
12月 23, 2014
作者:
F
Flavio Percoco
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Make Barrier and Condvar Sync/Send
上级
607f6071
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
36 addition
and
12 deletion
+36
-12
src/libstd/c_vec.rs
src/libstd/c_vec.rs
+4
-4
src/libstd/sync/barrier.rs
src/libstd/sync/barrier.rs
+7
-0
src/libstd/sync/condvar.rs
src/libstd/sync/condvar.rs
+6
-0
src/libstd/sync/mutex.rs
src/libstd/sync/mutex.rs
+13
-8
src/libstd/sync/rwlock.rs
src/libstd/sync/rwlock.rs
+6
-0
未找到文件。
src/libstd/c_vec.rs
浏览文件 @
d35ebcb4
...
...
@@ -180,12 +180,12 @@ mod tests {
fn
malloc
(
n
:
uint
)
->
CVec
<
u8
>
{
unsafe
{
let
mem
=
libc
::
malloc
(
n
as
libc
::
size_t
);
if
mem
.is_null
()
{
::
alloc
::
oom
()
}
let
mem
=
ptr
::
Unique
(
libc
::
malloc
(
n
as
libc
::
size_t
)
);
if
mem
.
0
.
is_null
()
{
::
alloc
::
oom
()
}
CVec
::
new_with_dtor
(
mem
as
*
mut
u8
,
CVec
::
new_with_dtor
(
mem
.0
as
*
mut
u8
,
n
,
move
||
{
libc
::
free
(
mem
as
*
mut
libc
::
c_void
);
})
move
||
{
libc
::
free
(
mem
.0
as
*
mut
libc
::
c_void
);
})
}
}
...
...
src/libstd/sync/barrier.rs
浏览文件 @
d35ebcb4
...
...
@@ -8,6 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
use
kinds
::{
Send
,
Sync
};
use
sync
::{
Mutex
,
Condvar
};
/// A barrier enables multiple tasks to synchronize the beginning
...
...
@@ -35,12 +36,18 @@ pub struct Barrier {
num_threads
:
uint
,
}
unsafe
impl
Send
for
Barrier
{}
unsafe
impl
Sync
for
Barrier
{}
// The inner state of a double barrier
struct
BarrierState
{
count
:
uint
,
generation_id
:
uint
,
}
unsafe
impl
Send
for
BarrierState
{}
unsafe
impl
Sync
for
BarrierState
{}
impl
Barrier
{
/// Create a new barrier that can block a given number of threads.
///
...
...
src/libstd/sync/condvar.rs
浏览文件 @
d35ebcb4
...
...
@@ -58,6 +58,9 @@
/// ```
pub
struct
Condvar
{
inner
:
Box
<
StaticCondvar
>
}
unsafe
impl
Send
for
Condvar
{}
unsafe
impl
Sync
for
Condvar
{}
/// Statically allocated condition variables.
///
/// This structure is identical to `Condvar` except that it is suitable for use
...
...
@@ -75,6 +78,9 @@ pub struct StaticCondvar {
mutex
:
AtomicUint
,
}
unsafe
impl
Send
for
StaticCondvar
{}
unsafe
impl
Sync
for
StaticCondvar
{}
/// Constant initializer for a statically allocated condition variable.
pub
const
CONDVAR_INIT
:
StaticCondvar
=
StaticCondvar
{
inner
:
sys
::
CONDVAR_INIT
,
...
...
src/libstd/sync/mutex.rs
浏览文件 @
d35ebcb4
...
...
@@ -284,6 +284,11 @@ mod test {
use
thread
::
Thread
;
use
sync
::{
Arc
,
Mutex
,
StaticMutex
,
MUTEX_INIT
,
Condvar
};
struct
Packet
<
T
>
(
Arc
<
(
Mutex
<
T
>
,
Condvar
)
>
);
unsafe
impl
<
T
:
'static
+
Send
>
Send
for
Packet
<
T
>
{}
unsafe
impl
<
T
>
Sync
for
Packet
<
T
>
{}
#[test]
fn
smoke
()
{
let
m
=
Mutex
::
new
(());
...
...
@@ -343,19 +348,19 @@ fn try_lock() {
#[test]
fn
test_mutex_arc_condvar
()
{
let
arc
=
Arc
::
new
((
Mutex
::
new
(
false
),
Condvar
::
new
(
)));
let
arc2
=
arc
.clone
(
);
let
packet
=
Packet
(
Arc
::
new
((
Mutex
::
new
(
false
),
Condvar
::
new
()
)));
let
packet2
=
Packet
(
packet
.0
.clone
()
);
let
(
tx
,
rx
)
=
channel
();
spawn
(
move
||
{
// wait until parent gets in
rx
.recv
();
let
&
(
ref
lock
,
ref
cvar
)
=
&*
arc2
;
let
&
(
ref
lock
,
ref
cvar
)
=
&*
packet2
.0
;
let
mut
lock
=
lock
.lock
();
*
lock
=
true
;
cvar
.notify_one
();
});
let
&
(
ref
lock
,
ref
cvar
)
=
&*
arc
;
let
&
(
ref
lock
,
ref
cvar
)
=
&*
packet
.0
;
let
lock
=
lock
.lock
();
tx
.send
(());
assert
!
(
!*
lock
);
...
...
@@ -367,20 +372,20 @@ fn test_mutex_arc_condvar() {
#[test]
#[should_fail]
fn
test_arc_condvar_poison
()
{
let
arc
=
Arc
::
new
((
Mutex
::
new
(
1
i
),
Condvar
::
new
(
)));
let
arc2
=
arc
.clone
(
);
let
packet
=
Packet
(
Arc
::
new
((
Mutex
::
new
(
1
i
),
Condvar
::
new
()
)));
let
packet2
=
Packet
(
packet
.0
.clone
()
);
let
(
tx
,
rx
)
=
channel
();
spawn
(
move
||
{
rx
.recv
();
let
&
(
ref
lock
,
ref
cvar
)
=
&*
arc2
;
let
&
(
ref
lock
,
ref
cvar
)
=
&*
packet2
.0
;
let
_
g
=
lock
.lock
();
cvar
.notify_one
();
// Parent should fail when it wakes up.
panic!
();
});
let
&
(
ref
lock
,
ref
cvar
)
=
&*
arc
;
let
&
(
ref
lock
,
ref
cvar
)
=
&*
packet
.0
;
let
lock
=
lock
.lock
();
tx
.send
(());
while
*
lock
==
1
{
...
...
src/libstd/sync/rwlock.rs
浏览文件 @
d35ebcb4
...
...
@@ -60,6 +60,9 @@ pub struct RWLock<T> {
data
:
UnsafeCell
<
T
>
,
}
unsafe
impl
<
T
:
'static
+
Send
>
Send
for
RWLock
<
T
>
{}
unsafe
impl
<
T
>
Sync
for
RWLock
<
T
>
{}
/// Structure representing a statically allocated RWLock.
///
/// This structure is intended to be used inside of a `static` and will provide
...
...
@@ -88,6 +91,9 @@ pub struct StaticRWLock {
poison
:
UnsafeCell
<
poison
::
Flag
>
,
}
unsafe
impl
Send
for
StaticRWLock
{}
unsafe
impl
Sync
for
StaticRWLock
{}
/// Constant initialization for a statically-initialized rwlock.
pub
const
RWLOCK_INIT
:
StaticRWLock
=
StaticRWLock
{
inner
:
sys
::
RWLOCK_INIT
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录