ReferenceCount.hh
Go to the documentation of this file.
1 
41 #ifndef CRL_MULTISENSE_REFERENCECOUNT_HH
42 #define CRL_MULTISENSE_REFERENCECOUNT_HH
43 
44 #include <stdint.h>
45 
46 namespace crl {
47 namespace multisense {
48 namespace details {
49 namespace utility {
50 
52 {
53 public:
54 
55  bool isShared() const {
56  if (m_countP && (*m_countP) > 1)
57  return true;
58  return false;
59  }
60 
61  void reset() {
62  release();
63  m_countP = new int32_t(1);
64  }
65 
67  : m_countP(new int32_t(1)) {};
68 
70  : m_countP(source.m_countP) {
71  share();
72  }
73 
75  release();
76  }
77 
79  if (this != &source) {
80  release();
81  m_countP = source.m_countP;
82  share();
83  }
84  return *this;
85  }
86 
87 private:
88 
89  volatile int32_t *m_countP;
90 
91  void share() {
92  if (m_countP)
93 #if WIN32
94  InterlockedIncrement((LONG*)m_countP);
95 #else
96  __sync_fetch_and_add(m_countP, 1);
97 #endif
98  }
99 
100  void release() {
101  if (m_countP) {
102 #if WIN32
103  int32_t count = InterlockedDecrement((LONG*)m_countP);
104 #else
105  int32_t count = __sync_sub_and_fetch(m_countP, 1);
106 #endif
107  if (count <= 0)
108  delete m_countP;
109  m_countP = NULL;
110  }
111  }
112 };
113 
114 }}}} // namespaces
115 
116 #endif /* #ifndef CRL_MULTISENSE_REFERENCECOUNT_HH */
Definition: channel.cc:56
ReferenceCount & operator=(const ReferenceCount &source)


multisense_lib
Author(s):
autogenerated on Sat Apr 6 2019 02:16:46