blob: d53239adc12efa302c2996447f356b34287c224c (
plain)
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
|
#ifndef THREAD_SHARED_OBJECT_H
#define THREAD_SHARED_OBJECT_H
#include "Runtime/Utilities/NonCopyable.h"
#include "Runtime/Threads/AtomicOps.h"
class ThreadSharedObject : public NonCopyable
{
public:
void AddRef() const { AtomicIncrement(&m_RefCount); }
void Release() const { if (AtomicDecrement(&m_RefCount) == 0) delete this; }
void Release(MemLabelId label) const
{
if (AtomicDecrement(&m_RefCount) == 0)
{
this->~ThreadSharedObject();
UNITY_FREE(label,const_cast<ThreadSharedObject*>(this));
}
}
int GetRefCount() const { return m_RefCount; }
protected:
ThreadSharedObject(int refs = 1) : m_RefCount(refs) {}
virtual ~ThreadSharedObject() {}
private:
volatile mutable int m_RefCount;
};
#endif
|