Chinaunix首页 | 论坛 | 博客
  • 博客访问: 471907
  • 博文数量: 134
  • 博客积分: 3056
  • 博客等级: 中校
  • 技术积分: 1150
  • 用 户 组: 普通用户
  • 注册时间: 2010-05-14 15:53
文章分类
文章存档

2013年(1)

2010年(133)

我的朋友

分类: LINUX

2010-08-09 19:18:06

The include file that defines semaphores and the operations on them.

#include <asm/semaphore.h>



Two macros for declaring and initializing a semaphore used in mutual exclusion  mode.

DECLARE_MUTEX(name);
DECLARE_MUTEX_LOCKED(name);



Lock and unlock a 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);
int down_interruptible(struct semaphore *sem);
int down_trylock(struct semaphore *sem);
void up(struct semaphore *sem);



The reader/writer version of semaphores and the function that initializes it.

struct rw_semaphore;
init_rwsem(struct rw_semaphore *sem);



Functions for obtaining and releasing read access to a reader/writer semaphore.

void down_read(struct rw_semaphore *sem);
int down_read_trylock(struct rw_semaphore *sem);
void up_read(struct rw_semaphore *sem);



Functions for managing write 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)



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>
DECLARE_COMPLETION(name);
init_completion(struct completion *c);
INIT_COMPLETION(struct completion c);



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);
void complete_all(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>
spinlock_t lock = SPIN_LOCK_UNLOCKED;
spin_lock_init(spinlock_t *lock);



The various ways of locking a spinlock and, possibly, disabling interrupts.

void spin_lock(spinlock_t *lock);
void spin_lock_irqsave(spinlock_t *lock, unsigned long flags);
void spin_lock_irq(spinlock_t *lock);
void spin_lock_bh(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);
int spin_trylock_bh(spinlock_t *lock);



The corresponding ways of releasing a spinlock.

void spin_unlock(spinlock_t *lock);
void spin_unlock_irqrestore(spinlock_t *lock, unsigned long flags);
void spin_unlock_irq(spinlock_t *lock);
void spin_unlock_bh(spinlock_t *lock);



The two ways of initializing reader/writer locks.

rwlock_t lock = RW_LOCK_UNLOCKED
rwlock_init(rwlock_t *lock);



Functions for obtaining read access to a reader/writer lock.

void read_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 releasing read access to a reader/writer spinlock.

void read_unlock(rwlock_t *lock);
void read_unlock_irqrestore(rwlock_t *lock, unsigned long flags);
void read_unlock_irq(rwlock_t *lock);
void read_unlock_bh(rwlock_t *lock);



Functions for obtaining write access to a reader/writer lock.

void write_lock(rwlock_t *lock);
void write_lock_irqsave(rwlock_t *lock, unsigned long flags);
void write_lock_irq(rwlock_t *lock);
void write_lock_bh(rwlock_t *lock);



Functions for releasing write access to a reader/writer spinlock.

void write_unlock(rwlock_t *lock);
void write_unlock_irqrestore(rwlock_t *lock, unsigned long flags);
void write_unlock_irq(rwlock_t *lock);
void write_unlock_bh(rwlock_t *lock);



Atomically access integer variables. The atomic_t variables must be accessed  only through these functions.

#include <asm/atomic.h>

atomic_t v = ATOMIC_INIT(value);

void atomic_set(atomic_t *v, int i);
int atomic_read(atomic_t *v);
void atomic_add(int i, atomic_t *v);
void atomic_sub(int i, atomic_t *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, atomic_t *v);
int atomic_sub_return(int i, atomic_t *v);
int atomic_inc_return(atomic_t *v);
int atomic_dec_return(atomic_t *v);



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 <asm/bitops.h>

void set_bit(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);



The include file defining seqlocks and the two ways of initializing them.

#include <linux/seqlock.h>

seqlock_t lock = SEQLOCK_UNLOCKED;
seqlock_init(seqlock_t *lock);



Functions for obtaining read access to a seqlock-protected resources.

unsigned int read_seqbegin(seqlock_t *lock);
unsigned int read_seqbegin_irqsave(seqlock_t *lock, unsigned long flags);
int read_seqretry(seqlock_t *lock, unsigned int seq);
int read_seqretry_irqrestore(seqlock_t *lock, unsigned int seq, unsigned long flags);



Functions for obtaining write access to a seqlock-protected resource.

void write_seqlock(seqlock_t *lock);
void write_seqlock_irqsave(seqlock_t *lock, unsigned long flags);
void write_seqlock_irq(seqlock_t *lock);
void write_seqlock_bh(seqlock_t *lock);
int write_tryseqlock(seqlock_t *lock);



The include file required to use the read-copy-update (RCU) mechanism.

#include <linux/rcupdate.h>



Macros for obtaining atomic read access to a resource protected by RCU.

void rcu_read_lock;
void rcu_read_unlock;



Arranges for a callbackto run after all processors have been scheduled and an  RCU-protected resource can be safely freed.

void call_rcu(struct rcu_head *head, void (*func)(void *arg), void *arg);


阅读(853) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~