base/include/asm-i386/rtai_atomic.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
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
00028
00029
#include <asm/system.h>
00030
00031
typedef struct {
volatile unsigned long val; } rtai_atomic_t;
00032
00033
00034
#define atomic_xchg(ptr, v) \
00035
((__typeof__(*(ptr)))xchg(&(((rtai_atomic_t *)ptr)->val),v))
00036
00037
00038
#define atomic_cmpxchg(ptr, o, n) \
00039
((__typeof__(*(ptr)))cmpxchg(&(((rtai_atomic_t *)ptr)->val), o, n))
00040
00041
#else
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
00050
00051
#include <asm/atomic.h>
00052
#undef atomic_cmpxchg
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
00082
#undef ADDR
00083
00084
#endif
00085
00086
#endif
Generated on Thu Nov 20 11:49:48 2008 for RTAI API by
1.3.8