Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
4cfb92f4
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,发现更多精彩内容 >>
提交
4cfb92f4
编写于
8月 23, 2012
作者:
B
Ben Blum
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Use region variance to remove a bunch of unsafety in sync/arc (#2282)
上级
8d00603d
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
15 addition
and
54 deletion
+15
-54
src/libstd/arc.rs
src/libstd/arc.rs
+12
-45
src/libstd/sync.rs
src/libstd/sync.rs
+3
-9
未找到文件。
src/libstd/arc.rs
浏览文件 @
4cfb92f4
...
...
@@ -182,16 +182,9 @@ unsafe fn access_cond<U>(blk: fn(x: &x/mut T, c: &c/condvar) -> U) -> U {
do
(
&
state
.lock
)
.lock_cond
|
cond
|
{
check_poison
(
true
,
state
.failed
);
let
_
z
=
poison_on_fail
(
&
mut
state
.failed
);
/*
blk
(
&
mut
state
.data
,
&
condvar
{
is_mutex
:
true
,
failed
:
&
mut
state
.failed
,
cond
:
cond
})
*/
// FIXME(#2282) region variance
let
fref
=
unsafe
{
unsafe
::
transmute_mut_region
(
&
mut
state
.failed
)
};
let
cvar
=
condvar
{
is_mutex
:
true
,
failed
:
fref
,
cond
:
cond
};
blk
(
&
mut
state
.data
,
unsafe
{
unsafe
::
transmute_region
(
&
cvar
)
}
)
}
}
}
...
...
@@ -302,17 +295,9 @@ fn write_cond<U>(blk: fn(x: &x/mut T, c: &c/condvar) -> U) -> U {
do
borrow_rwlock
(
state
)
.write_cond
|
cond
|
{
check_poison
(
false
,
state
.failed
);
let
_
z
=
poison_on_fail
(
&
mut
state
.failed
);
/*
blk
(
&
mut
state
.data
,
&
condvar
{
is_mutex
:
false
,
failed
:
&
mut
state
.failed
,
cond
:
cond
})
*/
// FIXME(#2282): Need region variance to use the commented-out
// code above instead of this casting mess
let
fref
=
unsafe
{
unsafe
::
transmute_mut_region
(
&
mut
state
.failed
)
};
let
cvar
=
condvar
{
is_mutex
:
false
,
failed
:
fref
,
cond
:
cond
};
blk
(
&
mut
state
.data
,
unsafe
{
unsafe
::
transmute_region
(
&
cvar
)
}
)
}
}
/**
...
...
@@ -353,11 +338,8 @@ fn write_downgrade<U>(blk: fn(+rw_write_mode<T>) -> U) -> U {
let
state
=
unsafe
{
get_shared_mutable_state
(
&
self
.x
)
};
do
borrow_rwlock
(
state
)
.write_downgrade
|
write_mode
|
{
check_poison
(
false
,
state
.failed
);
// FIXME(#2282) need region variance to avoid having to cast here
let
(
data
,
failed
)
=
unsafe
{
(
unsafe
::
transmute_mut_region
(
&
mut
state
.data
),
unsafe
::
transmute_mut_region
(
&
mut
state
.failed
))
};
blk
(
rw_write_mode
((
data
,
write_mode
,
poison_on_fail
(
failed
))))
blk
(
rw_write_mode
((
&
mut
state
.data
,
write_mode
,
poison_on_fail
(
&
mut
state
.failed
))))
}
}
...
...
@@ -401,8 +383,8 @@ fn unwrap_rw_arc<T: const send>(+arc: rw_arc<T>) -> T {
// lock it. This wraps the unsafety, with the justification that the 'lock'
// field is never overwritten; only 'failed' and 'data'.
#[doc(hidden)]
fn
borrow_rwlock
<
T
:
const
send
>
(
state
:
&
mut
rw_arc_inner
<
T
>
)
->
&
rwlock
{
unsafe
{
unsafe
::
reinterpret_cast
(
&
state
.lock
)
}
fn
borrow_rwlock
<
T
:
const
send
>
(
state
:
&
r
/
mut
rw_arc_inner
<
T
>
)
->
&
r
/
rwlock
{
unsafe
{
unsafe
::
transmute_immut
(
&
mut
state
.lock
)
}
}
// FIXME (#3154) ice with struct/&<T> prevents these from being structs.
...
...
@@ -418,9 +400,7 @@ impl<T: const send> &rw_write_mode<T> {
fn
write
<
U
>
(
blk
:
fn
(
x
:
&
mut
T
)
->
U
)
->
U
{
match
*
self
{
rw_write_mode
((
data
,
ref
token
,
_
))
=>
{
// FIXME(#2282) cast to avoid region invariance
let
mode
=
unsafe
{
unsafe
::
transmute_region
(
token
)
};
do
mode
.write
{
do
token
.write
{
blk
(
data
)
}
}
...
...
@@ -430,13 +410,10 @@ fn write<U>(blk: fn(x: &mut T) -> U) -> U {
fn
write_cond
<
U
>
(
blk
:
fn
(
x
:
&
x
/
mut
T
,
c
:
&
c
/
condvar
)
->
U
)
->
U
{
match
*
self
{
rw_write_mode
((
data
,
ref
token
,
ref
poison
))
=>
{
// FIXME(#2282) cast to avoid region invariance
let
mode
=
unsafe
{
unsafe
::
transmute_region
(
token
)
};
do
mode
.write_cond
|
cond
|
{
do
token
.write_cond
|
cond
|
{
let
cvar
=
condvar
{
is_mutex
:
false
,
failed
:
poison
.failed
,
cond
:
unsafe
{
unsafe
::
reinterpret_cast
(
cond
)
}
};
// FIXME(#2282) region variance would avoid having to cast
cond
:
cond
};
blk
(
data
,
&
cvar
)
}
}
...
...
@@ -449,9 +426,7 @@ impl<T: const send> &rw_read_mode<T> {
fn
read
<
U
>
(
blk
:
fn
(
x
:
&
T
)
->
U
)
->
U
{
match
*
self
{
rw_read_mode
((
data
,
ref
token
))
=>
{
// FIXME(#2282) cast to avoid region invariance
let
mode
=
unsafe
{
unsafe
::
transmute_region
(
token
)
};
do
mode
.read
{
blk
(
data
)
}
do
token
.read
{
blk
(
data
)
}
}
}
}
...
...
@@ -593,9 +568,7 @@ fn test_rw_arc_poison_dw() {
let
arc2
=
~
arc
.clone
();
do
task
::
try
{
do
arc2
.write_downgrade
|
write_mode
|
{
// FIXME(#2282)
let
mode
=
unsafe
{
unsafe
::
transmute_region
(
&
write_mode
)
};
do
mode
.write
|
one
|
{
do
(
&
write_mode
)
.write
|
one
|
{
assert
*
one
==
2
;
}
}
...
...
@@ -637,9 +610,7 @@ fn test_rw_arc_no_poison_dr() {
do
task
::
try
{
do
arc2
.write_downgrade
|
write_mode
|
{
let
read_mode
=
arc2
.downgrade
(
write_mode
);
// FIXME(#2282)
let
mode
=
unsafe
{
unsafe
::
transmute_region
(
&
read_mode
)
};
do
mode
.read
|
one
|
{
do
(
&
read_mode
)
.read
|
one
|
{
assert
*
one
==
2
;
}
}
...
...
@@ -728,9 +699,7 @@ fn test_rw_downgrade() {
// Downgrader (us)
do
arc
.write_downgrade
|
write_mode
|
{
// FIXME(#2282)
let
mode
=
unsafe
{
unsafe
::
transmute_region
(
&
write_mode
)
};
do
mode
.write_cond
|
state
,
cond
|
{
do
(
&
write_mode
)
.write_cond
|
state
,
cond
|
{
wc1
.send
(());
// send to another writer who will wake us up
while
*
state
==
0
{
cond
.wait
();
...
...
@@ -745,9 +714,7 @@ fn test_rw_downgrade() {
}
}
let
read_mode
=
arc
.downgrade
(
write_mode
);
// FIXME(#2282)
let
mode
=
unsafe
{
unsafe
::
transmute_region
(
&
read_mode
)
};
do
mode
.read
|
state
|
{
do
(
&
read_mode
)
.read
|
state
|
{
// complete handshake with other readers
for
vec
::
each
(
reader_convos
)
|
x
|
{
match
x
{
...
...
src/libstd/sync.rs
浏览文件 @
4cfb92f4
...
...
@@ -998,16 +998,12 @@ fn lock_rwlock_in_mode(x: &rwlock, mode: rwlock_mode, blk: fn()) {
write
=>
x
.write
(
blk
),
downgrade
=>
do
x
.write_downgrade
|
mode
|
{
// FIXME(#2282)
let
mode
=
unsafe
{
unsafe
::
transmute_region
(
&
mode
)
};
mode
.write
(
blk
);
(
&
mode
)
.write
(
blk
);
},
downgrade_read
=>
do
x
.write_downgrade
|
mode
|
{
let
mode
=
x
.downgrade
(
mode
);
// FIXME(#2282)
let
mode
=
unsafe
{
unsafe
::
transmute_region
(
&
mode
)
};
mode
.read
(
blk
);
(
&
mode
)
.read
(
blk
);
},
}
}
...
...
@@ -1152,9 +1148,7 @@ fn test_rwlock_cond_broadcast_helper(num_waiters: uint, dg1: bool,
fn
lock_cond
(
x
:
&
rwlock
,
downgrade
:
bool
,
blk
:
fn
(
c
:
&
condvar
))
{
if
downgrade
{
do
x
.write_downgrade
|
mode
|
{
// FIXME(#2282)
let
mode
=
unsafe
{
unsafe
::
transmute_region
(
&
mode
)
};
mode
.write_cond
(
blk
)
(
&
mode
)
.write_cond
(
blk
)
}
}
else
{
x
.write_cond
(
blk
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录