diff options
author | Jean-Francois Mauguit <jfmauguit@mac.com> | 2024-09-24 09:03:25 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-09-24 09:03:25 -0400 |
commit | bab614c421ed7ae329d26bf028c4a3b1d2450f5a (patch) | |
tree | 12f17f78986871dd2cfb0a56e5e93b545c1ae0d0 /Src/nu/refcount.h | |
parent | 4bde6044fddf053f31795b9eaccdd2a5a527d21f (diff) | |
parent | 20d28e80a5c861a9d5f449ea911ab75b4f37ad0d (diff) | |
download | winamp-bab614c421ed7ae329d26bf028c4a3b1d2450f5a.tar.gz |
Merge pull request #5 from WinampDesktop/community
Merge to main
Diffstat (limited to 'Src/nu/refcount.h')
-rw-r--r-- | Src/nu/refcount.h | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/Src/nu/refcount.h b/Src/nu/refcount.h new file mode 100644 index 00000000..9ab52f4e --- /dev/null +++ b/Src/nu/refcount.h @@ -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); + |