9 * Copyright February 2009 - Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca>
11 * Distributed under GPLv2
14 /* The "volatile" is due to gcc bugs */
15 #define barrier() __asm__ __volatile__("": : :"memory")
17 /* x86 32/64 specific */
18 #define mb() asm volatile("mfence":::"memory")
19 #define rmb() asm volatile("lfence":::"memory")
20 #define wmb() asm volatile("sfence" ::: "memory")
25 static inline void atomic_inc(int *v
)
27 asm volatile("lock; incl %0"
31 /* Nop everywhere except on alpha. */
32 #define smp_read_barrier_depends()
35 * Prevent the compiler from merging or refetching accesses. The compiler
36 * is also forbidden from reordering successive instances of ACCESS_ONCE(),
37 * but only when the compiler is aware of some particular ordering. One way
38 * to make the compiler aware of ordering is to put the two invocations of
39 * ACCESS_ONCE() in different C statements.
41 * This macro does absolutely -nothing- to prevent the CPU from reordering,
42 * merging, or refetching absolutely anything at any time. Its main intended
43 * use is to mediate communication between process-level code and irq/NMI
44 * handlers, all running on the same CPU.
46 #define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
49 * rcu_dereference - fetch an RCU-protected pointer in an
50 * RCU read-side critical section. This pointer may later
51 * be safely dereferenced.
53 * Inserts memory barriers on architectures that require them
54 * (currently only the Alpha), and, more importantly, documents
55 * exactly which pointers are protected by RCU.
58 #define rcu_dereference(p) ({ \
59 typeof(p) _________p1 = ACCESS_ONCE(p); \
60 smp_read_barrier_depends(); \
64 #define SIGURCU SIGUSR1
66 /* Global quiescent period parity */
67 extern int urcu_qparity
;
69 extern int __thread urcu_active_readers
[2];
71 static inline int get_urcu_qparity(void)
77 * returns urcu_parity.
79 static inline int rcu_read_lock(void)
81 int urcu_parity
= get_urcu_qparity();
82 urcu_active_readers
[urcu_parity
]++;
84 * Increment active readers count before accessing the pointer.
85 * See force_mb_all_threads().
91 static inline void rcu_read_unlock(int urcu_parity
)
95 * Finish using rcu before decrementing the pointer.
96 * See force_mb_all_threads().
98 urcu_active_readers
[urcu_parity
]--;
101 extern void rcu_write_lock(void);
102 extern void rcu_write_unlock(void);
104 extern void *urcu_publish_content(void **ptr
, void *new);
107 * Reader thread registration.
109 extern void urcu_register_thread(void);
110 extern void urcu_register_thread(void);