#ifndef __MUTEX_H_ #define __MUTEX_H_ /* * Definitions for high-level synchronization primitives. * * Mutexes. * Mutexes are a cross between semaphores and monitors. Like semaphores, * they must be inserted in code manually. Like monitors, they may be * associated with condition variables on which threads may block. * * For more information on mutexes, see the Birrell paper: * An Introduction to Programming with Threads * * You must implement the procedures and types defined in this interface. */ typedef struct mutex *mutex_t; typedef struct condition *condition_t; /* * Mutexes. */ /* * mutex_t mutex_create() * Allocate a new mutex. */ mutex_t mutex_create(); /* * mutex_destroy(mutex_t mu); * Deallocate a mutex. */ void mutex_destroy(mutex_t); /* * mutex_initialize(mutex_t mu) * initialize the mutex mu. */ void mutex_initialize(mutex_t); /* * mutex_lock(mutex_t mu) * Acquire the mutex. */ void mutex_lock(mutex_t); /* * mutex_try_lock(mutex_t mu) * Try to acquire the mutex. If the mutex is held, then return 0. Otherwise * return 1 to indicate the lock has been acquired. This procedure does * not block. */ int mutex_try_lock(mutex_t); /* * mutex_unlock(mutex_t mu) * Release the mutex. */ void mutex_unlock(mutex_t); /* * Condition Variables */ /* * condition_t condition_create() * Allocate a new condition variable. */ condition_t condition_create(); /* * condition_destroy(condition_t c); * Deallocate a condition variable. */ void condition_destroy(condition_t); /* * condition_initialize(condition_t c) * initialize the condition c */ void condition_initialize(condition_t); /* * condition_wait(mutex_t mu, condition_t c) * atomically release the mutex mu and wait on the condition variable c. * The mutex is reacquired before the return from condition_wait. */ void condition_wait(mutex_t,condition_t); /* * condition_signal(condition_t c) * signal at least one waiter on the condition variable c. If there are * no waiters, then this operation is a no op. */ void condition_signal(condition_t); /* * condition_broadcast(condition_t c) * signal all of the waiters on the condition variable c. */ void condition_broadcast(condition_t); #endif __MUTEX_H_