dinput reference count patch
Robert Reif
reif at earthlink.net
Fri Sep 17 06:51:12 CDT 2004
Use InterlockedIncrement/InterlockedDecrement for reference counting.
Fix bug in effect enumeration that crashed dxcapsviewer.
-------------- next part --------------
Index: dlls/dinput/device.c
===================================================================
RCS file: /home/wine/wine/dlls/dinput/device.c,v
retrieving revision 1.22
diff -u -r1.22 device.c
--- dlls/dinput/device.c 9 Sep 2004 20:17:08 -0000 1.22
+++ dlls/dinput/device.c 17 Sep 2004 11:44:28 -0000
@@ -475,11 +475,11 @@
ULONG WINAPI IDirectInputDevice2AImpl_Release(LPDIRECTINPUTDEVICE8A iface)
{
IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface;
- This->ref--;
- if (This->ref)
- return This->ref;
- HeapFree(GetProcessHeap(),0,This);
- return DI_OK;
+ ULONG ref;
+ ref = InterlockedDecrement(&(This->ref));
+ if (ref == 0)
+ HeapFree(GetProcessHeap(),0,This);
+ return ref;
}
HRESULT WINAPI IDirectInputDevice2AImpl_QueryInterface(
@@ -548,7 +548,7 @@
LPDIRECTINPUTDEVICE8A iface)
{
IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface;
- return ++This->ref;
+ return InterlockedIncrement(&(This->ref));
}
HRESULT WINAPI IDirectInputDevice2AImpl_EnumObjects(
@@ -688,8 +688,6 @@
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 @@
FIXME("(this=%p,%p,%p,0x%08lx): stub!\n",
iface, lpCallback, lpvRef, dwFlags);
- if (lpCallback)
- lpCallback(NULL, lpvRef);
return DI_OK;
}
Index: dlls/dinput/dinput_main.c
===================================================================
RCS file: /home/wine/wine/dlls/dinput/dinput_main.c,v
retrieving revision 1.46
diff -u -r1.46 dinput_main.c
--- dlls/dinput/dinput_main.c 13 Sep 2004 19:16:47 -0000 1.46
+++ dlls/dinput/dinput_main.c 17 Sep 2004 11:44:28 -0000
@@ -291,17 +291,17 @@
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 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(
Index: dlls/dinput/joystick_linux.c
===================================================================
RCS file: /home/wine/wine/dlls/dinput/joystick_linux.c,v
retrieving revision 1.16
diff -u -r1.16 joystick_linux.c
--- dlls/dinput/joystick_linux.c 13 Sep 2004 19:16:47 -0000 1.16
+++ dlls/dinput/joystick_linux.c 17 Sep 2004 11:44:30 -0000
@@ -662,10 +662,11 @@
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)
Index: dlls/dinput/joystick_linuxinput.c
===================================================================
RCS file: /home/wine/wine/dlls/dinput/joystick_linuxinput.c,v
retrieving revision 1.11
diff -u -r1.11 joystick_linuxinput.c
--- dlls/dinput/joystick_linuxinput.c 13 Sep 2004 19:16:47 -0000 1.11
+++ dlls/dinput/joystick_linuxinput.c 17 Sep 2004 11:44:30 -0000
@@ -332,10 +332,11 @@
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)
Index: dlls/dinput/keyboard.c
===================================================================
RCS file: /home/wine/wine/dlls/dinput/keyboard.c,v
retrieving revision 1.7
diff -u -r1.7 keyboard.c
--- dlls/dinput/keyboard.c 13 Sep 2004 19:16:47 -0000 1.7
+++ dlls/dinput/keyboard.c 17 Sep 2004 11:44:31 -0000
@@ -303,10 +303,11 @@
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) {
Index: dlls/dinput/mouse.c
===================================================================
RCS file: /home/wine/wine/dlls/dinput/mouse.c,v
retrieving revision 1.10
diff -u -r1.10 mouse.c
--- dlls/dinput/mouse.c 13 Sep 2004 19:16:47 -0000 1.10
+++ dlls/dinput/mouse.c 17 Sep 2004 11:44:32 -0000
@@ -326,10 +326,11 @@
static ULONG WINAPI SysMouseAImpl_Release(LPDIRECTINPUTDEVICE8A iface)
{
SysMouseImpl *This = (SysMouseImpl *)iface;
-
- This->ref--;
- if (This->ref)
- return This->ref;
+ ULONG ref;
+
+ ref = InterlockedDecrement(&(This->ref));
+ if (ref)
+ return ref;
/* Free the data queue */
if (This->data_queue != NULL)
@@ -349,7 +350,7 @@
}
HeapFree(GetProcessHeap(),0,This);
- return DI_OK;
+ return 0;
}
More information about the wine-patches
mailing list