Struct Condvar

pub struct Condvar {
        priv sem: & Sem<~[mut Waitqueue]>,
    }

A mechanism for atomic-unlock-and-deschedule blocking and signalling.

Struct Mutex

struct Mutex {
    priv sem: Sem<~[mut Waitqueue]>,
}

Struct 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.

Failure

A task which fails while holding an rwlock will unlock the rwlock as it unwinds.

Struct RWlockReadMode

pub struct RWlockReadMode {
        priv lock: & RWlock,
    }

The "read permission" token used for rwlock.write_downgrade().

Struct RWlockWriteMode

pub struct RWlockWriteMode {
        lock: & RWlock,
    }

The "write permission" token used for rwlock.write_downgrade().

Struct Semaphore

struct Semaphore {
    priv sem: Sem<()>,
}

Implementation for & Condvar

Method wait

fn wait()

Atomically drop the associated lock, and block until a signal is sent.

Failure

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.

Method 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).

Method signal

fn signal() -> bool

Wake up a blocked task. Returns false if there was no blocked task.

Method signal_on

fn signal_on(condvar_id: uint) -> bool

As signal, but with a specified condvar_id. See wait_on.

Method broadcast

fn broadcast() -> uint

Wake up all blocked tasks. Returns the number of tasks woken.

Method broadcast_on

fn broadcast_on(condvar_id: uint) -> uint

As broadcast, but with a specified condvar_id. See wait_on.

Implementation for & Semaphore

Method clone

fn clone() -> Semaphore

Create a new handle to the semaphore.

Method acquire

fn acquire()

Acquire a resource represented by the semaphore. Blocks if necessary until resource(s) become available.

Method release

fn release()

Release a held resource represented by the semaphore. Wakes a blocked contending task, if any exist. Won't block the caller.

Method access

fn access<U>(blk: fn&() -> U) -> U

Run a function with ownership of one of the semaphore's resources.

Implementation for & Mutex

Method clone

fn clone() -> Mutex

Create a new handle to the mutex.

Method lock

fn lock<U>(blk: fn&() -> U) -> U

Run a function with ownership of the mutex.

Method 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.

Implementation for & RWlock

Method clone

fn clone() -> RWlock

Create a new handle to the rwlock.

Method 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.

Method 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.

Method 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.)

Method 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 ... } } ~

Method downgrade

fn downgrade(token: RWlockWriteMode/&a) -> RWlockReadMode/&a

To be called inside of the write_downgrade block.

Implementation for & RWlockWriteMode

Method write

fn write<U>(blk: fn&() -> U) -> U

Access the pre-downgrade rwlock in write mode.

Method write_cond

fn write_cond<U>(blk: fn&(c: & Condvar) -> U) -> U

Access the pre-downgrade rwlock in write mode with a condvar.

Implementation for & RWlockReadMode

Method read

fn read<U>(blk: fn&() -> U) -> U

Access the post-downgrade rwlock in read mode.

Function Mutex

fn Mutex() -> Mutex

Create a new mutex, with one associated condvar.

Function RWlock

fn RWlock() -> RWlock

Create a new rwlock, with one associated condvar.

Function RWlockReleaseDowngrade

fn RWlockReleaseDowngrade(lock: &r/RWlock) -> RWlockReleaseDowngrade/&r

Function RWlockReleaseRead

fn RWlockReleaseRead(lock: &r/RWlock) -> RWlockReleaseRead/&r

Function SemAndSignalRelease

fn SemAndSignalRelease(sem: &r/Sem<~[mut Waitqueue]>) ->
   SemAndSignalRelease/&r

Function SemRelease

fn SemRelease(sem: &r/Sem<()>) -> SemRelease/&r

Function 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.)

Function new_waitqueue

fn new_waitqueue() -> Waitqueue

Function 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.

Function semaphore

fn semaphore(count: int) -> Semaphore

Create a new semaphore with the specified count.