Go to the source code of this file.
Data Structures | |
struct | rt_seqlock_t |
Defines | |
#define | RT_SEQLOCK_UNLOCKED { 0, RTDM_LOCK_UNLOCKED } |
#define | rt_seqlock_init(x) |
#define | rt_write_seqlock_irqsave(sl, flags) |
#define | rt_write_sequnlock_irqrestore(sl, flags) |
Functions | |
static void | rt_write_seqlock (seqlock_t *sl) |
static void | rt_write_sequnlock (seqlock_t *sl) |
static unsigned int | rt_read_seqbegin (const seqlock_t *sl) |
static int | rt_read_seqretry (const seqlock_t *sl, unsigned int iv) |
Provides real-time sequence lock. The implementation follows the structure of Linux sequence locks.
Reader/writer consistent mechanism without starving writers. 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 = rt_read_seqbegin(&foo); // ... } while (rt_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.
Definition in file rtseqlock.h.
#define RT_SEQLOCK_UNLOCKED { 0, RTDM_LOCK_UNLOCKED } |
Initialises a sequence lock statically at compile-time.
Definition at line 78 of file rtseqlock.h.
#define rt_seqlock_init | ( | x | ) |
Value:
do { \ *(x) = (rt_seqlock_t)RT_SEQLOCK_UNLOCKED; \ } while (0)
Definition at line 83 of file rtseqlock.h.
#define rt_write_seqlock_irqsave | ( | sl, | |||
flags | ) |
Value:
do { \ rtdm_lock_get_irqsave(&sl->lock, flags); \ ++sl->sequence; \ smp_wmb(); \ } while (0)
sl | the sequence lock | |
flags | the flags of type rtdm_lockctx_t that are safed |
Definition at line 154 of file rtseqlock.h.
#define rt_write_sequnlock_irqrestore | ( | sl, | |||
flags | ) |
Value:
do { \ smp_wmb(); \ sl->sequence++; \ rtdm_lock_put_irqrestore(&sl->lock, flags); \ } while (0)
sl | the sequence lock | |
flags | the flags of type rtdm_lockctx_t that are safed |
Definition at line 168 of file rtseqlock.h.
static void rt_write_seqlock | ( | seqlock_t * | sl | ) | [inline, static] |
Lock out other writers and update the count. Acts like a normal spin_lock/unlock. Don't need preempt_disable() because that is in the spin_lock already.
sl | the sequence lock |
Definition at line 95 of file rtseqlock.h.
static void rt_write_sequnlock | ( | seqlock_t * | sl | ) | [inline, static] |
Unlocks other writer and update the count again.
sl | the sequence lock |
Definition at line 107 of file rtseqlock.h.
static unsigned int rt_read_seqbegin | ( | const seqlock_t * | sl | ) | [inline, static] |
Start of read calculation -- fetch last complete writer token
sl | the sequence lock |
sl->sequence
at the beginning before reading has started (in a SMP-safe manner) Definition at line 121 of file rtseqlock.h.
static int rt_read_seqretry | ( | const seqlock_t * | sl, | |
unsigned int | iv | |||
) | [inline, static] |
Test if reader processed invalid data.
Using xor saves one conditional branch (it's the same as ==
here).
sl | the sequence lock | |
iv | the value that was fetched |
true
if the read must be repeated and false
otherwise Definition at line 142 of file rtseqlock.h.