Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
5d86e24a
R
Rust
项目概览
int
/
Rust
11 个月 前同步成功
通知
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,发现更多精彩内容 >>
提交
5d86e24a
编写于
2月 15, 2014
作者:
H
Huon Wilson
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
std::unstable::mutex: streamline & clarify documentation.
上级
0f4294b4
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
37 addition
and
26 deletion
+37
-26
src/libstd/unstable/mutex.rs
src/libstd/unstable/mutex.rs
+37
-26
未找到文件。
src/libstd/unstable/mutex.rs
浏览文件 @
5d86e24a
...
...
@@ -27,31 +27,34 @@
//!
//! It is not recommended to use this type for idiomatic rust use. These types
//! are appropriate where no other options are available, but other rust
//! concurrency primitives should be used before them.
//! concurrency primitives should be used before them: the `sync` crate defines
//! `StaticMutex` and `Mutex` types.
//!
//! # Example
//!
//! use std::unstable::mutex::{StaticNativeMutex, NATIVE_MUTEX_INIT};
//! ```rust
//! use std::unstable::mutex::{NativeMutex, StaticNativeMutex, NATIVE_MUTEX_INIT};
//!
//!
// Use a statically initialized mutex
//!
static mut LOCK: StaticNativeMutex = NATIVE_MUTEX_INIT;
//! // Use a statically initialized mutex
//! static mut LOCK: StaticNativeMutex = NATIVE_MUTEX_INIT;
//!
//!
unsafe {
//!
let _guard = LOCK.lock();
//!
} // automatically unlocked here
//! unsafe {
//! let _guard = LOCK.lock();
//! } // automatically unlocked here
//!
//!
// Use a normally initialized mutex
//!
unsafe {
//!
let mut lock = NativeMutex::new();
//! // Use a normally initialized mutex
//! unsafe {
//! let mut lock = NativeMutex::new();
//!
//!
{
//!
let _guard = lock.lock();
//!
} // unlocked here
//! {
//! let _guard = lock.lock();
//! } // unlocked here
//!
//! // sometimes the RAII guard isn't appropriate
//! lock.lock_noguard();
//! lock.unlock_noguard();
//! } // `lock` is deallocated here
//! // sometimes the RAII guard isn't appropriate
//! lock.lock_noguard();
//! lock.unlock_noguard();
//! } // `lock` is deallocated here
//! ```
#[allow(non_camel_case_types)]
;
...
...
@@ -61,7 +64,8 @@
/// A native mutex suitable for storing in statics (that is, it has
/// the `destroy` method rather than a destructor).
///
/// Prefer the `NativeMutex` type where possible.
/// Prefer the `NativeMutex` type where possible, since that does not
/// require manual deallocation.
pub
struct
StaticNativeMutex
{
priv
inner
:
imp
::
Mutex
,
}
...
...
@@ -128,14 +132,16 @@ pub unsafe fn trylock<'a>(&'a mut self) -> Option<LockGuard<'a>> {
/// Acquire the lock without creating a `LockGuard`.
///
/// Prefer using `.lock`.
/// These needs to be paired with a call to `.unlock_noguard`. Prefer using
/// `.lock`.
pub
unsafe
fn
lock_noguard
(
&
mut
self
)
{
self
.inner
.lock
()
}
/// Attempts to acquire the lock without creating a
/// `LockGuard`. The value returned is whether the lock was
/// acquired or not.
///
/// Prefer using `.trylock`.
/// If `true` is returned, this needs to be paired with a call to
/// `.unlock_noguard`. Prefer using `.trylock`.
pub
unsafe
fn
trylock_noguard
(
&
mut
self
)
->
bool
{
self
.inner
.trylock
()
}
...
...
@@ -175,11 +181,14 @@ pub unsafe fn new() -> NativeMutex {
/// # Example
/// ```rust
/// use std::unstable::mutex::NativeMutex;
/// let mut lock = NativeMutex::new();
/// unsafe {
/// let _guard = lock.lock();
/// // critical section...
/// } // automatically unlocked in `_guard`'s destructor
/// let mut lock = NativeMutex::new();
///
/// {
/// let _guard = lock.lock();
/// // critical section...
/// } // automatically unlocked in `_guard`'s destructor
/// }
/// ```
pub
unsafe
fn
lock
<
'a
>
(
&
'a
mut
self
)
->
LockGuard
<
'a
>
{
self
.inner
.lock
()
...
...
@@ -193,14 +202,16 @@ pub unsafe fn trylock<'a>(&'a mut self) -> Option<LockGuard<'a>> {
/// Acquire the lock without creating a `LockGuard`.
///
/// Prefer using `.lock`.
/// These needs to be paired with a call to `.unlock_noguard`. Prefer using
/// `.lock`.
pub
unsafe
fn
lock_noguard
(
&
mut
self
)
{
self
.inner
.lock_noguard
()
}
/// Attempts to acquire the lock without creating a
/// `LockGuard`. The value returned is whether the lock was
/// acquired or not.
///
/// Prefer using `.trylock`.
/// If `true` is returned, this needs to be paired with a call to
/// `.unlock_noguard`. Prefer using `.trylock`.
pub
unsafe
fn
trylock_noguard
(
&
mut
self
)
->
bool
{
self
.inner
.trylock_noguard
()
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录