00001 /* +---------------------------------------------------------------------------+ 00002 | The Mobile Robot Programming Toolkit (MRPT) C++ library | 00003 | | 00004 | http://mrpt.sourceforge.net/ | 00005 | | 00006 | Copyright (C) 2005-2009 University of Malaga | 00007 | | 00008 | This software was written by the Machine Perception and Intelligent | 00009 | Robotics Lab, University of Malaga (Spain). | 00010 | Contact: Jose-Luis Blanco <jlblanco@ctima.uma.es> | 00011 | | 00012 | This file is part of the MRPT project. | 00013 | | 00014 | MRPT is free software: you can redistribute it and/or modify | 00015 | it under the terms of the GNU General Public License as published by | 00016 | the Free Software Foundation, either version 3 of the License, or | 00017 | (at your option) any later version. | 00018 | | 00019 | MRPT is distributed in the hope that it will be useful, | 00020 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 00021 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 00022 | GNU General Public License for more details. | 00023 | | 00024 | You should have received a copy of the GNU General Public License | 00025 | along with MRPT. If not, see <http://www.gnu.org/licenses/>. | 00026 | | 00027 +---------------------------------------------------------------------------+ */ 00028 #ifndef mrpt_synch_atomicincr_H 00029 #define mrpt_synch_atomicincr_H 00030 00031 // This file CANNOT include "utils_defs.h" to avoid a double include: 00032 #include <mrpt/config.h> 00033 #define _IAMINUTILSDEFS_H 00034 #include <mrpt/utils/utils_impexp.h> // DLL import/export definitions 00035 #undef _IAMINUTILSDEFS_H 00036 00037 namespace mrpt 00038 { 00039 namespace synch 00040 { 00041 00042 /** This class acts exactly as an int (or long) variable, but with atomic increment and decrement operators. 00043 * This is a useful component of thread-safe smart pointers. 00044 * \note Based on code from the Boost library. 00045 */ 00046 class MRPTDLLIMPEXP CAtomicCounter 00047 { 00048 public: 00049 #ifdef MRPT_OS_WINDOWS 00050 typedef long atomic_num_t; 00051 #else 00052 typedef int atomic_num_t; 00053 #endif 00054 00055 explicit CAtomicCounter( long v ): m_value( static_cast<atomic_num_t>(v) ) 00056 { } 00057 00058 void operator++(); //!< Atomic increment of value. 00059 atomic_num_t operator--(); //!< Atomic decrement of value and return new value. 00060 operator atomic_num_t() const; //!< Get current value 00061 00062 private: 00063 mutable atomic_num_t m_value; 00064 00065 CAtomicCounter( CAtomicCounter const & ); //!< Forbidden method 00066 CAtomicCounter & operator=( CAtomicCounter const & ); //!< Forbidden method 00067 }; // end of CAtomicCounter 00068 00069 00070 } // End of namespace 00071 } // End of namespace 00072 00073 #endif
Page generated by Doxygen 1.5.9 for MRPT 0.7.1 SVN: at Mon Aug 17 22:32:05 EDT 2009 |