atomic.h

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  * As a special exception, the RTAI project gives permission for
00019  * additional uses of the text contained in its release of Xenomai.
00020  *
00021  * The exception is that, if you link the Xenomai libraries with other
00022  * files to produce an executable, this does not by itself cause the
00023  * resulting executable to be covered by the GNU General Public License.
00024  * Your use of that executable is in no way restricted on account of
00025  * linking the Xenomai libraries code into it.
00026  *
00027  * This exception does not however invalidate any other reasons why
00028  * the executable file might be covered by the GNU General Public
00029  * License.
00030  *
00031  * This exception applies only to the code released by the
00032  * RTAI project under the name Xenomai.  If you copy code from other
00033  * RTAI project releases into a copy of Xenomai, as the General Public
00034  * License permits, the exception does not apply to the code that you
00035  * add in this way.  To avoid misleading anyone as to the status of
00036  * such modified files, you must delete this exception notice from
00037  * them.
00038  *
00039  * If you write modifications of your own for Xenomai, it is your
00040  * choice whether to permit this exception to apply to your
00041  * modifications. If you do not wish that, delete this exception
00042  * notice.
00043  */
00044 
00045 #ifndef _RTAI_ASM_I386_ATOMIC_H
00046 #define _RTAI_ASM_I386_ATOMIC_H
00047 
00048 #include <linux/bitops.h>
00049 #include <asm/atomic.h>
00050 
00051 #ifdef __KERNEL__
00052 
00053 #include <asm/system.h>
00054 
00055 #define atomic_xchg(ptr,v)       xchg(ptr,v)
00056 #define atomic_cmpxchg(ptr,o,n)  cmpxchg(ptr,o,n)
00057 #define xnarch_memory_barrier()  smp_mb()
00058 
00059 #else /* !__KERNEL__ */
00060 
00061 struct __rtai_xchg_dummy { unsigned long a[100]; };
00062 #define __rtai_xg(x) ((struct __rtai_xchg_dummy *)(x))
00063 
00064 static inline unsigned long atomic_xchg (volatile void *ptr,
00065                                          unsigned long x)
00066 {
00067     __asm__ __volatile__(LOCK_PREFIX "xchgl %0,%1"
00068                          :"=r" (x)
00069                          :"m" (*__rtai_xg(ptr)), "0" (x)
00070                          :"memory");
00071     return x;
00072 }
00073 
00074 static inline unsigned long atomic_cmpxchg (volatile void *ptr,
00075                                             unsigned long o,
00076                                             unsigned long n)
00077 {
00078     unsigned long prev;
00079 
00080     __asm__ __volatile__(LOCK_PREFIX "cmpxchgl %1,%2"
00081                          : "=a"(prev)
00082                          : "q"(n), "m" (*__rtai_xg(ptr)), "0" (o)
00083                          : "memory");
00084 
00085     return prev;
00086 }
00087 
00088 #define xnarch_memory_barrier()  __asm__ __volatile__("": : :"memory")
00089 
00090 /* Depollute the namespace a bit. */
00091 #undef ADDR
00092 
00093 #endif /* __KERNEL__ */
00094 
00095 typedef atomic_t atomic_counter_t;
00096 typedef unsigned long atomic_flags_t;
00097 
00098 #define xnarch_atomic_set(pcounter,i)          atomic_set(pcounter,i)
00099 #define xnarch_atomic_get(pcounter)            atomic_read(pcounter)
00100 #define xnarch_atomic_inc(pcounter)            atomic_inc(pcounter)
00101 #define xnarch_atomic_dec(pcounter)            atomic_dec(pcounter)
00102 #define xnarch_atomic_inc_and_test(pcounter)   atomic_inc_and_test(pcounter)
00103 #define xnarch_atomic_dec_and_test(pcounter)   atomic_dec_and_test(pcounter)
00104 #define xnarch_atomic_set_mask(pflags,mask)    atomic_set_mask(mask,pflags)
00105 #define xnarch_atomic_clear_mask(pflags,mask)  atomic_clear_mask(mask,pflags)
00106 
00107 #define xnarch_atomic_xchg(ptr,x) atomic_xchg(ptr,x)
00108 
00109 #endif /* !_RTAI_ASM_I386_ATOMIC_H */

Generated on Mon Dec 13 09:49:49 2004 for RTAI API by  doxygen 1.3.9.1