Skip to content

Commit b87ed60

Browse files
committed
std: Rename unstable::mutex::Mutex to StaticNativeMutex.
This better reflects its purpose and design.
1 parent 75d92db commit b87ed60

File tree

13 files changed

+69
-65
lines changed

13 files changed

+69
-65
lines changed

src/libgreen/sched.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use std::rt::rtio::{RemoteCallback, PausableIdleCallback, Callback, EventLoop};
1515
use std::rt::task::BlockedTask;
1616
use std::rt::task::Task;
1717
use std::sync::deque;
18-
use std::unstable::mutex::Mutex;
18+
use std::unstable::mutex::StaticNativeMutex;
1919
use std::unstable::raw;
2020

2121
use TaskState;
@@ -764,7 +764,7 @@ impl Scheduler {
764764
// to it, but we're guaranteed that the task won't exit until we've
765765
// unlocked the lock so there's no worry of this memory going away.
766766
let cur = self.change_task_context(cur, next, |sched, mut task| {
767-
let lock: *mut Mutex = &mut task.nasty_deschedule_lock;
767+
let lock: *mut StaticNativeMutex = &mut task.nasty_deschedule_lock;
768768
unsafe {
769769
let _guard = (*lock).lock();
770770
f(sched, BlockedTask::block(task.swap()));
@@ -1453,8 +1453,8 @@ mod test {
14531453

14541454
#[test]
14551455
fn test_spawn_sched_blocking() {
1456-
use std::unstable::mutex::{Mutex, MUTEX_INIT};
1457-
static mut LOCK: Mutex = MUTEX_INIT;
1456+
use std::unstable::mutex::{StaticNativeMutex, NATIVE_MUTEX_INIT};
1457+
static mut LOCK: StaticNativeMutex = NATIVE_MUTEX_INIT;
14581458

14591459
// Testing that a task in one scheduler can block in foreign code
14601460
// without affecting other schedulers

src/libgreen/task.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use std::rt::local::Local;
2525
use std::rt::rtio;
2626
use std::rt::task::{Task, BlockedTask, SendMessage};
2727
use std::task::TaskOpts;
28-
use std::unstable::mutex::Mutex;
28+
use std::unstable::mutex::StaticNativeMutex;
2929
use std::unstable::raw;
3030

3131
use context::Context;
@@ -65,7 +65,7 @@ pub struct GreenTask {
6565
pool_id: uint,
6666

6767
// See the comments in the scheduler about why this is necessary
68-
nasty_deschedule_lock: Mutex,
68+
nasty_deschedule_lock: StaticNativeMutex,
6969
}
7070

7171
pub enum TaskType {
@@ -163,7 +163,7 @@ impl GreenTask {
163163
task_type: task_type,
164164
sched: None,
165165
handle: None,
166-
nasty_deschedule_lock: unsafe { Mutex::new() },
166+
nasty_deschedule_lock: unsafe { StaticNativeMutex::new() },
167167
task: Some(~Task::new()),
168168
}
169169
}
@@ -322,7 +322,7 @@ impl GreenTask {
322322
// uncontended except for when the task is rescheduled).
323323
fn reawaken_remotely(mut ~self) {
324324
unsafe {
325-
let mtx = &mut self.nasty_deschedule_lock as *mut Mutex;
325+
let mtx = &mut self.nasty_deschedule_lock as *mut StaticNativeMutex;
326326
let handle = self.handle.get_mut_ref() as *mut SchedHandle;
327327
let _guard = (*mtx).lock();
328328
(*handle).send(RunOnce(self));

src/libnative/bookkeeping.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@
1717
//! The green counterpart for this is bookkeeping on sched pools.
1818
1919
use std::sync::atomics;
20-
use std::unstable::mutex::{Mutex, MUTEX_INIT};
20+
use std::unstable::mutex::{StaticNativeMutex, NATIVE_MUTEX_INIT};
2121

2222
static mut TASK_COUNT: atomics::AtomicUint = atomics::INIT_ATOMIC_UINT;
23-
static mut TASK_LOCK: Mutex = MUTEX_INIT;
23+
static mut TASK_LOCK: StaticNativeMutex = NATIVE_MUTEX_INIT;
2424

2525
pub fn increment() {
2626
let _ = unsafe { TASK_COUNT.fetch_add(1, atomics::SeqCst) };

src/libnative/io/net.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,9 +218,9 @@ pub fn init() {
218218
}
219219

220220
unsafe {
221-
use std::unstable::mutex::{Mutex, MUTEX_INIT};
221+
use std::unstable::mutex::{StaticNativeMutex, NATIVE_MUTEX_INIT};
222222
static mut INITIALIZED: bool = false;
223-
static mut LOCK: Mutex = MUTEX_INIT;
223+
static mut LOCK: StaticNativeMutex = NATIVE_MUTEX_INIT;
224224

225225
let _guard = LOCK.lock();
226226
if !INITIALIZED {

src/libnative/io/timer_helper.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
2323
use std::cast;
2424
use std::rt;
25-
use std::unstable::mutex::{Mutex, MUTEX_INIT};
25+
use std::unstable::mutex::{StaticNativeMutex, NATIVE_MUTEX_INIT};
2626

2727
use bookkeeping;
2828
use io::timer::{Req, Shutdown};
@@ -37,7 +37,7 @@ static mut HELPER_CHAN: *mut Chan<Req> = 0 as *mut Chan<Req>;
3737
static mut HELPER_SIGNAL: imp::signal = 0 as imp::signal;
3838

3939
pub fn boot(helper: fn(imp::signal, Port<Req>)) {
40-
static mut LOCK: Mutex = MUTEX_INIT;
40+
static mut LOCK: StaticNativeMutex = NATIVE_MUTEX_INIT;
4141
static mut INITIALIZED: bool = false;
4242

4343
unsafe {

src/libnative/task.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use std::rt::task::{Task, BlockedTask, SendMessage};
2222
use std::rt::thread::Thread;
2323
use std::rt;
2424
use std::task::TaskOpts;
25-
use std::unstable::mutex::Mutex;
25+
use std::unstable::mutex::StaticNativeMutex;
2626
use std::unstable::stack;
2727

2828
use io;
@@ -40,7 +40,7 @@ pub fn new(stack_bounds: (uint, uint)) -> ~Task {
4040

4141
fn ops() -> ~Ops {
4242
~Ops {
43-
lock: unsafe { Mutex::new() },
43+
lock: unsafe { StaticNativeMutex::new() },
4444
awoken: false,
4545
io: io::IoFactory::new(),
4646
// these *should* get overwritten
@@ -109,7 +109,7 @@ pub fn spawn_opts(opts: TaskOpts, f: proc()) {
109109
// This structure is the glue between channels and the 1:1 scheduling mode. This
110110
// structure is allocated once per task.
111111
struct Ops {
112-
lock: Mutex, // native synchronization
112+
lock: StaticNativeMutex, // native synchronization
113113
awoken: bool, // used to prevent spurious wakeups
114114
io: io::IoFactory, // local I/O factory
115115

src/libstd/comm/shared.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ use rt::local::Local;
2828
use rt::task::{Task, BlockedTask};
2929
use rt::thread::Thread;
3030
use sync::atomics;
31-
use unstable::mutex::Mutex;
31+
use unstable::mutex::StaticNativeMutex;
3232
use vec::OwnedVector;
3333

3434
use mpsc = sync::mpsc_queue;
@@ -53,7 +53,7 @@ pub struct Packet<T> {
5353

5454
// this lock protects various portions of this implementation during
5555
// select()
56-
select_lock: Mutex,
56+
select_lock: StaticNativeMutex,
5757
}
5858

5959
pub enum Failure {
@@ -72,7 +72,7 @@ impl<T: Send> Packet<T> {
7272
channels: atomics::AtomicInt::new(2),
7373
port_dropped: atomics::AtomicBool::new(false),
7474
sender_drain: atomics::AtomicInt::new(0),
75-
select_lock: unsafe { Mutex::new() },
75+
select_lock: unsafe { StaticNativeMutex::new() },
7676
};
7777
// see comments in inherit_blocker about why we grab this lock
7878
unsafe { p.select_lock.lock_noguard() }

src/libstd/os.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,9 @@ Accessing environment variables is not generally threadsafe.
144144
Serialize access through a global lock.
145145
*/
146146
fn with_env_lock<T>(f: || -> T) -> T {
147-
use unstable::mutex::{Mutex, MUTEX_INIT};
147+
use unstable::mutex::{StaticNativeMutex, NATIVE_MUTEX_INIT};
148148

149-
static mut lock: Mutex = MUTEX_INIT;
149+
static mut lock: StaticNativeMutex = NATIVE_MUTEX_INIT;
150150

151151
unsafe {
152152
let _guard = lock.lock();

src/libstd/rt/args.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,11 @@ mod imp {
6868
use option::{Option, Some, None};
6969
use ptr::RawPtr;
7070
use iter::Iterator;
71-
use unstable::mutex::{Mutex, MUTEX_INIT};
71+
use unstable::mutex::{StaticNativeMutex, NATIVE_MUTEX_INIT};
7272
use mem;
7373

7474
static mut global_args_ptr: uint = 0;
75-
static mut lock: Mutex = MUTEX_INIT;
75+
static mut lock: StaticNativeMutex = NATIVE_MUTEX_INIT;
7676

7777
#[cfg(not(test))]
7878
pub unsafe fn init(argc: int, argv: **u8) {

src/libstd/unstable/dynamic_lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,8 @@ pub mod dl {
152152
}
153153

154154
pub fn check_for_errors_in<T>(f: || -> T) -> Result<T, ~str> {
155-
use unstable::mutex::{Mutex, MUTEX_INIT};
156-
static mut lock: Mutex = MUTEX_INIT;
155+
use unstable::mutex::{StaticNativeMutex, NATIVE_MUTEX_INIT};
156+
static mut lock: StaticNativeMutex = NATIVE_MUTEX_INIT;
157157
unsafe {
158158
// dlerror isn't thread safe, so we need to lock around this entire
159159
// sequence

src/libstd/unstable/mutex.rs

Lines changed: 37 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
//! A native mutex and condition variable type
1212
//!
1313
//! This module contains bindings to the platform's native mutex/condition
14-
//! variable primitives. It provides a single type, `Mutex`, which can be
15-
//! statically initialized via the `MUTEX_INIT` value. This object serves as both a
16-
//! mutex and a condition variable simultaneously.
14+
//! variable primitives. It provides a single type, `StaticNativeMutex`, which can be
15+
//! statically initialized via the `NATIVE_MUTEX_INIT` value. This object serves as
16+
//! both a mutex and a condition variable simultaneously.
1717
//!
1818
//! The lock is lazily initialized, but it can only be unsafely destroyed. A
1919
//! statically initialized lock doesn't necessarily have a time at which it can
@@ -27,21 +27,23 @@
2727
//!
2828
//! # Example
2929
//!
30-
//! use std::unstable::mutex::{Mutex, MUTEX_INIT};
30+
//! use std::unstable::mutex::{StaticNativeMutex, NATIVE_MUTEX_INIT};
3131
//!
3232
//! // Use a statically initialized mutex
33-
//! static mut lock: Mutex = MUTEX_INIT;
33+
//! static mut lock: StaticNativeMutex = NATIVE_MUTEX_INIT;
3434
//!
3535
//! unsafe {
36-
//! lock.lock();
37-
//! lock.unlock();
38-
//! }
36+
//! let _guard = lock.lock();
37+
//! } // automatically unlocked here
3938
//!
4039
//! // Use a normally initialized mutex
41-
//! let mut lock = Mutex::new();
4240
//! unsafe {
43-
//! lock.lock();
44-
//! lock.unlock();
41+
//! let mut lock = StaticNativeMutex::new();
42+
//!
43+
//! // sometimes the RAII guard isn't appropriate
44+
//! lock.lock_noguard();
45+
//! lock.unlock_noguard();
46+
//!
4547
//! lock.destroy();
4648
//! }
4749
@@ -50,7 +52,9 @@
5052
use option::{Option, None, Some};
5153
use ops::Drop;
5254

53-
pub struct Mutex {
55+
/// A native mutex suitable for storing in statics (that is, it has
56+
/// the `destroy` method rather than a destructor).
57+
pub struct StaticNativeMutex {
5458
priv inner: imp::Mutex,
5559
}
5660

@@ -62,33 +66,33 @@ pub struct Mutex {
6266
/// then.
6367
#[must_use]
6468
pub struct LockGuard<'a> {
65-
priv lock: &'a mut Mutex
69+
priv lock: &'a mut StaticNativeMutex
6670
}
6771

68-
pub static MUTEX_INIT: Mutex = Mutex {
72+
pub static NATIVE_MUTEX_INIT: StaticNativeMutex = StaticNativeMutex {
6973
inner: imp::MUTEX_INIT,
7074
};
7175

72-
impl Mutex {
73-
/// Creates a new mutex
74-
pub unsafe fn new() -> Mutex {
75-
Mutex { inner: imp::Mutex::new() }
76+
impl StaticNativeMutex {
77+
/// Creates a new mutex.
78+
///
79+
/// Note that a mutex created in this way needs to be explicit
80+
/// freed with a call to `destroy` or it will leak.
81+
pub unsafe fn new() -> StaticNativeMutex {
82+
StaticNativeMutex { inner: imp::Mutex::new() }
7683
}
7784

7885
/// Acquires this lock. This assumes that the current thread does not
7986
/// already hold the lock.
8087
///
8188
/// # Example
82-
/// ```
83-
/// use std::unstable::mutex::Mutex;
89+
/// ```rust
90+
/// use std::unstable::mutex::{StaticNativeMutex, NATIVE_MUTEX_INIT};
91+
/// static mut LOCK: StaticNativeMutex = NATIVE_MUTEX_INIT;
8492
/// unsafe {
85-
/// let mut lock = Mutex::new();
86-
///
87-
/// {
88-
/// let _guard = lock.lock();
89-
/// // critical section...
90-
/// } // automatically unlocked in `_guard`'s destructor
91-
/// }
93+
/// let _guard = LOCK.lock();
94+
/// // critical section...
95+
/// } // automatically unlocked in `_guard`'s destructor
9296
/// ```
9397
pub unsafe fn lock<'a>(&'a mut self) -> LockGuard<'a> {
9498
self.inner.lock();
@@ -455,20 +459,20 @@ mod test {
455459
use prelude::*;
456460

457461
use mem::drop;
458-
use super::{Mutex, MUTEX_INIT};
462+
use super::{StaticNativeMutex, NATIVE_MUTEX_INIT};
459463
use rt::thread::Thread;
460464

461465
#[test]
462466
fn smoke_lock() {
463-
static mut lock: Mutex = MUTEX_INIT;
467+
static mut lock: StaticNativeMutex = NATIVE_MUTEX_INIT;
464468
unsafe {
465469
let _guard = lock.lock();
466470
}
467471
}
468472

469473
#[test]
470474
fn smoke_cond() {
471-
static mut lock: Mutex = MUTEX_INIT;
475+
static mut lock: StaticNativeMutex = NATIVE_MUTEX_INIT;
472476
unsafe {
473477
let mut guard = lock.lock();
474478
let t = Thread::start(proc() {
@@ -484,7 +488,7 @@ mod test {
484488

485489
#[test]
486490
fn smoke_lock_noguard() {
487-
static mut lock: Mutex = MUTEX_INIT;
491+
static mut lock: StaticNativeMutex = NATIVE_MUTEX_INIT;
488492
unsafe {
489493
lock.lock_noguard();
490494
lock.unlock_noguard();
@@ -493,7 +497,7 @@ mod test {
493497

494498
#[test]
495499
fn smoke_cond_noguard() {
496-
static mut lock: Mutex = MUTEX_INIT;
500+
static mut lock: StaticNativeMutex = NATIVE_MUTEX_INIT;
497501
unsafe {
498502
lock.lock_noguard();
499503
let t = Thread::start(proc() {
@@ -511,7 +515,7 @@ mod test {
511515
#[test]
512516
fn destroy_immediately() {
513517
unsafe {
514-
let mut m = Mutex::new();
518+
let mut m = StaticNativeMutex::new();
515519
m.destroy();
516520
}
517521
}

src/libstd/unstable/sync.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ use kinds::Send;
1313
use ops::Drop;
1414
use option::Option;
1515
use sync::arc::UnsafeArc;
16-
use unstable::mutex::{Mutex, LockGuard};
16+
use unstable::mutex::{StaticNativeMutex, LockGuard};
1717

1818
pub struct LittleLock {
19-
priv l: Mutex,
19+
priv l: StaticNativeMutex,
2020
}
2121

2222
pub struct LittleGuard<'a> {
@@ -31,7 +31,7 @@ impl Drop for LittleLock {
3131

3232
impl LittleLock {
3333
pub fn new() -> LittleLock {
34-
unsafe { LittleLock { l: Mutex::new() } }
34+
unsafe { LittleLock { l: StaticNativeMutex::new() } }
3535
}
3636

3737
pub unsafe fn lock<'a>(&'a mut self) -> LittleGuard<'a> {

0 commit comments

Comments
 (0)