SemAndSignalRelease
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 rwlockSemReleaseGeneric
Semaphore
of Drop for SemReleaseGeneric<Q>
of Drop for Condvar
for &Condvar
of Clone for Semaphore
for &Semaphore
of Clone for Mutex
for &Mutex
for &RWlock
of Drop for RWlockReleaseRead
of Drop for RWlockReleaseDowngrade
of Drop for RWlockWriteMode
of Drop for RWlockReadMode
for &RWlockWriteMode
for &RWlockReadMode
Mutex
- Create a new mutex, with one associated condvar.RWlock
- Create a new rwlock, with one associated condvar.RWlockReleaseDowngrade
RWlockReleaseRead
SemAndSignalRelease
SemRelease
mutex_with_condvars
- Create a new mutex, with a specified number of associated condvarsnew_waitqueue
rwlock_with_condvars
- Create a new rwlock, with a specified number of associated condvarssemaphore
- Create a new semaphore with the specified count.SemAndSignalRelease
type SemAndSignalRelease = SemReleaseGeneric<~[mut Waitqueue]>
Condvar
pub struct Condvar {
priv sem: &Sem<~[mut Waitqueue]>,
}
A mechanism for atomic-unlock-and-deschedule blocking and signalling.
Mutex
struct Mutex {
priv sem: Sem<~[mut Waitqueue]>,
}
A task which fails while holding a mutex will unlock the mutex as it unwinds.
RWlock
struct RWlock {
order_lock: Semaphore,
access_lock: Sem<~[mut Waitqueue]>,
state: Exclusive<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 {
priv lock: &RWlock,
}
The "read permission" token used for rwlock.write_downgrade().
RWlockWriteMode
pub struct RWlockWriteMode {
lock: &RWlock,
}
The "write permission" token used for rwlock.write_downgrade().
SemReleaseGeneric
struct SemReleaseGeneric <Q: Owned>{
sem: &Sem<Q>,
}
Semaphore
struct Semaphore {
priv sem: Sem<()>,
}
Drop
for SemReleaseGeneric<Q>
finalize
fn finalize()
Drop
for Condvar
finalize
fn finalize()
&Condvar
wait
fn wait()
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(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() -> bool
Wake up a blocked task. Returns false if there was no blocked task.
signal_on
fn signal_on(condvar_id: uint) -> bool
As signal, but with a specified condvar_id. See wait_on.
broadcast
fn broadcast() -> uint
Wake up all blocked tasks. Returns the number of tasks woken.
broadcast_on
fn broadcast_on(condvar_id: uint) -> uint
As broadcast, but with a specified condvar_id. See wait_on.
Clone
for Semaphore
clone
fn clone() -> Semaphore
Create a new handle to the semaphore.
&Semaphore
acquire
fn acquire()
Acquire a resource represented by the semaphore. Blocks if necessary until resource(s) become available.
release
fn release()
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>(blk: &fn() -> U) -> U
Run a function with ownership of one of the semaphore's resources.
Clone
for Mutex
clone
fn clone() -> Mutex
Create a new handle to the mutex.
&Mutex
lock
fn lock<U>(blk: &fn() -> U) -> U
Run a function with ownership of the mutex.
lock_cond
fn lock_cond<U>(blk: &fn(c: &Condvar) -> U) -> U
Run a function with ownership of the mutex and a handle to a condvar.
&RWlock
clone
fn clone() -> RWlock
Create a new handle to the rwlock.
read
fn read<U>(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>(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>(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>(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 |write_mode| { do (&write_mode).write_cond |condvar| { ... exclusive access ... } let read_mode = lock.downgrade(write_mode); do (&read_mode).read { ... shared access ... } } ~
downgrade
fn downgrade(token: RWlockWriteMode/&a) -> RWlockReadMode/&a
To be called inside of the write_downgrade block.
Drop
for RWlockReleaseRead
finalize
fn finalize()
Drop
for RWlockReleaseDowngrade
finalize
fn finalize()
Drop
for RWlockWriteMode
finalize
fn finalize()
Drop
for RWlockReadMode
finalize
fn finalize()
&RWlockWriteMode
write
fn write<U>(blk: &fn() -> U) -> U
Access the pre-downgrade rwlock in write mode.
write_cond
fn write_cond<U>(blk: &fn(c: &Condvar) -> U) -> U
Access the pre-downgrade rwlock in write mode with a condvar.
&RWlockReadMode
read
fn read<U>(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.
RWlockReleaseDowngrade
fn RWlockReleaseDowngrade(lock: &r/RWlock) -> RWlockReleaseDowngrade/&r
RWlockReleaseRead
fn RWlockReleaseRead(lock: &r/RWlock) -> RWlockReleaseRead/&r
SemAndSignalRelease
fn SemAndSignalRelease(sem: &r/Sem<~[mut Waitqueue]>) ->
SemAndSignalRelease/&r
SemRelease
fn SemRelease(sem: &r/Sem<()>) -> SemRelease/&r
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.)
new_waitqueue
fn new_waitqueue() -> Waitqueue
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.