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


openrtm_aist
Author(s): Noriaki Ando
autogenerated on Thu Aug 27 2015 14:16:37