Main MRPT website > C++ reference
MRPT logo
atomic_incr.h
Go to the documentation of this file.
1 /* +---------------------------------------------------------------------------+
2  | The Mobile Robot Programming Toolkit (MRPT) C++ library |
3  | |
4  | http://www.mrpt.org/ |
5  | |
6  | Copyright (C) 2005-2012 University of Malaga |
7  | |
8  | This software was written by the Machine Perception and Intelligent |
9  | Robotics Lab, University of Malaga (Spain). |
10  | Contact: Jose-Luis Blanco <jlblanco@ctima.uma.es> |
11  | |
12  | This file is part of the MRPT project. |
13  | |
14  | MRPT is free software: you can redistribute it and/or modify |
15  | it under the terms of the GNU General Public License as published by |
16  | the Free Software Foundation, either version 3 of the License, or |
17  | (at your option) any later version. |
18  | |
19  | MRPT is distributed in the hope that it will be useful, |
20  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
21  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
22  | GNU General Public License for more details. |
23  | |
24  | You should have received a copy of the GNU General Public License |
25  | along with MRPT. If not, see <http://www.gnu.org/licenses/>. |
26  | |
27  +---------------------------------------------------------------------------+ */
28 #ifndef mrpt_synch_atomicincr_H
29 #define mrpt_synch_atomicincr_H
30 
31 // This file CANNOT include "utils_defs.h" to avoid a double include:
32 #include <mrpt/config.h>
33 #include <mrpt/base/link_pragmas.h> // DLL import/export definitions
34 
35 namespace mrpt
36 {
37 namespace synch
38 {
39 
40 /** This class acts exactly as an int (or long) variable, but with atomic increment and decrement operators.
41  * This is a useful component of thread-safe smart pointers.
42  * \note Based on code from the Boost library.
43  * \ingroup synch_grp
44  */
46 {
47 public:
48 #ifdef MRPT_OS_WINDOWS
49  typedef long atomic_num_t;
50 #else
51  typedef int atomic_num_t;
52 #endif
53 
54  explicit CAtomicCounter( long v ): m_value( static_cast<atomic_num_t>(v) )
55  { }
56 
57  void operator++(); //!< Atomic increment of value.
58  atomic_num_t operator--(); //!< Atomic decrement of value and return new value.
59  operator atomic_num_t() const; //!< Get current value
60 
61 private:
63 
64  CAtomicCounter( CAtomicCounter const & ); //!< Forbidden method
65  CAtomicCounter & operator=( CAtomicCounter const & ); //!< Forbidden method
66 }; // end of CAtomicCounter
67 
68 
69 } // End of namespace
70 } // End of namespace
71 
72 #endif



Page generated by Doxygen 1.8.3 for MRPT 0.9.6 SVN: at Fri Feb 15 22:05:02 EST 2013