Skip to content

Commit bfaf9a4

Browse files
authored
thread-rcu: Fix the types in rcu.h and barrier counter (#14)
rcu.h: - Fix the parameter type of smp_store_release(). The parameter that wants to store should be a pointer type. - Fix the type of tid in rcu_node. - Rename all the internal parameters in Linux kernel style API to make it more prettier. main.c: - Fix the barrier counter that doesn't initialize after exit. No functional change.
1 parent 694204f commit bfaf9a4

File tree

2 files changed

+29
-28
lines changed

2 files changed

+29
-28
lines changed

thread-rcu/main.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ static inline void thread_barrier(struct barrier_struct *b, size_t n)
2323
pthread_mutex_lock(&b->lock);
2424
b->count++;
2525
if (b->count == n) {
26+
b->count = 0;
2627
pthread_mutex_unlock(&b->lock);
2728
atomic_store_explicit(&b->flag, local_sense, memory_order_release);
2829
} else {

thread-rcu/rcu.h

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -75,32 +75,32 @@ static inline void spin_unlock(spinlock_t *sp)
7575
memory_order_relaxed); \
7676
} while (0)
7777

78-
#define smp_store_release(x, val) \
79-
do { \
80-
atomic_store_explicit((volatile _Atomic __typeof__(x) *) &x, (val), \
81-
memory_order_release); \
78+
#define smp_store_release(x, val) \
79+
do { \
80+
__typeof__(*x) ___x; \
81+
atomic_store_explicit((volatile _Atomic __typeof__(___x) *) x, (val), \
82+
memory_order_release); \
8283
} while (0)
8384

84-
#define atomic_fetch_add_release(x, v) \
85-
({ \
86-
__typeof__(*x) __a_a_r_x; \
87-
atomic_fetch_add_explicit( \
88-
(volatile _Atomic __typeof__(__a_a_r_x) *) x, v, \
89-
memory_order_release); \
85+
#define atomic_fetch_add_release(x, v) \
86+
({ \
87+
__typeof__(*x) ___x; \
88+
atomic_fetch_add_explicit((volatile _Atomic __typeof__(___x) *) x, v, \
89+
memory_order_release); \
9090
})
9191

92-
#define atomic_fetch_or_release(x, v) \
93-
({ \
94-
__typeof__(*x) __a_r_r_x; \
95-
atomic_fetch_or_explicit((volatile _Atomic __typeof__(__a_r_r_x) *) x, \
96-
v, memory_order_release); \
92+
#define atomic_fetch_or_release(x, v) \
93+
({ \
94+
__typeof__(*x) ___x; \
95+
atomic_fetch_or_explicit((volatile _Atomic __typeof__(___x) *) x, v, \
96+
memory_order_release); \
9797
})
9898

99-
#define atomic_xchg_release(x, v) \
100-
({ \
101-
__typeof__(*x) __a_c_r_x; \
102-
atomic_exchange_explicit((volatile _Atomic __typeof__(__a_c_r_x) *) x, \
103-
v, memory_order_release); \
99+
#define atomic_xchg_release(x, v) \
100+
({ \
101+
__typeof__(*x) ___x; \
102+
atomic_exchange_explicit((volatile _Atomic __typeof__(___x) *) x, v, \
103+
memory_order_release); \
104104
})
105105

106106
#include <errno.h>
@@ -140,7 +140,7 @@ static inline void spin_unlock(spinlock_t *sp)
140140
* to access it.
141141
*/
142142
struct rcu_node {
143-
unsigned int tid;
143+
uintptr_t tid;
144144
uintptr_t __next_rcu_nesting;
145145
} __rcu_aligned;
146146

@@ -163,12 +163,12 @@ struct rcu_data {
163163
} while (0)
164164
#define rcu_unset_nesting(np) \
165165
do { \
166-
smp_store_release((np)->__next_rcu_nesting, \
166+
smp_store_release(&(np)->__next_rcu_nesting, \
167167
READ_ONCE((np)->__next_rcu_nesting) & ~0x3); \
168168
} while (0)
169169
#define rcu_next(np) \
170170
((struct rcu_node *) (READ_ONCE((np)->__next_rcu_nesting) & ~0x3))
171-
#define rcu_next_mask(nrn) ((struct rcu_node *) ((uintptr_t) (nrn) & ~0x3))
171+
#define rcu_next_mask(nrn) ((struct rcu_node *) ((uintptr_t)(nrn) & ~0x3))
172172

173173
static struct rcu_data rcu_data = {
174174
.nr_thread = 0,
@@ -309,11 +309,11 @@ static inline void synchronize_rcu(void)
309309
smp_mb();
310310
}
311311

312-
#define rcu_dereference(p) \
313-
({ \
314-
__typeof__(*p) *__r_d_p = (__typeof__(*p) __force *) READ_ONCE(p); \
315-
rcu_check_sparse(p, __rcu); \
316-
__r_d_p; \
312+
#define rcu_dereference(p) \
313+
({ \
314+
__typeof__(*p) *___p = (__typeof__(*p) __force *) READ_ONCE(p); \
315+
rcu_check_sparse(p, __rcu); \
316+
___p; \
317317
})
318318

319319
#define rcu_assign_pointer(p, v) \

0 commit comments

Comments
 (0)