Skip to content

Commit

Permalink
locking,arch: Use ACCESS_ONCE() instead of cast to volatile in atomic…
Browse files Browse the repository at this point in the history
…_read()

Use the much more reader friendly ACCESS_ONCE() instead of the cast to volatile.
This is purely a stylistic change.

Signed-off-by: Pranith Kumar <[email protected]>
Acked-by: Jesper Nilsson <[email protected]>
Acked-by: Hans-Christian Egtvedt <[email protected]>
Acked-by: Max Filippov <[email protected]>
Signed-off-by: Peter Zijlstra (Intel) <[email protected]>
Cc: Linus Torvalds <[email protected]>
Cc: [email protected]
Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Ingo Molnar <[email protected]>
  • Loading branch information
pranith authored and Ingo Molnar committed Oct 3, 2014
1 parent da4c544 commit 2291059
Show file tree
Hide file tree
Showing 18 changed files with 24 additions and 24 deletions.
4 changes: 2 additions & 2 deletions arch/alpha/include/asm/atomic.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
#define ATOMIC_INIT(i) { (i) }
#define ATOMIC64_INIT(i) { (i) }

#define atomic_read(v) (*(volatile int *)&(v)->counter)
#define atomic64_read(v) (*(volatile long *)&(v)->counter)
#define atomic_read(v) ACCESS_ONCE((v)->counter)
#define atomic64_read(v) ACCESS_ONCE((v)->counter)

#define atomic_set(v,i) ((v)->counter = (i))
#define atomic64_set(v,i) ((v)->counter = (i))
Expand Down
2 changes: 1 addition & 1 deletion arch/arm/include/asm/atomic.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
* strex/ldrex monitor on some implementations. The reason we can use it for
* atomic_set() is the clrex or dummy strex done on every exception return.
*/
#define atomic_read(v) (*(volatile int *)&(v)->counter)
#define atomic_read(v) ACCESS_ONCE((v)->counter)
#define atomic_set(v,i) (((v)->counter) = (i))

#if __LINUX_ARM_ARCH__ >= 6
Expand Down
4 changes: 2 additions & 2 deletions arch/arm64/include/asm/atomic.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
* strex/ldrex monitor on some implementations. The reason we can use it for
* atomic_set() is the clrex or dummy strex done on every exception return.
*/
#define atomic_read(v) (*(volatile int *)&(v)->counter)
#define atomic_read(v) ACCESS_ONCE((v)->counter)
#define atomic_set(v,i) (((v)->counter) = (i))

/*
Expand Down Expand Up @@ -139,7 +139,7 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
*/
#define ATOMIC64_INIT(i) { (i) }

#define atomic64_read(v) (*(volatile long *)&(v)->counter)
#define atomic64_read(v) ACCESS_ONCE((v)->counter)
#define atomic64_set(v,i) (((v)->counter) = (i))

#define ATOMIC64_OP(op, asm_op) \
Expand Down
2 changes: 1 addition & 1 deletion arch/avr32/include/asm/atomic.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

#define ATOMIC_INIT(i) { (i) }

#define atomic_read(v) (*(volatile int *)&(v)->counter)
#define atomic_read(v) ACCESS_ONCE((v)->counter)
#define atomic_set(v, i) (((v)->counter) = i)

#define ATOMIC_OP_RETURN(op, asm_op, asm_con) \
Expand Down
2 changes: 1 addition & 1 deletion arch/cris/include/asm/atomic.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

#define ATOMIC_INIT(i) { (i) }

#define atomic_read(v) (*(volatile int *)&(v)->counter)
#define atomic_read(v) ACCESS_ONCE((v)->counter)
#define atomic_set(v,i) (((v)->counter) = (i))

/* These should be written in asm but we do it in C for now. */
Expand Down
2 changes: 1 addition & 1 deletion arch/frv/include/asm/atomic.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
*/

#define ATOMIC_INIT(i) { (i) }
#define atomic_read(v) (*(volatile int *)&(v)->counter)
#define atomic_read(v) ACCESS_ONCE((v)->counter)
#define atomic_set(v, i) (((v)->counter) = (i))

#ifndef CONFIG_FRV_OUTOFLINE_ATOMIC_OPS
Expand Down
4 changes: 2 additions & 2 deletions arch/ia64/include/asm/atomic.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
#define ATOMIC_INIT(i) { (i) }
#define ATOMIC64_INIT(i) { (i) }

#define atomic_read(v) (*(volatile int *)&(v)->counter)
#define atomic64_read(v) (*(volatile long *)&(v)->counter)
#define atomic_read(v) ACCESS_ONCE((v)->counter)
#define atomic64_read(v) ACCESS_ONCE((v)->counter)

