00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef RTSEQLOCK_H
00022 #define RTSEQLOCK_H
00023
00024 #ifdef HAVE_CONFIG_H
00025 #include "config/config.h"
00026 #endif
00027 #include <asm/system.h>
00028 #include <rtdm/rtdm_driver.h>
00029
00070 typedef struct {
00071 unsigned int sequence;
00072 rtdm_lock_t lock;
00073 } rt_seqlock_t;
00074
00078 #define RT_SEQLOCK_UNLOCKED { 0, RTDM_LOCK_UNLOCKED }
00079
00083 #define rt_seqlock_init(x) \
00084 do { \
00085 *(x) = (rt_seqlock_t)RT_SEQLOCK_UNLOCKED; \
00086 } while (0)
00087
00095 static inline void rt_write_seqlock(seqlock_t *sl)
00096 {
00097 rtdm_lock_get(&sl->lock);
00098 ++sl->sequence;
00099 smp_wmb();
00100 }
00101
00107 static inline void rt_write_sequnlock(seqlock_t *sl)
00108 {
00109 smp_wmb();
00110 sl->sequence++;
00111 rtdm_lock_put(&sl->lock);
00112 }
00113
00121 static inline unsigned int rt_read_seqbegin(const seqlock_t *sl)
00122 {
00123 unsigned ret = sl->sequence;
00124 smp_rmb();
00125 return ret;
00126 }
00127
00142 static inline int rt_read_seqretry(const seqlock_t *sl, unsigned int iv)
00143 {
00144 smp_rmb();
00145 return (iv & 1) | (sl->sequence ^ iv);
00146 }
00147
00154 #define rt_write_seqlock_irqsave(sl, flags) \
00155 do { \
00156 rtdm_lock_get_irqsave(&sl->lock, flags); \
00157 ++sl->sequence; \
00158 smp_wmb(); \
00159 } while (0)
00160
00161
00168 #define rt_write_sequnlock_irqrestore(sl, flags) \
00169 do { \
00170 smp_wmb(); \
00171 sl->sequence++; \
00172 rtdm_lock_put_irqrestore(&sl->lock, flags); \
00173 } while (0)
00174
00175
00176 #endif
00177
00178