顺序锁

#include

typedef struct {
	struct seqcount seqcount;
	spinlock_t lock;
} seqlock_t;

DEFINE_SEQLOCK(x)

#define DEFINE_SEQLOCK(x) \

seqlock_t x = __SEQLOCK_UNLOCKED(x)

举例:

DEFINE_SEQLOCK(jiffies_lock);

 

seqlock_init(x)

#define seqlock_init(x)					\
	do {						\
		seqcount_init(&(x)->seqcount);		\
		spin_lock_init(&(x)->lock);		\
	} while (0)

举例:

seqlock_t stats_lock;

seqlock_init(&stats_lock);

 

void write_seqlock(seqlock_t *sl)

void write_sequnlock(seqlock_t *sl)

void write_seqlock_bh(seqlock_t *sl)

void write_sequnlock_bh(seqlock_t *sl)

void write_seqlock_irq(seqlock_t *sl)

void write_sequnlock_irq(seqlock_t *sl)

举例:

write_seqlock(&stats_lock);

...

write_sequnlock(&stats_lock);

------------

write_seqlock(&jiffies_lock);

...

write_sequnlock(&jiffies_lock);

 

unsigned read_seqbegin(const seqlock_t *sl)

unsigned read_seqretry(const seqlock_t *sl, unsigned start)

举例:

u64 get_jiffies_64(void)

{

    unsigned long seq;

    u64 ret;

 

    do {

        seq = read_seqbegin(&jiffies_lock);

        ret = jiffies_64;

     } while (read_seqretry(&jiffies_lock, seq));

     return ret;

}

你可能感兴趣的:(linux,kernel)