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


openrtm_aist
Author(s): Noriaki Ando
autogenerated on Sat Jun 8 2019 18:49:03