00001 #ifndef __SEQLOCK_H
00002 #define __SEQLOCK_H
00003
00004
00005
00006 #include <asm/xenomai/atomic.h>
00007
00008 typedef struct xnseqcount {
00009 unsigned sequence;
00010 } xnseqcount_t;
00011
00012 #define XNSEQCNT_ZERO { 0 }
00013 #define xnseqcount_init(x) do { *(x) = (xnseqcount_t) SEQCNT_ZERO; } while (0)
00014
00015
00016 static inline unsigned xnread_seqcount_begin(const xnseqcount_t *s)
00017 {
00018 unsigned ret;
00019
00020 repeat:
00021 ret = s->sequence;
00022 xnarch_read_memory_barrier();
00023 if (unlikely(ret & 1)) {
00024 cpu_relax();
00025 goto repeat;
00026 }
00027 return ret;
00028 }
00029
00030
00031
00032
00033 static inline int xnread_seqcount_retry(const xnseqcount_t *s, unsigned start)
00034 {
00035 xnarch_read_memory_barrier();
00036
00037 return s->sequence != start;
00038 }
00039
00040
00041
00042
00043
00044
00045 static inline void xnwrite_seqcount_begin(xnseqcount_t *s)
00046 {
00047 s->sequence++;
00048 xnarch_write_memory_barrier();
00049 }
00050
00051 static inline void xnwrite_seqcount_end(xnseqcount_t *s)
00052 {
00053 xnarch_write_memory_barrier();
00054 s->sequence++;
00055 }
00056
00057 #endif