Initial community commit
This commit is contained in:
parent
537bcbc862
commit
fc06254474
16440 changed files with 4239995 additions and 2 deletions
21
Src/nu/refcount.h
Normal file
21
Src/nu/refcount.h
Normal file
|
@ -0,0 +1,21 @@
|
|||
#pragma once
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <windows.h>
|
||||
template <class ifc_t>
|
||||
class Countable : public ifc_t
|
||||
{
|
||||
public:
|
||||
Countable()
|
||||
{
|
||||
ref_count=1;
|
||||
}
|
||||
|
||||
// this needs to be done like this otherwise the destructor doesn't get called properly (we don't want virtual destructor for various reasons)
|
||||
#define REFERENCE_COUNT_IMPLEMENTATION size_t AddRef() { return InterlockedIncrement((LONG*)&ref_count); }\
|
||||
size_t Release() { if (!ref_count) return ref_count; LONG r = InterlockedDecrement((LONG*)&ref_count); if (!r) delete(this); return r; }
|
||||
protected:
|
||||
size_t ref_count;
|
||||
};
|
||||
|
||||
#define REFERENCE_COUNTED CB(ADDREF, AddRef); CB(RELEASE, Release);
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue