posix/coil/atomic.h
Go to the documentation of this file.
1 // -*- C++ -*-
19 #ifndef COIL_ATOMIC_H
20 
21 #ifdef COIL_HAS_ATOMIC_OP
22 
23 #include <bits/atomicity.h>
24 
25 #define COIL_USES_ATOMIC_OP
26 #define atomic_add(x, y) __gnu_cxx::__atomic_add(x, y)
27 #define atomic_incr(x) __gnu_cxx::__atomic_add(x, 1)
28 #define atomic_decr(x) __gnu_cxx::__atomic_add(x, -1)
29 #define atomic_exchange_add(x, y) __gnu_cxx::__exchange_and_add(x, y)
30 #else
31 
32 #include <coil/Mutex.h>
33 #include <coil/Guard.h>
34 #define COIL_USES_ATOMIC_OP coil::Mutex __mutex;
35 
36 #define atomic_add(x, y) \
37  { \
38  coil::Guard<coil::Mutex> guard(__mutex); \
39  *x = *x + y; \
40  }
41 
42 #define atomic_incr(x) \
43  { \
44  coil::Guard<coil::Mutex> guard(__mutex); \
45  ++(*x); \
46  }
47 
48 #define atomic_decr(x) \
49  { \
50  coil::Guard<coil::Mutex> guard(__mutex); \
51  --(*x); \
52  }
53 
54 int exchange_add(int* x, int y, coil::Mutex* mutex)
55 {
56  coil::Guard<coil::Mutex> guard(*mutex);
57  int tmp(*x);
58  *x = *x + y;
59  return tmp;
60 }
61 
62 #define atomic_exchange_add(x, y) \
63  exchange_add(x, y, &__mutex)
64 
65 #endif // COIL_HAS_ATOMIC_ADD
66 #endif // COIL_ATOMIC_H
Mutex class.
int exchange_add(int *x, int y, coil::Mutex *mutex)


openrtm_aist
Author(s): Noriaki Ando
autogenerated on Mon Jun 10 2019 14:07:50