Struct Condvar

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

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

Struct Mutex

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

Failure

A task which fails while holding a mutex will unlock the mutex as it unwinds.

Struct RWlock

pub struct RWlock {
    priv order_lock: Semaphore,
    priv access_lock: Sem<~[Waitqueue]>,
    priv 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<'self> {
    priv lock: &'self RWlock,
}

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

Struct RWlockWriteMode

pub struct RWlockWriteMode<'self> {
    priv lock: &'self RWlock,
}

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

Implementation of Drop for SemReleaseGeneric<'self, Q> where <'self, Q: Owned>

Method finalize

fn finalize(&self)

Implementation of Drop for Condvar<'self> where <'self>

Method finalize

fn finalize(&self)

Implementation for Condvar<'self> where <'self>

Method wait

fn wait(&self)

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(&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).

Method signal

fn signal(&self) -> bool

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

Method signal_on

fn signal_on(&self, condvar_id: uint) -> bool

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

Method broadcast

fn broadcast(&self) -> uint

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

Method broadcast_on

fn broadcast_on(&self, condvar_id: uint) -> uint

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

Implementation of Clone for Semaphore

Method clone

fn clone(&self) -> Semaphore

Create a new handle to the semaphore.

Implementation for Semaphore

Method acquire

fn acquire(&self)

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

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

Method access

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

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

Implementation of Clone for Mutex

Method clone

fn clone(&self) -> Mutex

Create a new handle to the mutex.

Implementation for Mutex

Method lock

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

Run a function with ownership of the mutex.

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

Implementation for RWlock

Method clone

fn clone(&self) -> RWlock

Create a new handle to the rwlock.

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

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

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

Method 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 |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<'a>(&self, token: RWlockWriteMode<'a>) -> RWlockReadMode<'a>

To be called inside of the write_downgrade block.

Implementation of Drop for RWlockReleaseRead<'self> where <'self>

Method finalize

fn finalize(&self)

Implementation of Drop for RWlockReleaseDowngrade<'self> where <'self>

Method finalize

fn finalize(&self)

Implementation of Drop for RWlockWriteMode<'self> where <'self>

Method finalize

fn finalize(&self)

Implementation of Drop for RWlockReadMode<'self> where <'self>

Method finalize

fn finalize(&self)

Implementation for RWlockWriteMode<'self> where <'self>

Method write

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

Access the pre-downgrade rwlock in write mode.

Method write_cond

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

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

Implementation for RWlockReadMode<'self> where <'self>

Method read

fn read<U>(&self, 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 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 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.