Main MRPT website > C++ reference
MRPT logo

atomic_incr.h

Go to the documentation of this file.
00001 /* +---------------------------------------------------------------------------+
00002    |          The Mobile Robot Programming Toolkit (MRPT) C++ library          |
00003    |                                                                           |
00004    |                   http://mrpt.sourceforge.net/                            |
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   */
00044 class BASE_IMPEXP CAtomicCounter
00045 {
00046 public:
00047 #ifdef MRPT_OS_WINDOWS
00048         typedef long atomic_num_t;
00049 #else
00050         typedef int atomic_num_t;
00051 #endif
00052 
00053         explicit CAtomicCounter( long v ): m_value( static_cast<atomic_num_t>(v) )
00054         { }
00055 
00056         void operator++();  //!< Atomic increment of value.
00057         atomic_num_t operator--();      //!< Atomic decrement of value and return new value.
00058         operator atomic_num_t() const; //!< Get current value
00059 
00060 private:
00061         mutable atomic_num_t m_value;
00062 
00063         CAtomicCounter( CAtomicCounter const & );       //!< Forbidden method
00064         CAtomicCounter & operator=( CAtomicCounter const & );   //!< Forbidden method
00065 }; // end of CAtomicCounter
00066 
00067 
00068 } // End of namespace
00069 } // End of namespace
00070 
00071 #endif



Page generated by Doxygen 1.7.3 for MRPT 0.9.4 SVN: at Sat Mar 26 06:40:17 UTC 2011