Skip to content

Commit

Permalink
Convert some unnecessary StaticNativeMutexes to NativeMutexes.
Browse files Browse the repository at this point in the history
  • Loading branch information
huonw committed Feb 15, 2014
1 parent 5d86e24 commit 4668cdf
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 25 deletions.
4 changes: 2 additions & 2 deletions src/libgreen/sched.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use std::rt::rtio::{RemoteCallback, PausableIdleCallback, Callback, EventLoop};
use std::rt::task::BlockedTask;
use std::rt::task::Task;
use std::sync::deque;
use std::unstable::mutex::StaticNativeMutex;
use std::unstable::mutex::NativeMutex;
use std::unstable::raw;

use TaskState;
Expand Down Expand Up @@ -764,7 +764,7 @@ impl Scheduler {
// to it, but we're guaranteed that the task won't exit until we've
// unlocked the lock so there's no worry of this memory going away.
let cur = self.change_task_context(cur, next, |sched, mut task| {
let lock: *mut StaticNativeMutex = &mut task.nasty_deschedule_lock;
let lock: *mut NativeMutex = &mut task.nasty_deschedule_lock;
unsafe {
let _guard = (*lock).lock();
f(sched, BlockedTask::block(task.swap()));
Expand Down
14 changes: 4 additions & 10 deletions src/libgreen/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use std::rt::local::Local;
use std::rt::rtio;
use std::rt::task::{Task, BlockedTask, SendMessage};
use std::task::TaskOpts;
use std::unstable::mutex::StaticNativeMutex;
use std::unstable::mutex::NativeMutex;
use std::unstable::raw;

use context::Context;
Expand Down Expand Up @@ -65,7 +65,7 @@ pub struct GreenTask {
pool_id: uint,

// See the comments in the scheduler about why this is necessary
nasty_deschedule_lock: StaticNativeMutex,
nasty_deschedule_lock: NativeMutex,
}

pub enum TaskType {
Expand Down Expand Up @@ -163,7 +163,7 @@ impl GreenTask {
task_type: task_type,
sched: None,
handle: None,
nasty_deschedule_lock: unsafe { StaticNativeMutex::new() },
nasty_deschedule_lock: unsafe { NativeMutex::new() },
task: Some(~Task::new()),
}
}
Expand Down Expand Up @@ -322,7 +322,7 @@ impl GreenTask {
// uncontended except for when the task is rescheduled).
fn reawaken_remotely(mut ~self) {
unsafe {
let mtx = &mut self.nasty_deschedule_lock as *mut StaticNativeMutex;
let mtx = &mut self.nasty_deschedule_lock as *mut NativeMutex;
let handle = self.handle.get_mut_ref() as *mut SchedHandle;
let _guard = (*mtx).lock();
(*handle).send(RunOnce(self));
Expand Down Expand Up @@ -478,12 +478,6 @@ impl Runtime for GreenTask {
fn wrap(~self) -> ~Any { self as ~Any }
}

impl Drop for GreenTask {
fn drop(&mut self) {
unsafe { self.nasty_deschedule_lock.destroy(); }
}
}

#[cfg(test)]
mod tests {
use std::rt::Runtime;
Expand Down
12 changes: 3 additions & 9 deletions src/libnative/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use std::rt::task::{Task, BlockedTask, SendMessage};
use std::rt::thread::Thread;
use std::rt;
use std::task::TaskOpts;
use std::unstable::mutex::StaticNativeMutex;
use std::unstable::mutex::NativeMutex;
use std::unstable::stack;

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

fn ops() -> ~Ops {
~Ops {
lock: unsafe { StaticNativeMutex::new() },
lock: unsafe { NativeMutex::new() },
awoken: false,
io: io::IoFactory::new(),
// these *should* get overwritten
Expand Down Expand Up @@ -109,7 +109,7 @@ pub fn spawn_opts(opts: TaskOpts, f: proc()) {
// This structure is the glue between channels and the 1:1 scheduling mode. This
// structure is allocated once per task.
struct Ops {
lock: StaticNativeMutex, // native synchronization
lock: NativeMutex, // native synchronization
awoken: bool, // used to prevent spurious wakeups
io: io::IoFactory, // local I/O factory

Expand Down Expand Up @@ -251,12 +251,6 @@ impl rt::Runtime for Ops {
}
}

impl Drop for Ops {
fn drop(&mut self) {
unsafe { self.lock.destroy() }
}
}

#[cfg(test)]
mod tests {
use std::rt::Runtime;
Expand Down
7 changes: 3 additions & 4 deletions src/libstd/comm/shared.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use rt::local::Local;
use rt::task::{Task, BlockedTask};
use rt::thread::Thread;
use sync::atomics;
use unstable::mutex::StaticNativeMutex;
use unstable::mutex::NativeMutex;
use vec::OwnedVector;

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

// this lock protects various portions of this implementation during
// select()
select_lock: StaticNativeMutex,
select_lock: NativeMutex,
}

pub enum Failure {
Expand All @@ -72,7 +72,7 @@ impl<T: Send> Packet<T> {
channels: atomics::AtomicInt::new(2),
port_dropped: atomics::AtomicBool::new(false),
sender_drain: atomics::AtomicInt::new(0),
select_lock: unsafe { StaticNativeMutex::new() },
select_lock: unsafe { NativeMutex::new() },
};
// see comments in inherit_blocker about why we grab this lock
unsafe { p.select_lock.lock_noguard() }
Expand Down Expand Up @@ -486,7 +486,6 @@ impl<T: Send> Drop for Packet<T> {
assert_eq!(self.cnt.load(atomics::SeqCst), DISCONNECTED);
assert_eq!(self.to_wake.load(atomics::SeqCst), 0);
assert_eq!(self.channels.load(atomics::SeqCst), 0);
self.select_lock.destroy();
}
}
}

5 comments on commit 4668cdf

@bors
Copy link
Contributor

@bors bors commented on 4668cdf Feb 15, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from alexcrichton
at huonw@4668cdf

@bors
Copy link
Contributor

@bors bors commented on 4668cdf Feb 15, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging huonw/rust/raii-lock = 4668cdf into auto

@bors
Copy link
Contributor

@bors bors commented on 4668cdf Feb 15, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

huonw/rust/raii-lock = 4668cdf merged ok, testing candidate = d98668a

@bors
Copy link
Contributor

@bors bors commented on 4668cdf Feb 16, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors
Copy link
Contributor

@bors bors commented on 4668cdf Feb 16, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding master to auto = d98668a

Please sign in to comment.