Main MRPT website > C++ reference for MRPT 1.9.9
xsatomicint.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-2018, 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 XSATOMICINT_H
10 #define XSATOMICINT_H
11 
12 #include "xstypesconfig.h"
13 
14 #ifdef XSENS_64BIT
15 typedef long long XsAtomicIntValue;
16 #else
17 typedef long XsAtomicIntValue;
18 #endif
19 struct XsAtomicInt;
20 #ifndef __cplusplus
21 #define XSATOMICINT_INITIALIZER \
22  { \
23  0 \
24  }
25 #endif
26 
27 #ifdef _MSC_VER
28 #include <windows.h>
29 #ifdef XSENS_64BIT
30 #define atomicIncrement(a) InterlockedIncrement64(&a)
31 #define atomicDecrement(a) InterlockedDecrement64(&a)
32 #else
33 #define atomicIncrement(a) InterlockedIncrement(&a)
34 #define atomicDecrement(a) InterlockedDecrement(&a)
35 #endif
36 #else
37 #ifdef XSENS_64BIT
38 #define atomicIncrement(a) __sync_add_and_fetch(&a, 1)
39 #define atomicDecrement(a) __sync_sub_and_fetch(&a, 1)
40 #else
41 #define atomicIncrement(a) (++a)
42 #define atomicDecrement(a) (--a)
43 #endif
44 #endif
45 
46 /*! \relates XsAtomicInt \brief Increase the value by one unit (prefix
47  * notation). */
48 #define XsAtomicInt_preIncrement(a) \
49  ((XsAtomicIntValue)atomicIncrement((a)->m_value))
50 
51 /*! \relates XsAtomicInt \brief Decrease the value by one unit (prefix
52  * notation). */
53 #define XsAtomicInt_preDecrement(a) \
54  ((XsAtomicIntValue)atomicDecrement((a)->m_value))
55 
56 /*! \relates XsAtomicInt \brief Increase the value by one unit (postfix
57  * notation). */
58 #define XsAtomicInt_postIncrement(a) \
59  ((XsAtomicIntValue)atomicIncrement((a)->m_value) - 1)
60 
61 /*! \relates XsAtomicInt \brief Decrease the value by one unit (postfix
62  * notation). */
63 #define XsAtomicInt_postDecrement(a) \
64  ((XsAtomicIntValue)atomicDecrement((a)->m_value) + 1)
65 
66 /*! \class XsAtomicInt
67  \brief Wrapper class for easy use of XsAtomicIntValue values
68 */
70 {
71  /** The actual value */
73 
74 #ifdef __cplusplus
75  /*! \brief Initialize the value. */
77  /*! \brief Set the value to the given \a val. */
78  inline void setValue(XsAtomicIntValue val) { m_value = val; }
79  /*! \brief Get the current value. */
80  inline XsAtomicIntValue value() const { return (XsAtomicIntValue)m_value; }
81  /*! \brief Increase the value by one unit (prefix). */
83  {
84  return XsAtomicInt_preIncrement(this);
85  }
86 
87  /*! \brief Decrease the value by one unit (prefix). */
88  inline XsAtomicIntValue operator--()
89  {
90  return XsAtomicInt_preDecrement(this);
91  }
92 
93  /*! \brief Increase the value by one unit (postfix). */
94  inline XsAtomicIntValue operator++(int)
95  {
96  return XsAtomicInt_postIncrement(this);
97  }
98 
99  /*! \brief Decrease the value by one unit (postfix). */
100  inline XsAtomicIntValue operator--(int)
101  {
102  return XsAtomicInt_postDecrement(this);
103  }
104 
105 #endif // __cplusplus
106 };
107 
108 typedef struct XsAtomicInt XsAtomicInt;
109 
110 #endif // file guard
XsAtomicInt::XsAtomicInt_postIncrement
#define XsAtomicInt_postIncrement(a)
Increase the value by one unit (postfix notation).
Definition: xsatomicint.h:58
XsAtomicInt
struct XsAtomicInt XsAtomicInt
Definition: xsatomicint.h:108
XsAtomicInt::m_value
volatile XsAtomicIntValue m_value
The actual value.
Definition: xsatomicint.h:72
val
int val
Definition: mrpt_jpeglib.h:955
XsAtomicInt::XsAtomicInt_preDecrement
#define XsAtomicInt_preDecrement(a)
Decrease the value by one unit (prefix notation).
Definition: xsatomicint.h:53
XsAtomicIntValue
long XsAtomicIntValue
Definition: xsatomicint.h:17
XsAtomicInt::XsAtomicInt_postDecrement
#define XsAtomicInt_postDecrement(a)
Decrease the value by one unit (postfix notation).
Definition: xsatomicint.h:63
mrpt::containers::operator++
iterator operator++(int)
A thread-safe (ts) container which minimally emulates a std::map<>'s [] and find() methods but which ...
Definition: ts_hash_map.h:163
xstypesconfig.h
value
GLsizei const GLfloat * value
Definition: glext.h:4117
XsAtomicInt::XsAtomicInt_preIncrement
#define XsAtomicInt_preIncrement(a)
Increase the value by one unit (prefix notation).
Definition: xsatomicint.h:48
XsAtomicInt
Wrapper class for easy use of XsAtomicIntValue values.
Definition: xsatomicint.h:69



Page generated by Doxygen 1.8.17 for MRPT 1.9.9 Git: ad3a9d8ae Tue May 1 23:10:22 2018 -0700 at miƩ 12 jul 2023 10:03:34 CEST