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 namespace mrpt
17 {
18 namespace synch
19 {
20 
21 /** This class acts exactly as an int (or long) variable, but with atomic increment and decrement operators.
22  * This is a useful component of thread-safe smart pointers.
23  * \note Based on code from the Boost library.
24  * \ingroup synch_grp
25  */
27 {
28 public:
29 #ifdef MRPT_OS_WINDOWS
30  typedef long atomic_num_t;
31 #else
32  typedef int atomic_num_t;
33 #endif
34 
35  explicit CAtomicCounter( long v ): m_value( static_cast<atomic_num_t>(v) )
36  { }
37 
38  void operator++(); //!< Atomic increment of value.
39  atomic_num_t operator--(); //!< Atomic decrement of value and return new value.
40  operator atomic_num_t() const; //!< Get current value
41 
42 private:
43  mutable atomic_num_t m_value;
44 
45  CAtomicCounter( CAtomicCounter const & ); //!< Forbidden method
46  CAtomicCounter & operator=( CAtomicCounter const & ); //!< Forbidden method
47 }; // end of CAtomicCounter
48 
49 
50 } // End of namespace
51 } // End of namespace
52 
53 #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:26



Page generated by Doxygen 1.8.13 for MRPT 1.4.0 SVN: at Sat Sep 2 18:44:07 UTC 2017