This type of lock for data where the reader wants a consitent set of information and is willing to retry if the information changes. Readers never block but they may have to retry if a writer is in progress. Writers do not wait for readers.
This is not as cache friendly as brlock. Also, this will not work for data that contains pointers, because any writer could invalidate a pointer that a reader was following.
Expected reader usage: do { seq = read_seqbegin(&foo); ... } while (read_seqretry(&foo, seq));
On non-SMP the spin locks disappear but the writer still needs to increment the sequence variables because an interrupt routine could change the state of the data.
Based on x86_64 vsyscall gettimeofday by Keith Owens and Andrea Arcangeli
#define read_seqretry_restore | ( | lock, | |||
iv, | |||||
flags | ) |
Value:
({ \
int ret = read_seqretry(lock, iv); \
put_cpu_flags(flags); \
ret; \
})