win32/coil/atomic.h
Go to the documentation of this file.
1 // -*- C++ -*-
19 #ifndef COIL_ATOMIC_H
20 
21 #ifdef COIL_HAS_ATOMIC_ADD
22 #include <windows.h>
23 #define atomic_add(x, y) ::InterlockedExchangeAdd(x, y)
24 #define atomic_incr(x) ::InterlockedIncrement(x)
25 #define atomic_decr(x) ::InterlockedDecrement(x)
26 #define atomic_exchange_add(x, y) ::InterlockedExchangeAdd(x, y)
27 #else
28 
29 #include <coil/Mutex.h>
30 #include <coil/Guard.h>
31 
32 #define atomic_add(x, y) \
33  { \
34  coil::Guard<coil::Mutex> guard(__mutex); \
35  x = x + y; \
36  }
37 
38 #define atomic_incr(x) \
39  { \
40  coil::Guard<coil::Mutex> guard(__mutex); \
41  ++x; \
42  }
43 
44 #define atomic_decr(x) \
45  { \
46  coil::Guard<coil::Mutex> guard(__mutex); \
47  --x; \
48  }
49 
50 int exchange_add(int* x, int y, coil::Mutex* mutex)
51 {
52  coil::Guard<coil::Mutex> guard(*mutex);
53  int tmp(*x);
54  *x = *x + y;
55  return tmp;
56 }
57 
58 #define atomic_exchange_add(x, y) \
59  exchange_add(x, y, &__mutex)
60 
61 #endif // COIL_HAS_ATOMIC_ADD
62 #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 Feb 28 2022 23:00:42