diff options
author | Jef <jef@targetspot.com> | 2024-09-24 08:54:57 -0400 |
---|---|---|
committer | Jef <jef@targetspot.com> | 2024-09-24 08:54:57 -0400 |
commit | 20d28e80a5c861a9d5f449ea911ab75b4f37ad0d (patch) | |
tree | 12f17f78986871dd2cfb0a56e5e93b545c1ae0d0 /Src/Winamp/AppRefCount.cpp | |
parent | 537bcbc86291b32fc04ae4133ce4d7cac8ebe9a7 (diff) | |
download | winamp-20d28e80a5c861a9d5f449ea911ab75b4f37ad0d.tar.gz |
Initial community commit
Diffstat (limited to 'Src/Winamp/AppRefCount.cpp')
-rw-r--r-- | Src/Winamp/AppRefCount.cpp | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/Src/Winamp/AppRefCount.cpp b/Src/Winamp/AppRefCount.cpp new file mode 100644 index 00000000..4d67f17f --- /dev/null +++ b/Src/Winamp/AppRefCount.cpp @@ -0,0 +1,52 @@ +#include "AppRefCount.h" + +AppRefCount appRefCount; +AppRefCount::AppRefCount() +{ + refCount = 1; + m_dwThread = 0; +} + +STDMETHODIMP AppRefCount::QueryInterface(REFIID riid, PVOID *ppvObject) +{ + if (!ppvObject) + return E_POINTER; + else if (IsEqualIID(riid, IID_IUnknown)) + *ppvObject = this; + else + { + *ppvObject = NULL; + return E_NOINTERFACE; + } + + AddRef(); + return S_OK; +} + +ULONG AppRefCount::AddRef(void) +{ + return InterlockedIncrement(&refCount); +} + +ULONG AppRefCount::Release(void) +{ + LONG lRef = InterlockedDecrement(&refCount); + if (lRef == 0) PostThreadMessage(m_dwThread, WM_NULL, 0, 0); + return lRef; +} + +int AppRefCount_CanQuit() +{ + return appRefCount.refCount == 0; +} + +void *InitAppRefCounterObject(DWORD threadId) +{ + appRefCount.m_dwThread = threadId; + return (IUnknown *)&appRefCount; +} + +void AppRefCount_Release() +{ + appRefCount.Release(); +}
\ No newline at end of file |