-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHandle.h
57 lines (46 loc) · 835 Bytes
/
Handle.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/*
* Copyright 2010-2014 Fabric Software Inc. All rights reserved.
*/
#ifndef __handle_h__
#define __handle_h__
#ifndef _WIN32
# include <stdlib.h>
#endif
template <class T>
struct Handle
{
private:
T * m_data;
bool m_owned;
// Fabric::EDK::AtomicUInt32 m_refCount;
uint32_t m_refCount;
public:
Handle(T * data, bool owned = false)
{
Fabric::EDK::AtomicUInt32SetValue( 1, &m_refCount );
m_data = data;
m_owned = owned;
}
void retain()
{
Fabric::EDK::AtomicUInt32Increment( &m_refCount );
}
void release()
{
if ( Fabric::EDK::AtomicUInt32DecrementAndGetValue( &m_refCount ) == 0 )
{
if(m_data != NULL && m_owned)
delete(m_data);
delete this;
}
}
T * data()
{
return m_data;
}
const T * data() const
{
return m_data;
}
};
#endif