Commit 873e5bfe authored by Robert Reif's avatar Robert Reif Committed by Alexandre Julliard

Use InterlockedIncrement/InterlockedDecrement for reference counting.

Fix bug in effect enumeration that crashed dxcapsviewer.
parent f0509667
......@@ -475,11 +475,11 @@ HRESULT WINAPI IDirectInputDevice2AImpl_SetEventNotification(
ULONG WINAPI IDirectInputDevice2AImpl_Release(LPDIRECTINPUTDEVICE8A iface)
{
IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface;
This->ref--;
if (This->ref)
return This->ref;
ULONG ref;
ref = InterlockedDecrement(&(This->ref));
if (ref == 0)
HeapFree(GetProcessHeap(),0,This);
return DI_OK;
return ref;
}
HRESULT WINAPI IDirectInputDevice2AImpl_QueryInterface(
......@@ -548,7 +548,7 @@ ULONG WINAPI IDirectInputDevice2AImpl_AddRef(
LPDIRECTINPUTDEVICE8A iface)
{
IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface;
return ++This->ref;
return InterlockedIncrement(&(This->ref));
}
HRESULT WINAPI IDirectInputDevice2AImpl_EnumObjects(
......@@ -688,8 +688,6 @@ HRESULT WINAPI IDirectInputDevice2AImpl_EnumEffects(
FIXME("(this=%p,%p,%p,0x%08lx): stub!\n",
iface, lpCallback, lpvRef, dwFlags);
if (lpCallback)
lpCallback(NULL, lpvRef);
return DI_OK;
}
......@@ -702,8 +700,6 @@ HRESULT WINAPI IDirectInputDevice2WImpl_EnumEffects(
FIXME("(this=%p,%p,%p,0x%08lx): stub!\n",
iface, lpCallback, lpvRef, dwFlags);
if (lpCallback)
lpCallback(NULL, lpvRef);
return DI_OK;
}
......
......@@ -291,17 +291,17 @@ static HRESULT WINAPI IDirectInputWImpl_EnumDevices(
static ULONG WINAPI IDirectInputAImpl_AddRef(LPDIRECTINPUT7A iface)
{
IDirectInputImpl *This = (IDirectInputImpl *)iface;
return ++(This->ref);
return InterlockedIncrement((&This->ref));
}
static ULONG WINAPI IDirectInputAImpl_Release(LPDIRECTINPUT7A iface)
{
IDirectInputImpl *This = (IDirectInputImpl *)iface;
if (!(--This->ref)) {
ULONG ref;
ref = InterlockedDecrement(&(This->ref));
if (ref == 0)
HeapFree(GetProcessHeap(),0,This);
return 0;
}
return This->ref;
return ref;
}
static HRESULT WINAPI IDirectInputAImpl_QueryInterface(LPDIRECTINPUT7A iface, REFIID riid, LPVOID *ppobj) {
......@@ -640,13 +640,13 @@ static HRESULT WINAPI DICF_QueryInterface(LPCLASSFACTORY iface,REFIID riid,LPVOI
static ULONG WINAPI DICF_AddRef(LPCLASSFACTORY iface) {
IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
return ++(This->ref);
return InterlockedIncrement(&(This->ref));
}
static ULONG WINAPI DICF_Release(LPCLASSFACTORY iface) {
IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
/* static class, won't be freed */
return --(This->ref);
return InterlockedDecrement(&(This->ref));
}
static HRESULT WINAPI DICF_CreateInstance(
......
......@@ -662,10 +662,11 @@ DECL_GLOBAL_CONSTRUCTOR(joydev_register) { dinput_register_device(&joydev); }
static ULONG WINAPI JoystickAImpl_Release(LPDIRECTINPUTDEVICE8A iface)
{
JoystickImpl *This = (JoystickImpl *)iface;
ULONG ref;
This->ref--;
if (This->ref)
return This->ref;
ref = InterlockedDecrement((&This->ref));
if (ref)
return ref;
/* Free the device name */
if (This->name)
......
......@@ -332,10 +332,11 @@ DECL_GLOBAL_CONSTRUCTOR(joydev_register) { dinput_register_device(&joydev); }
static ULONG WINAPI JoystickAImpl_Release(LPDIRECTINPUTDEVICE8A iface)
{
JoystickImpl *This = (JoystickImpl *)iface;
ULONG ref;
This->ref--;
if (This->ref)
return This->ref;
ref = InterlockedDecrement(&(This->ref));
if (ref)
return ref;
/* Free the data queue */
if (This->data_queue != NULL)
......
......@@ -303,10 +303,11 @@ DECL_GLOBAL_CONSTRUCTOR(keyboarddev_register) { dinput_register_device(&keyboard
static ULONG WINAPI SysKeyboardAImpl_Release(LPDIRECTINPUTDEVICE8A iface)
{
SysKeyboardImpl *This = (SysKeyboardImpl *)iface;
ULONG ref;
This->ref--;
if (This->ref)
return This->ref;
ref = InterlockedDecrement(&(This->ref));
if (ref)
return ref;
EnterCriticalSection(&keyboard_crit);
if (!--keyboard_users) {
......
......@@ -326,10 +326,11 @@ DECL_GLOBAL_CONSTRUCTOR(mousedev_register) { dinput_register_device(&mousedev);
static ULONG WINAPI SysMouseAImpl_Release(LPDIRECTINPUTDEVICE8A iface)
{
SysMouseImpl *This = (SysMouseImpl *)iface;
ULONG ref;
This->ref--;
if (This->ref)
return This->ref;
ref = InterlockedDecrement(&(This->ref));
if (ref)
return ref;
/* Free the data queue */
if (This->data_queue != NULL)
......@@ -349,7 +350,7 @@ static ULONG WINAPI SysMouseAImpl_Release(LPDIRECTINPUTDEVICE8A iface)
}
HeapFree(GetProcessHeap(),0,This);
return DI_OK;
return 0;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment