ch05-Concurrency and Race Conditions
时间:2010-08-09 来源:guocai_yao
#include <asm/semaphore.h> |
Two macros for declaring and initializing a semaphore used in mutual exclusion mode.
DECLARE_MUTEX(name); |
Lockand unlocka semaphore. down puts the calling process into an uninterruptible sleep if need be; down_interruptible, instead, can be interrupted by a signal. down_trylock does not sleep; instead, it returns immediately if the semaphore is unavailable. Code that locks a semaphore must eventually unlock it with up.
void down(struct semaphore *sem); |
The reader/writer version of semaphores and the function that initializes it.
struct rw_semaphore; |
Functions for obtaining and releasing read access to a reader/writer semaphore.
void down_read(struct rw_semaphore *sem); |
Functions for managing write access to a reader/writer semaphore.
void down_write(struct rw_semaphore *sem) |
The include file describing the Linux completion mechanism, and the normal methods for initializing completions. INIT_COMPLETION should be used only to reinitialize a completion that has been previously used.
#include <linux/completion.h> |
Wait for a completion event to be signalled.
void wait_for_completion(struct completion *c); |
Signal a completion event. complete wakes, at most, one waiting thread, while complete_all wakes all waiters.
void complete(struct completion *c); |
Signals a completion event by calling complete and calls exit for the current thread.
void complete_and_exit(struct completion *c, long retval); |
The include file defining the spinlockinterface and the two ways of initializing locks.
#include <linux/spinlock.h> |
The various ways of locking a spinlock and, possibly, disabling interrupts.
oid spin_lock(spinlock_t *lock); |
Nonspinning versions of the above functions; these return 0 in case of failure to obtain the lock, nonzero otherwise.
int spin_trylock(spinlock_t *lock); |