Main MRPT website > C++ reference for MRPT 1.4.0
atomic_incr.h
Go to the documentation of this file.
1 /* +---------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | http://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2016, Individual contributors, see AUTHORS file |
6  | See: http://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See details in http://www.mrpt.org/License |
8  +---------------------------------------------------------------------------+ */
9 #ifndef mrpt_synch_atomicincr_H
10 #define mrpt_synch_atomicincr_H
11 
12 #include <mrpt/config.h>
14 #include <mrpt/base/link_pragmas.h> // DLL import/export definitions
15 
16 #if defined( __GNUC__ )
17 # include <ext/atomicity.h>
18 #endif
19 
20 namespace mrpt
21 {
22 namespace synch
23 {
24 
25 /** This class acts exactly as an int (or long) variable, but with atomic increment and decrement operators.
26  * This is a useful component of thread-safe smart pointers.
27  * \note Based on code from the Boost library.
28  * \ingroup synch_grp
29  */
31 {
32 public:
33 #if defined( __GNUC__ )
34  typedef _Atomic_word atomic_num_t;
35 #else // mostly for MSVC in Windows
36  typedef long atomic_num_t;
37 #endif
38 
39  explicit CAtomicCounter( long v ): m_value( static_cast<atomic_num_t>(v) )
40  { }
41 
42  void operator++(); //!< Atomic increment of value.
43  atomic_num_t operator--(); //!< Atomic decrement of value and return new value.
44  operator atomic_num_t() const; //!< Get current value
45 
46 private:
47  mutable atomic_num_t m_value;
48 
49  CAtomicCounter( CAtomicCounter const & ); //!< Forbidden method
50  CAtomicCounter & operator=( CAtomicCounter const & ); //!< Forbidden method
51 }; // end of CAtomicCounter
52 
53 
54 } // End of namespace
55 } // End of namespace
56 
57 #endif
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
This class acts exactly as an int (or long) variable, but with atomic increment and decrement operato...
Definition: atomic_incr.h:30



Page generated by Doxygen 1.8.11 for MRPT 1.4.0 SVN: at Mon Aug 15 11:50:21 UTC 2016