00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef _RTAI_ASM_I386_ATOMIC_H
00021 #define _RTAI_ASM_I386_ATOMIC_H
00022
00023 #include <linux/bitops.h>
00024
00025 #ifdef __KERNEL__
00026
00027 #include <asm/atomic.h>
00028 #include <asm/system.h>
00029
00030 #define atomic_xchg(ptr,v) xchg(ptr,v)
00031 #define atomic_cmpxchg(ptr,o,n) cmpxchg(ptr,o,n)
00032 #define xnarch_memory_barrier() smp_mb()
00033
00034 #else
00035
00036 #ifndef likely
00037 #if __GNUC__ == 2 && __GNUC_MINOR__ < 96
00038 #define __builtin_expect(x, expected_value) (x)
00039 #endif
00040 #define likely(x) __builtin_expect(!!(x), 1)
00041 #define unlikely(x) __builtin_expect(!!(x), 0)
00042 #endif
00043
00044 #include <asm/atomic.h>
00045
00046 struct __rtai_xchg_dummy { unsigned long a[100]; };
00047 #define __rtai_xg(x) ((struct __rtai_xchg_dummy *)(x))
00048
00049 static inline unsigned long atomic_xchg (volatile void *ptr,
00050 unsigned long x)
00051 {
00052 __asm__ __volatile__(LOCK_PREFIX "xchgl %0,%1"
00053 :"=r" (x)
00054 :"m" (*__rtai_xg(ptr)), "0" (x)
00055 :"memory");
00056 return x;
00057 }
00058
00059 static inline unsigned long atomic_cmpxchg (volatile void *ptr,
00060 unsigned long o,
00061 unsigned long n)
00062 {
00063 unsigned long prev;
00064
00065 __asm__ __volatile__(LOCK_PREFIX "cmpxchgl %1,%2"
00066 : "=a"(prev)
00067 : "q"(n), "m" (*__rtai_xg(ptr)), "0" (o)
00068 : "memory");
00069
00070 return prev;
00071 }
00072
00073 #define xnarch_memory_barrier() __asm__ __volatile__("": : :"memory")
00074
00075
00076 #undef ADDR
00077
00078 #endif
00079
00080 typedef atomic_t atomic_counter_t;
00081 typedef unsigned long atomic_flags_t;
00082
00083 #define xnarch_atomic_set(pcounter,i) atomic_set(pcounter,i)
00084 #define xnarch_atomic_get(pcounter) atomic_read(pcounter)
00085 #define xnarch_atomic_inc(pcounter) atomic_inc(pcounter)
00086 #define xnarch_atomic_dec(pcounter) atomic_dec(pcounter)
00087 #define xnarch_atomic_inc_and_test(pcounter) atomic_inc_and_test(pcounter)
00088 #define xnarch_atomic_dec_and_test(pcounter) atomic_dec_and_test(pcounter)
00089 #define xnarch_atomic_set_mask(pflags,mask) atomic_set_mask(mask,pflags)
00090 #define xnarch_atomic_clear_mask(pflags,mask) atomic_clear_mask(mask,pflags)
00091
00092 #define xnarch_atomic_xchg(ptr,x) atomic_xchg(ptr,x)
00093
00094 #endif