Main MRPT website > C++ reference for MRPT 1.5.6
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-2017, 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 
16 #if defined( __clang__ ) && defined( MRPT_OS_APPLE )
17  //no include
18 #elif defined( __GNUC__ )
19 #if ( __GNUC__ * 100 + __GNUC_MINOR__ >= 402 )
20 # include <ext/atomicity.h>
21 #else
22 # include <bits/atomicity.h>
23 #endif
24 #endif
25 
26 
27 namespace mrpt
28 {
29 namespace synch
30 {
31 
32 /** This class acts exactly as an int (or long) variable, but with atomic increment and decrement operators.
33  * This is a useful component of thread-safe smart pointers.
34  * \note Based on code from the Boost library.
35  * \ingroup synch_grp
36  */
38 {
39 public:
40 #if defined( __GNUC__ ) && !defined( MRPT_OS_APPLE )
41  typedef _Atomic_word atomic_num_t;
42 #elif defined(_WIN32) // mostly for MSVC in Windows
43  typedef long atomic_num_t;
44 #else
45  typedef int atomic_num_t;
46 #endif
47 
48  explicit CAtomicCounter( long v ): m_value( static_cast<atomic_num_t>(v) )
49  { }
50 
51  void operator++(); //!< Atomic increment of value.
52  atomic_num_t operator--(); //!< Atomic decrement of value and return new value.
53  operator atomic_num_t() const; //!< Get current value
54 
55 private:
57 
58  CAtomicCounter( CAtomicCounter const & ); //!< Forbidden method
59  CAtomicCounter & operator=( CAtomicCounter const & ); //!< Forbidden method
60 }; // end of CAtomicCounter
61 
62 
63 } // End of namespace
64 } // End of namespace
65 
66 #endif
iterator operator++(int)
A thread-safe (ts) container which minimally emulates a std::map<>&#39;s [] and find() methods but which ...
Definition: ts_hash_map.h:97
const GLdouble * v
Definition: glext.h:3603
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
This class acts exactly as an int (or long) variable, but with atomic increment and decrement operato...
Definition: atomic_incr.h:37



Page generated by Doxygen 1.8.14 for MRPT 1.5.6 Git: 4c65e8431 Tue Apr 24 08:18:17 2018 +0200 at lun oct 28 01:35:26 CET 2019