atomic.h

00001 /*
00002  * Copyright (C) 2003 Philippe Gerum <rpm@xenomai.org>.
00003  *
00004  * RTAI/fusion is free software; you can redistribute it and/or modify
00005  * it under the terms of the GNU General Public License as published
00006  * by the Free Software Foundation; either version 2 of the License,
00007  * or (at your option) any later version.
00008  *
00009  * RTAI/fusion is distributed in the hope that it will be useful, but
00010  * WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012  * General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with RTAI/fusion; if not, write to the Free Software
00016  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
00017  * 02111-1307, USA.
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 /* !__KERNEL__ */
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 /* !likely */
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 /* Depollute the namespace a bit. */
00076 #undef ADDR
00077 
00078 #endif /* __KERNEL__ */
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 /* !_RTAI_ASM_I386_ATOMIC_H */

Generated on Sat Sep 3 12:32:47 2005 for RTAI Fusion API by  doxygen 1.4.2