Skip to content

thread-rcu: Fix the types in rcu.h and barrier counter #14

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions thread-rcu/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ static inline void thread_barrier(struct barrier_struct *b, size_t n)
pthread_mutex_lock(&b->lock);
b->count++;
if (b->count == n) {
b->count = 0;
pthread_mutex_unlock(&b->lock);
atomic_store_explicit(&b->flag, local_sense, memory_order_release);
} else {
Expand Down
56 changes: 28 additions & 28 deletions thread-rcu/rcu.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,32 +75,32 @@ static inline void spin_unlock(spinlock_t *sp)
memory_order_relaxed); \
} while (0)

#define smp_store_release(x, val) \
do { \
atomic_store_explicit((volatile _Atomic __typeof__(x) *) &x, (val), \
memory_order_release); \
#define smp_store_release(x, val) \
do { \
__typeof__(*x) ___x; \
atomic_store_explicit((volatile _Atomic __typeof__(___x) *) x, (val), \
memory_order_release); \
} while (0)

#define atomic_fetch_add_release(x, v) \
({ \
__typeof__(*x) __a_a_r_x; \
atomic_fetch_add_explicit( \
(volatile _Atomic __typeof__(__a_a_r_x) *) x, v, \
memory_order_release); \
#define atomic_fetch_add_release(x, v) \
({ \
__typeof__(*x) ___x; \
atomic_fetch_add_explicit((volatile _Atomic __typeof__(___x) *) x, v, \
memory_order_release); \
})

#define atomic_fetch_or_release(x, v) \
({ \
__typeof__(*x) __a_r_r_x; \
atomic_fetch_or_explicit((volatile _Atomic __typeof__(__a_r_r_x) *) x, \
v, memory_order_release); \
#define atomic_fetch_or_release(x, v) \
({ \
__typeof__(*x) ___x; \
atomic_fetch_or_explicit((volatile _Atomic __typeof__(___x) *) x, v, \
memory_order_release); \
})

#define atomic_xchg_release(x, v) \
({ \
__typeof__(*x) __a_c_r_x; \
atomic_exchange_explicit((volatile _Atomic __typeof__(__a_c_r_x) *) x, \
v, memory_order_release); \
#define atomic_xchg_release(x, v) \
({ \
__typeof__(*x) ___x; \
atomic_exchange_explicit((volatile _Atomic __typeof__(___x) *) x, v, \
memory_order_release); \
})

#include <errno.h>
Expand Down Expand Up @@ -140,7 +140,7 @@ static inline void spin_unlock(spinlock_t *sp)
* to access it.
*/
struct rcu_node {
unsigned int tid;
uintptr_t tid;
uintptr_t __next_rcu_nesting;
} __rcu_aligned;

Expand All @@ -163,12 +163,12 @@ struct rcu_data {
} while (0)
#define rcu_unset_nesting(np) \
do { \
smp_store_release((np)->__next_rcu_nesting, \
smp_store_release(&(np)->__next_rcu_nesting, \
READ_ONCE((np)->__next_rcu_nesting) & ~0x3); \
} while (0)
#define rcu_next(np) \
((struct rcu_node *) (READ_ONCE((np)->__next_rcu_nesting) & ~0x3))
#define rcu_next_mask(nrn) ((struct rcu_node *) ((uintptr_t) (nrn) & ~0x3))
#define rcu_next_mask(nrn) ((struct rcu_node *) ((uintptr_t)(nrn) & ~0x3))

static struct rcu_data rcu_data = {
.nr_thread = 0,
Expand Down Expand Up @@ -309,11 +309,11 @@ static inline void synchronize_rcu(void)
smp_mb();
}

#define rcu_dereference(p) \
({ \
__typeof__(*p) *__r_d_p = (__typeof__(*p) __force *) READ_ONCE(p); \
rcu_check_sparse(p, __rcu); \
__r_d_p; \
#define rcu_dereference(p) \
({ \
__typeof__(*p) *___p = (__typeof__(*p) __force *) READ_ONCE(p); \
rcu_check_sparse(p, __rcu); \
___p; \
})

#define rcu_assign_pointer(p, v) \
Expand Down