Orocos Real-Time Toolkit  2.9.0
oro_arch.h
Go to the documentation of this file.
1 #ifndef __GCC_ORO_ARCH__
2 #define __GCC_ORO_ARCH__
3 
4 #include "../../rtt-config.h"
5 
10 typedef struct {
11  int volatile cnt;
12 } oro_atomic_t;
13 
14 #define ORO_ATOMIC_SETUP oro_atomic_set
15 #define ORO_ATOMIC_CLEANUP(a_int)
16 
17 #define oro_atomic_read(a_int) ((a_int)->cnt)
18 
19 #define oro_atomic_set(a_int,n) (((a_int)->cnt) = (n))
20 
24 static __inline__ void oro_atomic_add(oro_atomic_t *a_int, int n)
25 {
26  (void)__sync_add_and_fetch(&a_int->cnt, n);
27 }
28 
32 static __inline__ int oro_atomic_add_return(oro_atomic_t *a_int, int n)
33 {
34  return __sync_add_and_fetch(&a_int->cnt, n);
35 }
36 
40 static __inline__ void oro_atomic_sub(oro_atomic_t *a_int, int n)
41 {
42  (void)__sync_sub_and_fetch(&a_int->cnt, n);
43 }
44 
48 static __inline__ int oro_atomic_sub_return(oro_atomic_t *a_int, int n)
49 {
50  return __sync_sub_and_fetch(&a_int->cnt, n);
51 }
52 
56 static __inline__ int oro_atomic_sub_and_test(oro_atomic_t *a_int, int n)
57 {
58  return !(__sync_sub_and_fetch(&a_int->cnt, n));
59 }
60 
64 static __inline__ void oro_atomic_inc(oro_atomic_t *a_int)
65 {
66  (void)__sync_fetch_and_add(&a_int->cnt, 1);
67 }
68 
73 {
74  return __sync_fetch_and_add(&a_int->cnt, 1);
75 }
76 
80 static __inline__ void oro_atomic_dec(oro_atomic_t *a_int)
81 {
82  (void)__sync_fetch_and_sub(&a_int->cnt, 1);
83 }
84 
89 {
90  return __sync_fetch_and_sub(&a_int->cnt, 1);
91 }
92 
97 {
98  return !(__sync_sub_and_fetch(&a_int->cnt, 1));
99 }
100 
105 {
106  return !(__sync_add_and_fetch(&a_int->cnt, 1));
107 }
108 
112 #define oro_cmpxchg(ptr,o,n)\
113  ((__typeof__(*(ptr)))__sync_val_compare_and_swap((ptr),(o),(n)))
114 
115 
116 #endif // __GCC_ORO_ARCH__
int oro_atomic_inc_return(oro_atomic_t *a)
Increment a atomically and return the new value.
int oro_atomic_inc_and_test(oro_atomic_t *a)
Increment a atomically and test for zero.
int oro_atomic_sub_return(int n, oro_atomic_t *a, int n)
Subtract n from a and return the new value.
void oro_atomic_inc(oro_atomic_t *a)
Increment a atomically.
#define __inline__
Definition: oro_arch.h:52
volatile long oro_atomic_t
Definition: oro_arch.h:9
void oro_atomic_sub(int n, oro_atomic_t *a, int n)
Subtract n from a.
int volatile cnt
Definition: oro_arch.h:11
int oro_atomic_dec_and_test(oro_atomic_t *a)
Decrement a atomically and test for zero.
int oro_atomic_sub_and_test(oro_atomic_t *a, int n)
Subtract n from a and test for zero.
int oro_atomic_dec_return(oro_atomic_t *a)
Decrement a atomically and return the new value.
void oro_atomic_dec(oro_atomic_t *a)
Decrement a atomically.
Structure that contains an int for atomic operations.
Definition: oro_arch.h:10
int oro_atomic_add_return(oro_atomic_t *a, int n)
Add n to a and return the new value.
void oro_atomic_add(oro_atomic_t *a, int n)
Add n to a.