Skip to content

Commit

Permalink
atomic_t: Cast to volatile when accessing atomic variables
Browse files Browse the repository at this point in the history
In preparation for removing volatile from the atomic_t definition, this
patch adds a volatile cast to all the atomic read functions.

Signed-off-by: Anton Blanchard <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
antonblanchard authored and torvalds committed May 17, 2010
1 parent e40152e commit f3d46f9
Show file tree
Hide file tree
Showing 20 changed files with 25 additions and 25 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) ( (atomic_t) { (i) } )
#define ATOMIC64_INIT(i) ( (atomic64_t) { (i) } )

#define atomic_read(v) ((v)->counter + 0)
#define atomic64_read(v) ((v)->counter + 0)
#define atomic_read(v) (*(volatile int *)&(v)->counter)
#define atomic64_read(v) (*(volatile long *)&(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 @@ -24,7 +24,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) ((v)->counter)
#define atomic_read(v) (*(volatile int *)&(v)->counter)
#define atomic_set(v,i) (((v)->counter) = (i))

#if __LINUX_ARM_ARCH__ >= 6
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) ((v)->counter)
#define atomic_read(v) (*(volatile int *)&(v)->counter)
#define atomic_set(v, i) (((v)->counter) = i)

/*
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 @@ -15,7 +15,7 @@

#define ATOMIC_INIT(i) { (i) }

#define atomic_read(v) ((v)->counter)
#define atomic_read(v) (*(volatile int *)&(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 @@ -36,7 +36,7 @@
#define smp_mb__after_atomic_inc() barrier()

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

#ifndef CONFIG_FRV_OUTOFLINE_ATOMIC_OPS
Expand Down
2 changes: 1 addition & 1 deletion arch/h8300/include/asm/atomic.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

#define ATOMIC_INIT(i) { (i) }

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

#include <asm/system.h>
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) ((atomic_t) { (i) })
#define ATOMIC64_INIT(i) ((atomic64_t) { (i) })

#define atomic_read(v) ((v)->counter)
#define atomic64_read(v) ((v)->counter)
#define atomic_read(v) (*(volatile int *)&(v)->counter)
#define atomic64_read(v) (*(volatile long *)&(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 @@ -26,7 +26,7 @@
*
* Atomically reads the value of @v.
*/
#define atomic_read(v) ((v)->counter)
#define atomic_read(v) (*(volatile int *)&(v)->counter)

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

#define ATOMIC_INIT(i) { (i) }

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

static inline void atomic_add(int i, atomic_t *v)
Expand Down
2 changes: 1 addition & 1 deletion arch/m68k/include/asm/atomic_no.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

#define ATOMIC_INIT(i) { (i) }

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

static __inline__ void atomic_add(int i, atomic_t *v)
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) ((v)->counter)
#define atomic_read(v) (*(volatile int *)&(v)->counter)

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

/*
* atomic64_set - set atomic variable
Expand Down
2 changes: 1 addition & 1 deletion arch/mn10300/include/asm/atomic.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
* Atomically reads the value of @v. Note that the guaranteed
* useful range of an atomic_t is only 24 bits.
*/
#define atomic_read(v) ((v)->counter)
#define atomic_read(v) (*(volatile int *)&(v)->counter)

/**
* atomic_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 @@ -189,7 +189,7 @@ static __inline__ void atomic_set(atomic_t *v, int i)

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

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

#define atomic64_add(i,v) ((void)(__atomic64_add_return( ((s64)(i)),(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 @@ -13,7 +13,7 @@

#define ATOMIC_INIT(i) ( (atomic_t) { (i) } )

#define atomic_read(v) ((v)->counter)
#define atomic_read(v) (*(volatile int *)&(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 @@ -25,7 +25,7 @@ extern int atomic_cmpxchg(atomic_t *, int, int);
extern int atomic_add_unless(atomic_t *, int, int);
extern void atomic_set(atomic_t *, int);

#define atomic_read(v) ((v)->counter)
#define atomic_read(v) (*(volatile int *)&(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 @@ -13,8 +13,8 @@
#define ATOMIC_INIT(i) { (i) }
#define ATOMIC64_INIT(i) { (i) }

#define atomic_read(v) ((v)->counter)
#define atomic64_read(v) ((v)->counter)
#define atomic_read(v) (*(volatile int *)&(v)->counter)
#define atomic64_read(v) (*(volatile long *)&(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 @@ -22,7 +22,7 @@
*/
static inline int atomic_read(const atomic_t *v)
{
return v->counter;
return (*(volatile int *)&(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 v->counter;
return (*(volatile long *)&(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 @@ -46,7 +46,7 @@
*
* Atomically reads the value of @v.
*/
#define atomic_read(v) ((v)->counter)
#define atomic_read(v) (*(volatile int *)&(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 @@ -33,7 +33,7 @@
* Atomically reads the value of @v. Note that the guaranteed
* useful range of an atomic_t is only 24 bits.
*/
#define atomic_read(v) ((v)->counter)
#define atomic_read(v) (*(volatile int *)&(v)->counter)

/**
* atomic_set - set atomic variable
Expand Down

0 comments on commit f3d46f9

Please sign in to comment.