Skip to content

Commit 670058d

Browse files
committed
---
yaml --- r: 108342 b: refs/heads/dist-snap c: 5d86e24 h: refs/heads/master v: v3
1 parent 2e0ca9a commit 670058d

File tree

2 files changed

+38
-27
lines changed

2 files changed

+38
-27
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ refs/heads/try: f64fdf524a434f0e5cd0bc91d09c144723f3c90d
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: 147ecfdd8221e4a4d4e090486829a06da1e0ca3c
9-
refs/heads/dist-snap: 0f4294b4e2887ffe9d0532564521c456bb89a780
9+
refs/heads/dist-snap: 5d86e24ab27dba0a773bd00a98e3845ece0ebf16
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503
1212
refs/heads/try3: 9387340aab40a73e8424c48fd42f0c521a4875c0

branches/dist-snap/src/libstd/unstable/mutex.rs

Lines changed: 37 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -27,31 +27,34 @@
2727
//!
2828
//! It is not recommended to use this type for idiomatic rust use. These types
2929
//! are appropriate where no other options are available, but other rust
30-
//! concurrency primitives should be used before them.
30+
//! concurrency primitives should be used before them: the `sync` crate defines
31+
//! `StaticMutex` and `Mutex` types.
3132
//!
3233
//! # Example
3334
//!
34-
//! use std::unstable::mutex::{StaticNativeMutex, NATIVE_MUTEX_INIT};
35+
//! ```rust
36+
//! use std::unstable::mutex::{NativeMutex, StaticNativeMutex, NATIVE_MUTEX_INIT};
3537
//!
36-
//! // Use a statically initialized mutex
37-
//! static mut LOCK: StaticNativeMutex = NATIVE_MUTEX_INIT;
38+
//! // Use a statically initialized mutex
39+
//! static mut LOCK: StaticNativeMutex = NATIVE_MUTEX_INIT;
3840
//!
39-
//! unsafe {
40-
//! let _guard = LOCK.lock();
41-
//! } // automatically unlocked here
41+
//! unsafe {
42+
//! let _guard = LOCK.lock();
43+
//! } // automatically unlocked here
4244
//!
43-
//! // Use a normally initialized mutex
44-
//! unsafe {
45-
//! let mut lock = NativeMutex::new();
45+
//! // Use a normally initialized mutex
46+
//! unsafe {
47+
//! let mut lock = NativeMutex::new();
4648
//!
47-
//! {
48-
//! let _guard = lock.lock();
49-
//! } // unlocked here
49+
//! {
50+
//! let _guard = lock.lock();
51+
//! } // unlocked here
5052
//!
51-
//! // sometimes the RAII guard isn't appropriate
52-
//! lock.lock_noguard();
53-
//! lock.unlock_noguard();
54-
//! } // `lock` is deallocated here
53+
//! // sometimes the RAII guard isn't appropriate
54+
//! lock.lock_noguard();
55+
//! lock.unlock_noguard();
56+
//! } // `lock` is deallocated here
57+
//! ```
5558
5659
#[allow(non_camel_case_types)];
5760

@@ -61,7 +64,8 @@ use ops::Drop;
6164
/// A native mutex suitable for storing in statics (that is, it has
6265
/// the `destroy` method rather than a destructor).
6366
///
64-
/// Prefer the `NativeMutex` type where possible.
67+
/// Prefer the `NativeMutex` type where possible, since that does not
68+
/// require manual deallocation.
6569
pub struct StaticNativeMutex {
6670
priv inner: imp::Mutex,
6771
}
@@ -128,14 +132,16 @@ impl StaticNativeMutex {
128132

129133
/// Acquire the lock without creating a `LockGuard`.
130134
///
131-
/// Prefer using `.lock`.
135+
/// These needs to be paired with a call to `.unlock_noguard`. Prefer using
136+
/// `.lock`.
132137
pub unsafe fn lock_noguard(&mut self) { self.inner.lock() }
133138

134139
/// Attempts to acquire the lock without creating a
135140
/// `LockGuard`. The value returned is whether the lock was
136141
/// acquired or not.
137142
///
138-
/// Prefer using `.trylock`.
143+
/// If `true` is returned, this needs to be paired with a call to
144+
/// `.unlock_noguard`. Prefer using `.trylock`.
139145
pub unsafe fn trylock_noguard(&mut self) -> bool {
140146
self.inner.trylock()
141147
}
@@ -175,11 +181,14 @@ impl NativeMutex {
175181
/// # Example
176182
/// ```rust
177183
/// use std::unstable::mutex::NativeMutex;
178-
/// let mut lock = NativeMutex::new();
179184
/// unsafe {
180-
/// let _guard = lock.lock();
181-
/// // critical section...
182-
/// } // automatically unlocked in `_guard`'s destructor
185+
/// let mut lock = NativeMutex::new();
186+
///
187+
/// {
188+
/// let _guard = lock.lock();
189+
/// // critical section...
190+
/// } // automatically unlocked in `_guard`'s destructor
191+
/// }
183192
/// ```
184193
pub unsafe fn lock<'a>(&'a mut self) -> LockGuard<'a> {
185194
self.inner.lock()
@@ -193,14 +202,16 @@ impl NativeMutex {
193202

194203
/// Acquire the lock without creating a `LockGuard`.
195204
///
196-
/// Prefer using `.lock`.
205+
/// These needs to be paired with a call to `.unlock_noguard`. Prefer using
206+
/// `.lock`.
197207
pub unsafe fn lock_noguard(&mut self) { self.inner.lock_noguard() }
198208

199209
/// Attempts to acquire the lock without creating a
200210
/// `LockGuard`. The value returned is whether the lock was
201211
/// acquired or not.
202212
///
203-
/// Prefer using `.trylock`.
213+
/// If `true` is returned, this needs to be paired with a call to
214+
/// `.unlock_noguard`. Prefer using `.trylock`.
204215
pub unsafe fn trylock_noguard(&mut self) -> bool {
205216
self.inner.trylock_noguard()
206217
}

0 commit comments

Comments
 (0)