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
16namespace mrpt
17{
18namespace 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{
28public:
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
42private:
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 class acts exactly as an int (or long) variable, but with atomic increment and decrement operato...
Definition atomic_incr.h:27
CAtomicCounter(CAtomicCounter const &)
Forbidden method.
CAtomicCounter & operator=(CAtomicCounter const &)
Forbidden method.
void operator++()
Atomic increment of value.
atomic_num_t operator--()
Atomic decrement of value and return new value.
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.



Page generated by Doxygen 1.9.7 for MRPT 1.4.0 SVN: at Tue Jun 13 13:56:43 UTC 2023