oro_gcc/oro_arch.h
Go to the documentation of this file.00001 #ifndef __GCC_ORO_ARCH__
00002 #define __GCC_ORO_ARCH__
00003
00004
00005
00006
00007
00008
00009
00010 typedef struct {
00011 int volatile cnt;
00012 } oro_atomic_t;
00013
00014 #define ORO_ATOMIC_SETUP oro_atomic_set
00015 #define ORO_ATOMIC_CLEANUP(a_int)
00016
00017 #define oro_atomic_read(a_int) ((a_int)->cnt)
00018
00019 #define oro_atomic_set(a_int,n) (((a_int)->cnt) = (n))
00020
00021
00022
00023
00024 static __inline__ void oro_atomic_add(oro_atomic_t *a_int, int n)
00025 {
00026 (void)__sync_add_and_fetch(&a_int->cnt, n);
00027 }
00028
00029
00030
00031
00032 static __inline__ void oro_atomic_sub(oro_atomic_t *a_int, int n)
00033 {
00034 (void)__sync_sub_and_fetch(&a_int->cnt, n);
00035 }
00036
00037
00038
00039
00040 static __inline__ int oro_atomic_sub_and_test(oro_atomic_t *a_int, int n)
00041 {
00042 return !(__sync_sub_and_fetch(&a_int->cnt, n));
00043 }
00044
00045
00046
00047
00048 static __inline__ void oro_atomic_inc(oro_atomic_t *a_int)
00049 {
00050 (void)__sync_fetch_and_add(&a_int->cnt, 1);
00051 }
00052
00053
00054
00055
00056 static __inline__ void oro_atomic_dec(oro_atomic_t *a_int)
00057 {
00058 (void)__sync_fetch_and_sub(&a_int->cnt, 1);
00059 }
00060
00061
00062
00063
00064 static __inline__ int oro_atomic_dec_and_test(oro_atomic_t *a_int)
00065 {
00066 return !(__sync_sub_and_fetch(&a_int->cnt, 1));
00067 }
00068
00069
00070
00071
00072 static __inline__ int oro_atomic_inc_and_test(oro_atomic_t *a_int)
00073 {
00074 return !(__sync_add_and_fetch(&a_int->cnt, 1));
00075 }
00076
00077
00078
00079
00080 #define oro_cmpxchg(ptr,o,n)\
00081 ((__typeof__(*(ptr)))__sync_val_compare_and_swap((ptr),(o),(n)))
00082
00083
00084 #endif // __GCC_ORO_ARCH__