Main Page
Namespaces
Classes
Files
File List
File Members
sensor_api
source
LibMultiSense
details
utility
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
51
class
ReferenceCount
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
66
ReferenceCount
()
67
:
m_countP
(new int32_t(1)) {};
68
69
ReferenceCount
(
const
ReferenceCount
& source)
70
:
m_countP
(source.
m_countP
) {
71
share
();
72
}
73
74
~ReferenceCount
() {
75
release
();
76
}
77
78
ReferenceCount
&
operator=
(
const
ReferenceCount
& source) {
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 */
crl::multisense::details::utility::ReferenceCount::m_countP
volatile int32_t * m_countP
Definition:
ReferenceCount.hh:89
crl::multisense::details::utility::ReferenceCount::reset
void reset()
Definition:
ReferenceCount.hh:61
crl::multisense::details::utility::ReferenceCount
Definition:
ReferenceCount.hh:51
crl::multisense::details::utility::ReferenceCount::~ReferenceCount
~ReferenceCount()
Definition:
ReferenceCount.hh:74
crl::multisense::details::utility::ReferenceCount::ReferenceCount
ReferenceCount(const ReferenceCount &source)
Definition:
ReferenceCount.hh:69
crl::multisense::details::utility::ReferenceCount::isShared
bool isShared() const
Definition:
ReferenceCount.hh:55
crl::multisense::details::utility::ReferenceCount::share
void share()
Definition:
ReferenceCount.hh:91
crl
Definition:
channel.cc:56
crl::multisense::details::utility::ReferenceCount::release
void release()
Definition:
ReferenceCount.hh:100
crl::multisense::details::utility::ReferenceCount::operator=
ReferenceCount & operator=(const ReferenceCount &source)
Definition:
ReferenceCount.hh:78
crl::multisense::details::utility::ReferenceCount::ReferenceCount
ReferenceCount()
Definition:
ReferenceCount.hh:66
multisense_lib
Author(s):
autogenerated on Sat Apr 6 2019 02:16:46