blob: 4d67f17f139340c718d4345ecb30853a9d05772c (
plain) (
blame)
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
|
#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();
}
|