• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #ifndef FIO_SEQLOCK_H
2 #define FIO_SEQLOCK_H
3 
4 #include "../arch/arch.h"
5 
6 struct seqlock {
7 	volatile int sequence;
8 };
9 
seqlock_init(struct seqlock * s)10 static inline void seqlock_init(struct seqlock *s)
11 {
12 	s->sequence = 0;
13 }
14 
read_seqlock_begin(struct seqlock * s)15 static inline unsigned int read_seqlock_begin(struct seqlock *s)
16 {
17 	unsigned int seq;
18 
19 	do {
20 		seq = s->sequence;
21 		if (!(seq & 1))
22 			break;
23 		nop;
24 	} while (1);
25 
26 	read_barrier();
27 	return seq;
28 }
29 
read_seqlock_retry(struct seqlock * s,unsigned int seq)30 static inline bool read_seqlock_retry(struct seqlock *s, unsigned int seq)
31 {
32 	read_barrier();
33 	return s->sequence != seq;
34 }
35 
write_seqlock_begin(struct seqlock * s)36 static inline void write_seqlock_begin(struct seqlock *s)
37 {
38 	s->sequence++;
39 	write_barrier();
40 }
41 
write_seqlock_end(struct seqlock * s)42 static inline void write_seqlock_end(struct seqlock *s)
43 {
44 	write_barrier();
45 	s->sequence++;
46 }
47 
48 #endif
49