00001 /* +---------------------------------------------------------------------------+ 00002 | The Mobile Robot Programming Toolkit (MRPT) C++ library | 00003 | | 00004 | http://www.mrpt.org/ | 00005 | | 00006 | Copyright (C) 2005-2011 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 #include <mrpt/base/link_pragmas.h> // DLL import/export definitions 00034 00035 namespace mrpt 00036 { 00037 namespace synch 00038 { 00039 00040 /** This class acts exactly as an int (or long) variable, but with atomic increment and decrement operators. 00041 * This is a useful component of thread-safe smart pointers. 00042 * \note Based on code from the Boost library. 00043 * \ingroup synch_grp 00044 */ 00045 class BASE_IMPEXP CAtomicCounter 00046 { 00047 public: 00048 #ifdef MRPT_OS_WINDOWS 00049 typedef long atomic_num_t; 00050 #else 00051 typedef int atomic_num_t; 00052 #endif 00053 00054 explicit CAtomicCounter( long v ): m_value( static_cast<atomic_num_t>(v) ) 00055 { } 00056 00057 void operator++(); //!< Atomic increment of value. 00058 atomic_num_t operator--(); //!< Atomic decrement of value and return new value. 00059 operator atomic_num_t() const; //!< Get current value 00060 00061 private: 00062 mutable atomic_num_t m_value; 00063 00064 CAtomicCounter( CAtomicCounter const & ); //!< Forbidden method 00065 CAtomicCounter & operator=( CAtomicCounter const & ); //!< Forbidden method 00066 }; // end of CAtomicCounter 00067 00068 00069 } // End of namespace 00070 } // End of namespace 00071 00072 #endif
| Page generated by Doxygen 1.7.5 for MRPT 0.9.5 SVN: at Thu Oct 13 21:25:36 UTC 2011 |