#define atomic_set(v,i) (((v)->counter) = (i))
#define atomic64_set(v,i) (((v)->counter) = (i))
Expand Down
2 changes: 1 addition & 1 deletion arch/m32r/include/asm/atomic.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
*
* Atomically reads the value of @v.
*/
#define atomic_read(v) (*(volatile int *)&(v)->counter)
#define atomic_read(v) ACCESS_ONCE((v)->counter)

/**
* atomic_set - set atomic variable
Expand Down
2 changes: 1 addition & 1 deletion arch/m68k/include/asm/atomic.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

#define ATOMIC_INIT(i) { (i) }

#define atomic_read(v) (*(volatile int *)&(v)->counter)
#define atomic_read(v) ACCESS_ONCE((v)->counter)
#define atomic_set(v, i) (((v)->counter) = i)

/*
Expand Down
4 changes: 2 additions & 2 deletions arch/mips/include/asm/atomic.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
*
* Atomically reads the value of @v.
*/
#define atomic_read(v) (*(volatile int *)&(v)->counter)
#define atomic_read(v) ACCESS_ONCE((v)->counter)

/*
* atomic_set - set atomic variable
Expand Down Expand Up @@ -306,7 +306,7 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
* @v: pointer of type atomic64_t
*
*/
#define atomic64_read(v) (*(volatile long *)&(v)->counter)
#define atomic64_read(v) ACCESS_ONCE((v)->counter)

/*
* atomic64_set - set atomic variable
Expand Down
4 changes: 2 additions & 2 deletions arch/parisc/include/asm/atomic.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ static __inline__ void atomic_set(atomic_t *v, int i)

static __inline__ int atomic_read(const atomic_t *v)
{
return (*(volatile int *)&(v)->counter);
return ACCESS_ONCE((v)->counter);
}

/* exported interface */
Expand Down Expand Up @@ -204,7 +204,7 @@ atomic64_set(atomic64_t *v, s64 i)
static __inline__ s64
atomic64_read(const atomic64_t *v)
{
return (*(volatile long *)&(v)->counter);
return ACCESS_ONCE((v)->counter);
}

#define atomic64_inc(v) (atomic64_add( 1,(v)))
Expand Down
2 changes: 1 addition & 1 deletion arch/sh/include/asm/atomic.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

#define ATOMIC_INIT(i) { (i) }

#define atomic_read(v) (*(volatile int *)&(v)->counter)
#define atomic_read(v) ACCESS_ONCE((v)->counter)
#define atomic_set(v,i) ((v)->counter = (i))

#if defined(CONFIG_GUSA_RB)
Expand Down
2 changes: 1 addition & 1 deletion arch/sparc/include/asm/atomic_32.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ int atomic_cmpxchg(atomic_t *, int, int);
int __atomic_add_unless(atomic_t *, int, int);
void atomic_set(atomic_t *, int);

#define atomic_read(v) (*(volatile int *)&(v)->counter)
#define atomic_read(v) ACCESS_ONCE((v)->counter)

#define atomic_add(i, v) ((void)atomic_add_return( (int)(i), (v)))
#define atomic_sub(i, v) ((void)atomic_add_return(-(int)(i), (v)))
Expand Down
4 changes: 2 additions & 2 deletions arch/sparc/include/asm/atomic_64.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
#define ATOMIC_INIT(i) { (i) }
#define ATOMIC64_INIT(i) { (i) }

#define atomic_read(v) (*(volatile int *)&(v)->counter)
#define atomic64_read(v) (*(volatile long *)&(v)->counter)
#define atomic_read(v) ACCESS_ONCE((v)->counter)
#define atomic64_read(v) ACCESS_ONCE((v)->counter)

#define atomic_set(v, i) (((v)->counter) = i)
#define atomic64_set(v, i) (((v)->counter) = i)
Expand Down
2 changes: 1 addition & 1 deletion arch/x86/include/asm/atomic.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
*/
static inline int atomic_read(const atomic_t *v)
{
return (*(volatile int *)&(v)->counter);
return ACCESS_ONCE((v)->counter);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion arch/x86/include/asm/atomic64_64.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/
static inline long atomic64_read(const atomic64_t *v)
{
return (*(volatile long *)&(v)->counter);
return ACCESS_ONCE((v)->counter);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion arch/xtensa/include/asm/atomic.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
*
* Atomically reads the value of @v.
*/
#define atomic_read(v) (*(volatile int *)&(v)->counter)
#define atomic_read(v) ACCESS_ONCE((v)->counter)

/**
* atomic_set - set atomic variable
Expand Down
2 changes: 1 addition & 1 deletion include/asm-generic/atomic.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ ATOMIC_OP(or, |)
* Atomically reads the value of @v.
*/
#ifndef atomic_read
#define atomic_read(v) (*(volatile int *)&(v)->counter)
#define atomic_read(v) ACCESS_ONCE((v)->counter)
#endif

/**
Expand Down

0 comments on commit 2291059

Please sign in to comment.