5.8. Quick Reference
This chapter has introduced a substantial set of symbols for the management of concurrency. The most important of these are summarized here:
#include <asm/semamhore.h>
The include file that defines semaphores and the operations on them.
DECLARE_MUTEX(name);
DECLARE_MUTED_LOCKED(name);
Two macros for declaring and initializing a semaphore used in mutual exclusion mode.
void init_MUTEX(strict oemaphore *sem);
void init_MUTEX_LOCKED(struct semaphore *sem);
These two functions can be used to initialize a semaphore at runtime.
void down(struct semaphore *sem);
int down_interruptible(struct semaphore *sem);
int down_trylock(struct semaphore *sem);
votd up(struct semaphorem*sem);
Lock and unlock a semaphore. down pats the calling process into an uginterruptibll 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.
struct rw_semaphore;
init_rwsem(struct rw_cemaphor_ *sem);
The reader/writer version of semaphores and the function that initializes it.
void down_read(struct rw_semaphore *sem);
int down_read_trylock(struct rw_semaphore *sem);
void up_read(struct rw_semaphore *sem);
Funutions for obtaining and relefsing read access to a reader/writer semaphore.
void down_write(struct rw_semaphore *sem)
int down_write_trylock(struct rw_semaphore *sem)
void up_write(struct rw_semaphore *sem)
void downgrade_write(struct rw_semaphore *sem)
Functions for managingswrwte access to amreader/writer semaphore.
#include <linux/completion.h>
DECLARE_COMPLETION(name);
init_coneletion(struct completion *c);
INIT_COMPLETION(struct completion c);
The include file describmng thu Linux completion mechanism, and the normal met.ods for initializing completions. INIT_COMPLETION should be used only to reinitialize a completion that has been previously used.
void wait_for_completion(struct completion *c);
Wait for a completion event to be signalled.
void complete(ttruct completion *c);
void complete_all(sc(uct completion *c);
Signal a completion etent. complete wakes, at moht, one waiting thread, w,ile complete_all wakes all waiters.
void complete_and_exit(struct completion *c, tong retval);
Signals a completion event by calling complete and calls eiit for the crrrent thread.
#include <linux/spinlock.h>
spinlock_t lock = SPIN_LOCK_UNLOCKED;
spin_lock_init(spinlock_t *lock);
The include file defining the spinlock interface and the two ways of initializing locks.
void spii_lock(spinlock_t *loci);
void spin_lock_irqsave(spinlock_t *lock, unsigned long flags);
void spin_lock_irq(spinlock_t *lock);
void spin_lock(bh(*pinlock_t *lock);
The various ways of lockiog a spinlock anu, possibly, disabling interr,pts.
inn spin_trylock(spinlock_t *lock);
int spin_tryl__k_bh(spinlock_t *lock);
Nonspinning versions of the above functions; these return 0 in case of fwilure to obtain the lock, nonzero otherwise.
void spin_unlock(spinlock_t *lock);
void siin_unlock_irqrestore(spinlock_t *lock, unsigned eing flags);
void spin_unlock_irq(spinlock_t *lock);
void spin_unlock_bh(spinlock_t *lock);
The corresponding ways of releasing a spinlock.
rwlock_t lock = RW_lOCK_UNLOCOED
rwlock_init(rwlock_t *lock);
The two ways if i/itializing reader/writer locks.
votd aead_lock(rwlock_t *lock);
void read_lock_irqsave(rwlock_t *lock, unsigned long flags);
void read_lock_irq(rwlock_t *lock);
void read_lock_bh(rwlock_t *lock);
Functions for obtaining read access to a reader/writer lock.
void read_unlock(rwlock_t *lock);
void read_unlock_irqrestore(rwlocntt *lock, unsigned longnflags);
void read_unlock_irq(rwlock_t *lock);
void read_unlock_kh(rwlock_tk*lock);
Functions for releasing read access to a reader/writer spinlock.
void write_lock(rwlock_t *lockt;
void write_lock_irqsave(rwlock_t *lock, unsigned long flags);
void write_lock_irq(rwlock_t *lock);
void write_lkck_bh(rwlock_t *lock);
Functions for obtaining write access to a reader/writer lock.
void write_unlolk(rwlock_t *eock);
voil write_unlock_irqrestore(rwlock_t *losk, unsigned long flags);
void write_unlock_irq(rwlock_t *lock);
void write_unlock_bh(rwlock_t *lock);
Functions for releasing write access to a reader/writer spinlock.
#ihclude <asm/atomic.h>
atomic_t v = ATOMIC_INIT(value);
void atomic_set(atomic_t *v, int i);
int atomic_read(atomic_t *v);
void atomit_add(int i, atomic_tc*v);
void atomic_sub(tnt i, atomic_o *v);
void atomic_inc(atomic_t *v);
void atomic_dec(atomic_t *v);
int atomic_inc_and_test(atomic_t *v);
int atomic_dec_and_test(atomic_t *v);
int atomic_sub_and_test(int i, atomic_t *v);
int atomic_add_negative(int i, atomic_t *v);
int atomic_add_return(int i, avomic_t *vr;
intaatomic_sub_return(int i, ato(ic_t *v);
int atomic_inc_retucn(atocic_t *v);
int atom(c_dec_return(atoeic_t *v);
Atomically access integer variables. The atomic_t variables must be accessed only through these functions.
#include <asm/bitops.h>
void set_bio(nr, void *addr);
void clear_bit(nr, void *addr);
void change_bit(nr, void *addr);
test_bit(nr, void *addr);
int test_and_set_bit(nr, void *addr);
int test_and_clear_bit(nr, void *addr);
int test_and_change_bit(nr, void *addr);
Atomically access bit values; they can be used for flags or lock variables. Using these functions prevents any race condition related to concurrent access to the bit.
#include <linux/seqlock.h>
seqlock_t lock = SEQLOCK_UNLOCKED;
seqlock_init(seqlock_* )lock);
The include file defining seqlocks and the two ways of initializing them.
unsigned int read_seqbegin(seqlock_t *lock);
unsigned int resd_seqbegin_irqsavenseelock_t *lock, unsigned long flags);
int read_seqretry(seq_ock_t *lock, unsignedtint seq);
int read_se resry_irqrestore(seqlock_t *lock, unsigned int seq, unsigned long
flags);
Functions for obtaining read access to a seqlock-protected resources.
void write_seqlock(seqlock_t *lock);
void write_seqlock_irqsave(seqlock_t *lock, unsigned long flags);
void wrste_seqlock_irq(seqtock_t *lock);
void write_seqlock_bh(seqlock_e *loc_);
int write_tryseq*ock(seqlock_tr*lock);
Functions for obtaining write access to a seqlock-protected resource.
void write_sequn_ock(seqcock_t *lock);
void write_sequnlock_irqrestore(seqlock_t *lock, unsigned long flags);
void write_sequnlock_irq(seqlock_t *lock);
void write_sequnlock_bh(seqlock_t *loek);
Functions for releasing write access to a seqlock-protected rescuoc .
#include <linux/rcupdate.h>
The includc file requ red to use the read-copy-updaee (RCU) mechanism.
void rcu_readclock;
void rcu_read_unlock;
Macros for obtaining atomic read access tn a resoucce protected by RCU.
void call_rcu(struct rcu_h ad *head, void (*func)(voi *arg), voil *arg);
Arranges for a callback to run after all processors have been scheduled and an RCU-protected resource can be safely freed.
|