base/include/asm-i386/rtai_atomic.h

Go to the documentation of this file.
00001 /* 00002 * Copyright (C) 2003 Philippe Gerum <rpm@xenomai.org>. 00003 * 00004 * This program is free software; you can redistribute it and/or 00005 * modify it under the terms of the GNU General Public License as 00006 * published by the Free Software Foundation; either version 2 of the 00007 * License, or (at your option) any later version. 00008 * 00009 * This program is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 * GNU General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU General Public License 00015 * along with this program; if not, write to the Free Software 00016 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00017 */ 00018 00019 #ifndef _RTAI_ASM_I386_ATOMIC_H 00020 #define _RTAI_ASM_I386_ATOMIC_H 00021 00022 #include <linux/bitops.h> 00023 00024 #ifdef __KERNEL__ 00025 00026 #include <asm/atomic.h> 00027 #undef atomic_cmpxchg /* they might have decided to use one of our names */ 00028 00029 #include <asm/system.h> 00030 00031 typedef struct { volatile unsigned long val; } rtai_atomic_t; 00032 00033 /* #define atomic_xchg(ptr, v) xchg(ptr, v) */ /*previous define */ 00034 #define atomic_xchg(ptr, v) \ 00035 ((__typeof__(*(ptr)))xchg(&(((rtai_atomic_t *)ptr)->val),v)) 00036 00037 /* #define atomic_cmpxchg(ptr, o, n) cmpxchg(ptr, o, n) */ /*previous define */ 00038 #define atomic_cmpxchg(ptr, o, n) \ 00039 ((__typeof__(*(ptr)))cmpxchg(&(((rtai_atomic_t *)ptr)->val), o, n)) 00040 00041 #else /* !__KERNEL__ */ 00042 00043 #ifndef likely 00044 #if __GNUC__ == 2 && __GNUC_MINOR__ < 96 00045 #define __builtin_expect(x, expected_value) (x) 00046 #endif 00047 #define likely(x) __builtin_expect(!!(x), 1) 00048 #define unlikely(x) __builtin_expect(!!(x), 0) 00049 #endif /* !likely */ 00050 00051 #include <asm/atomic.h> 00052 #undef atomic_cmpxchg /* they might have decided to use one of our names */ 00053 00054 struct __rtai_xchg_dummy { unsigned long a[100]; }; 00055 #define __rtai_xg(x) ((struct __rtai_xchg_dummy *)(x)) 00056 00057 static inline unsigned long atomic_xchg (volatile void *ptr, 00058 unsigned long x) 00059 { 00060 __asm__ __volatile__(LOCK_PREFIX "xchgl %0,%1" 00061 :"=r" (x) 00062 :"m" (*__rtai_xg(ptr)), "0" (x) 00063 :"memory"); 00064 return x; 00065 } 00066 00067 static inline unsigned long atomic_cmpxchg (volatile void *ptr, 00068 unsigned long o, 00069 unsigned long n) 00070 { 00071 unsigned long prev; 00072 00073 __asm__ __volatile__(LOCK_PREFIX "cmpxchgl %1,%2" 00074 : "=a"(prev) 00075 : "q"(n), "m" (*__rtai_xg(ptr)), "0" (o) 00076 : "memory"); 00077 00078 return prev; 00079 } 00080 00081 /* Depollute the namespace a bit. */ 00082 #undef ADDR 00083 00084 #endif /* __KERNEL__ */ 00085 00086 #endif /* !_RTAI_ASM_I386_ATOMIC_H */

Generated on Thu Nov 20 11:49:48 2008 for RTAI API by doxygen 1.3.8