00001 #ifndef ARCH_SMP_ATOMIC_H 00002 #define ARCH_SMP_ATOMIC_H 00003 00004 /* 00005 * Make sure gcc doesn't try to be clever and move things around 00006 * on us. We need to use _exactly_ the address the user gave us, 00007 * not some alias that contains the same information. 00008 */ 00009 typedef struct { volatile int counter; } atomic_t; 00010 00011 #define ATOMIC_INIT(i) { (i) } 00012 00013 /* 00014 * Atomic operations that C can't guarantee us. Useful for 00015 * resource counting etc.. 00016 */ 00017 00018 /** 00019 * atomic_read - read atomic variable 00020 * @v: pointer of type atomic_t 00021 * 00022 * Atomically reads the value of @v. Note that the guaranteed 00023 * useful range of an atomic_t is only 24 bits. 00024 */ 00025 #define atomic_read(v) ((v)->counter) 00026 00027 /** 00028 * atomic_set - set atomic variable 00029 * @v: pointer of type atomic_t 00030 * @i: required value 00031 * 00032 * Atomically sets the value of @v to @i. Note that the guaranteed 00033 * useful range of an atomic_t is only 24 bits. 00034 */ 00035 #define atomic_set(v,i) (((v)->counter) = (i)) 00036 00037 /** 00038 * atomic_inc - increment atomic variable 00039 * @v: pointer of type atomic_t 00040 * 00041 * Atomically increments @v by 1. Note that the guaranteed 00042 * useful range of an atomic_t is only 24 bits. 00043 */ 00044 static __inline__ __attribute__((always_inline)) void atomic_inc(atomic_t *v) 00045 { 00046 __asm__ __volatile__( 00047 "lock ; incl %0" 00048 :"=m" (v->counter) 00049 :"m" (v->counter)); 00050 } 00051 00052 /** 00053 * atomic_dec - decrement atomic variable 00054 * @v: pointer of type atomic_t 00055 * 00056 * Atomically decrements @v by 1. Note that the guaranteed 00057 * useful range of an atomic_t is only 24 bits. 00058 */ 00059 static __inline__ __attribute__((always_inline)) void atomic_dec(atomic_t *v) 00060 { 00061 __asm__ __volatile__( 00062 "lock ; decl %0" 00063 :"=m" (v->counter) 00064 :"m" (v->counter)); 00065 } 00066 00067 00068 00069 #endif /* ARCH_SMP_ATOMIC_H */
1.5.5