URL
https://opencores.org/ocsvn/or1k/or1k/trunk
Subversion Repositories or1k
[/] [or1k/] [trunk/] [linux/] [linux-2.4/] [include/] [asm-or32/] [atomic.h] - Rev 1774
Go to most recent revision | Compare with Previous | Blame | View Log
#ifndef _OR32_ATOMIC_H #define _OR32_ATOMIC_H #include <linux/config.h> #include <asm/system.h> #ifdef __KERNEL__ #define ATOMIC_INIT(i) { (i) } #define atomic_read(v) ((v)->counter) #define atomic_set(v,i) (((v)->counter) = (i)) /* * Atomic operations that C can't guarantee us. Useful for * resource counting etc.. */ typedef struct { volatile int counter; } atomic_t; static __inline__ void atomic_add(int i, volatile atomic_t *v) { unsigned long flags; save_and_cli(flags); v->counter += i; restore_flags(flags); } static __inline__ void atomic_sub(int i, volatile atomic_t *v) { unsigned long flags; save_and_cli(flags); v->counter -= i; restore_flags(flags); } static __inline__ int atomic_add_return(int i, volatile atomic_t *v) { unsigned long flags; int retval; save_and_cli(flags); retval = (v->counter += i); restore_flags(flags); return retval; } static __inline__ int atomic_sub_return(int i, volatile atomic_t *v) { unsigned long flags; int retval; save_and_cli(flags); retval = (v->counter -= i); restore_flags(flags); return retval; } static __inline__ int atomic_sub_and_test(int i, volatile atomic_t *v) { int retval; unsigned long flags; save_and_cli(flags); retval = (v->counter -= i) == 0; restore_flags(flags); return retval; } static __inline__ void atomic_inc(volatile atomic_t *v) { unsigned long flags; save_and_cli(flags); (v->counter)++; restore_flags(flags); } static __inline__ void atomic_dec(volatile atomic_t *v) { unsigned long flags; save_and_cli(flags); (v->counter)--; restore_flags(flags); } static __inline__ int atomic_inc_return(volatile atomic_t *v) { unsigned long flags; int retval; save_and_cli(flags); retval = (v->counter)++; restore_flags(flags); return retval; } static __inline__ int atomic_dec_return(volatile atomic_t *v) { unsigned long flags; int retval; save_and_cli(flags); retval = (v->counter)--; restore_flags(flags); return retval; } static __inline__ int atomic_dec_and_test(volatile atomic_t *v) { int retval; unsigned long flags; save_and_cli(flags); retval = --(v->counter) == 0; restore_flags(flags); return retval; } static __inline__ int atomic_inc_and_test(volatile atomic_t *v) { int retval; unsigned long flags; save_and_cli(flags); retval = ++(v->counter) == 0; restore_flags(flags); return retval; } /* Atomic operations are already serializing */ #define smp_mb__before_atomic_dec() barrier() #define smp_mb__after_atomic_dec() barrier() #define smp_mb__before_atomic_inc() barrier() #define smp_mb__after_atomic_inc() barrier() #endif #endif /* _OR32_ATOMIC_H */
Go to most recent revision | Compare with Previous | Blame | View Log