Main MRPT website > C++ reference for MRPT 1.5.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-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 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 { 0 }
22 #endif
23 
24 #ifdef _MSC_VER
25 #include <windows.h>
26  #ifdef XSENS_64BIT
27  #define atomicIncrement(a) InterlockedIncrement64(&a)
28  #define atomicDecrement(a) InterlockedDecrement64(&a)
29  #else
30  #define atomicIncrement(a) InterlockedIncrement(&a)
31  #define atomicDecrement(a) InterlockedDecrement(&a)
32  #endif
33 #else
34  #ifdef XSENS_64BIT
35  #define atomicIncrement(a) __sync_add_and_fetch(&a, 1)
36  #define atomicDecrement(a) __sync_sub_and_fetch(&a, 1)
37  #else
38  #define atomicIncrement(a) (++a)
39  #define atomicDecrement(a) (--a)
40  #endif
41 #endif
42 
43 /*! \relates XsAtomicInt \brief Increase the value by one unit (prefix notation). */
44 #define XsAtomicInt_preIncrement(a) ((XsAtomicIntValue) atomicIncrement((a)->m_value))
45 
46 /*! \relates XsAtomicInt \brief Decrease the value by one unit (prefix notation). */
47 #define XsAtomicInt_preDecrement(a) ((XsAtomicIntValue) atomicDecrement((a)->m_value))
48 
49 /*! \relates XsAtomicInt \brief Increase the value by one unit (postfix notation). */
50 #define XsAtomicInt_postIncrement(a) ((XsAtomicIntValue) atomicIncrement((a)->m_value) - 1)
51 
52 /*! \relates XsAtomicInt \brief Decrease the value by one unit (postfix notation). */
53 #define XsAtomicInt_postDecrement(a) ((XsAtomicIntValue) atomicDecrement((a)->m_value) + 1)
54 
55 /*! \class XsAtomicInt
56  \brief Wrapper class for easy use of XsAtomicIntValue values
57 */
58 struct XsAtomicInt {
59  volatile XsAtomicIntValue m_value; //!< The actual value
60 
61 #ifdef __cplusplus
62  /*! \brief Initialize the value. */
64  : m_value(val)
65  {}
66 
67  /*! \brief Set the value to the given \a val. */
68  inline void setValue(XsAtomicIntValue val)
69  {
70  m_value = val;
71  }
72 
73  /*! \brief Get the current value. */
74  inline XsAtomicIntValue value() const
75  {
76  return (XsAtomicIntValue) m_value;
77  }
78 
79  /*! \brief Increase the value by one unit (prefix). */
81  {
82  return XsAtomicInt_preIncrement(this);
83  }
84 
85  /*! \brief Decrease the value by one unit (prefix). */
86  inline XsAtomicIntValue operator--()
87  {
88  return XsAtomicInt_preDecrement(this);
89  }
90 
91  /*! \brief Increase the value by one unit (postfix). */
92  inline XsAtomicIntValue operator++(int)
93  {
94  return XsAtomicInt_postIncrement(this);
95  }
96 
97  /*! \brief Decrease the value by one unit (postfix). */
98  inline XsAtomicIntValue operator--(int)
99  {
100  return XsAtomicInt_postDecrement(this);
101  }
102 
103 #endif // __cplusplus
104 };
105 
106 typedef struct XsAtomicInt XsAtomicInt;
107 
108 #endif // file guard
Wrapper class for easy use of XsAtomicIntValue values.
Definition: xsatomicint.h:58
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
long XsAtomicIntValue
Definition: xsatomicint.h:17
volatile XsAtomicIntValue m_value
The actual value.
Definition: xsatomicint.h:59
#define XsAtomicInt_preDecrement(a)
Decrease the value by one unit (prefix notation).
Definition: xsatomicint.h:47
int val
Definition: mrpt_jpeglib.h:953
GLsizei const GLfloat * value
Definition: glext.h:3929
#define XsAtomicInt_postIncrement(a)
Increase the value by one unit (postfix notation).
Definition: xsatomicint.h:50
#define XsAtomicInt_preIncrement(a)
Increase the value by one unit (prefix notation).
Definition: xsatomicint.h:44
#define XsAtomicInt_postDecrement(a)
Decrease the value by one unit (postfix notation).
Definition: xsatomicint.h:53
struct XsAtomicInt XsAtomicInt
Definition: xsatomicint.h:106



Page generated by Doxygen 1.8.14 for MRPT 1.5.9 Git: 690a4699f Wed Apr 15 19:29:53 2020 +0200 at miƩ abr 15 19:30:12 CEST 2020