atomic.h
Go to the documentation of this file.
00001 // -*- C++ -*-
00019 #ifndef COIL_ATOMIC_H
00020 
00021 #ifdef COIL_HAS_ATOMIC_ADD
00022 #include <windows.h>
00023 #define atomic_add(x, y) ::InterlockedExchangeAdd(x, y)
00024 #define atomic_incr(x)   ::InterlockedIncrement(x)
00025 #define atomic_decr(x)   ::InterlockedDecrement(x)
00026 #define atomic_exchange_add(x, y) ::InterlockedExchangeAdd(x, y)
00027 #else
00028 
00029 #include <coil/Mutex.h>
00030 #include <coil/Guard.h>
00031 
00032 #define atomic_add(x, y)                        \
00033   {                                             \
00034     coil::Guard<coil::Mutex> guard(__mutex);    \
00035     x = x + y;                                  \
00036   }
00037 
00038 #define atomic_incr(x)                          \
00039   {                                             \
00040     coil::Guard<coil::Mutex> guard(__mutex);    \
00041     ++x;                                        \
00042   }
00043 
00044 #define atomic_decr(x)                          \
00045   {                                             \
00046     coil::Guard<coil::Mutex> guard(__mutex);    \
00047     --x;                                        \
00048   }
00049 
00050 int exchange_add(int* x, int y, coil::Mutex* mutex)
00051 {
00052   coil::Guard<coil::Mutex> guard(*mutex);
00053   int tmp(*x);
00054   *x = *x + y;
00055   return tmp;
00056 }
00057 
00058 #define atomic_exchange_add(x, y)               \
00059   exchange_add(x, y, &__mutex)
00060 
00061 #endif // COIL_HAS_ATOMIC_ADD
00062 #endif // COIL_ATOMIC_H


openrtm_aist
Author(s): Noriaki Ando
autogenerated on Sun Mar 26 2017 03:37:14