Condvar
- A mechanism for atomic-unlock-and-deschedule blocking and signalling.Mutex
RWlock
- A blocking, no-starvation, reader-writer lock with an associated condvar.RWlockReadMode
- The "read permission" token used for rwlockRWlockWriteMode
- The "write permission" token used for rwlockof Drop for Condvar<'self> where <'self>
for Condvar<'self> where <'self>
of Clone for Semaphore
for Semaphore
of Clone for Mutex
for Mutex
for RWlock
of Drop for RWlockWriteMode<'self> where <'self>
of Drop for RWlockReadMode<'self> where <'self>
for RWlockWriteMode<'self> where <'self>
for RWlockReadMode<'self> where <'self>
Mutex
- Create a new mutex, with one associated condvar.RWlock
- Create a new rwlock, with one associated condvar.mutex_with_condvars
- Create a new mutex, with a specified number of associated condvarsrwlock_with_condvars
- Create a new rwlock, with a specified number of associated condvarssemaphore
- Create a new semaphore with the specified count.Condvar
pub struct Condvar<'self> {
priv sem: &'self Sem<~[Waitqueue]>,
priv order: ReacquireOrderLock<'self>,
}
A mechanism for atomic-unlock-and-deschedule blocking and signalling.
Mutex
pub struct Mutex {
priv sem: Sem<~[Waitqueue]>,
}
A task which fails while holding a mutex will unlock the mutex as it unwinds.
RWlock
pub struct RWlock {
priv order_lock: Semaphore,
priv access_lock: Sem<~[Waitqueue]>,
priv state: UnsafeAtomicRcBox<RWlockInner>,
}
A blocking, no-starvation, reader-writer lock with an associated condvar.
A task which fails while holding an rwlock will unlock the rwlock as it unwinds.
RWlockReadMode
pub struct RWlockReadMode<'self> {
priv lock: &'self RWlock,
}
The "read permission" token used for rwlock.write_downgrade().
RWlockWriteMode
pub struct RWlockWriteMode<'self> {
priv lock: &'self RWlock,
}
The "write permission" token used for rwlock.write_downgrade().
Drop
for Condvar<'self>
where <'self>
drop
fn drop(&self)
Condvar<'self>
where <'self>
wait
fn wait(&self)
Atomically drop the associated lock, and block until a signal is sent.
A task which is killed (i.e., by linked failure with another task) while waiting on a condition variable will wake up, fail, and unlock the associated lock as it unwinds.
wait_on
fn wait_on(&self, condvar_id: uint)
As wait(), but can specify which of multiple condition variables to wait on. Only a signal_on() or broadcast_on() with the same condvar_id will wake this thread.
The associated lock must have been initialised with an appropriate number of condvars. The condvar_id must be between 0 and num_condvars-1 or else this call will fail.
wait() is equivalent to wait_on(0).
signal
fn signal(&self) -> bool
Wake up a blocked task. Returns false if there was no blocked task.
signal_on
fn signal_on(&self, condvar_id: uint) -> bool
As signal, but with a specified condvar_id. See wait_on.
broadcast
fn broadcast(&self) -> uint
Wake up all blocked tasks. Returns the number of tasks woken.
broadcast_on
fn broadcast_on(&self, condvar_id: uint) -> uint
As broadcast, but with a specified condvar_id. See wait_on.
Clone
for Semaphore
clone
fn clone(&self) -> Semaphore
Create a new handle to the semaphore.
Semaphore
acquire
fn acquire(&self)
Acquire a resource represented by the semaphore. Blocks if necessary until resource(s) become available.
release
fn release(&self)
Release a held resource represented by the semaphore. Wakes a blocked contending task, if any exist. Won't block the caller.
access
fn access<U>(&self, blk: &fn() -> U) -> U
Run a function with ownership of one of the semaphore's resources.
Clone
for Mutex
clone
fn clone(&self) -> Mutex
Create a new handle to the mutex.
Mutex
lock
fn lock<U>(&self, blk: &fn() -> U) -> U
Run a function with ownership of the mutex.
lock_cond
fn lock_cond<U>(&self, blk: &fn(c: &Condvar) -> U) -> U
Run a function with ownership of the mutex and a handle to a condvar.
RWlock
clone
fn clone(&self) -> RWlock
Create a new handle to the rwlock.
read
fn read<U>(&self, blk: &fn() -> U) -> U
Run a function with the rwlock in read mode. Calls to 'read' from other tasks may run concurrently with this one.
write
fn write<U>(&self, blk: &fn() -> U) -> U
Run a function with the rwlock in write mode. No calls to 'read' or 'write' from other tasks will run concurrently with this one.
write_cond
fn write_cond<U>(&self, blk: &fn(c: &Condvar) -> U) -> U
As write(), but also with a handle to a condvar. Waiting on this condvar will allow readers and writers alike to take the rwlock before the waiting task is signalled. (Note: a writer that waited and then was signalled might reacquire the lock before other waiting writers.)
write_downgrade
fn write_downgrade<U>(&self, blk: &fn(v: RWlockWriteMode) -> U) -> U
As write(), but with the ability to atomically 'downgrade' the lock; i.e., to become a reader without letting other writers get the lock in the meantime (such as unlocking and then re-locking as a reader would do). The block takes a "write mode token" argument, which can be transformed into a "read mode token" by calling downgrade(). Example:
do lock.write_downgrade |mut write_token| {
do write_token.write_cond |condvar| {
... exclusive access ...
}
let read_token = lock.downgrade(write_token);
do read_token.read {
... shared access ...
}
}
downgrade
fn downgrade<'a>(&self, token: RWlockWriteMode<'a>) -> RWlockReadMode<'a>
To be called inside of the write_downgrade block.
Drop
for RWlockWriteMode<'self>
where <'self>
drop
fn drop(&self)
Drop
for RWlockReadMode<'self>
where <'self>
drop
fn drop(&self)
RWlockWriteMode<'self>
where <'self>
write
fn write<U>(&self, blk: &fn() -> U) -> U
Access the pre-downgrade rwlock in write mode.
write_cond
fn write_cond<U>(&self, blk: &fn(c: &Condvar) -> U) -> U
Access the pre-downgrade rwlock in write mode with a condvar.
RWlockReadMode<'self>
where <'self>
read
fn read<U>(&self, blk: &fn() -> U) -> U
Access the post-downgrade rwlock in read mode.
Mutex
fn Mutex() -> Mutex
Create a new mutex, with one associated condvar.
RWlock
fn RWlock() -> RWlock
Create a new rwlock, with one associated condvar.
mutex_with_condvars
fn mutex_with_condvars(num_condvars: uint) -> Mutex
Create a new mutex, with a specified number of associated condvars. This will allow calling wait_on/signal_on/broadcast_on with condvar IDs between 0 and num_condvars-1. (If num_condvars is 0, lock_cond will be allowed but any operations on the condvar will fail.)
rwlock_with_condvars
fn rwlock_with_condvars(num_condvars: uint) -> RWlock
Create a new rwlock, with a specified number of associated condvars. Similar to mutex_with_condvars.
semaphore
fn semaphore(count: int) -> Semaphore
Create a new semaphore with the specified count.