dinput: Move critical section to the base device class.

This commit is contained in:
Vitaliy Margolen 2006-12-01 10:56:00 -07:00 committed by Alexandre Julliard
parent f7eacd64d1
commit 0da0486cc3
6 changed files with 43 additions and 32 deletions

View File

@ -454,11 +454,14 @@ BOOL DIEnumDevicesCallbackAtoW(LPCDIDEVICEOBJECTINSTANCEA lpddi, LPVOID lpvRef)
HRESULT WINAPI IDirectInputDevice2AImpl_Acquire(LPDIRECTINPUTDEVICE8A iface) HRESULT WINAPI IDirectInputDevice2AImpl_Acquire(LPDIRECTINPUTDEVICE8A iface)
{ {
IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface; IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface;
HRESULT res;
if (This->acquired) return S_FALSE; EnterCriticalSection(&This->crit);
res = This->acquired ? S_FALSE : DI_OK;
This->acquired = 1; This->acquired = 1;
LeaveCriticalSection(&This->crit);
return DI_OK; return res;
} }
/****************************************************************************** /******************************************************************************
@ -468,11 +471,14 @@ HRESULT WINAPI IDirectInputDevice2AImpl_Acquire(LPDIRECTINPUTDEVICE8A iface)
HRESULT WINAPI IDirectInputDevice2AImpl_Unacquire(LPDIRECTINPUTDEVICE8A iface) HRESULT WINAPI IDirectInputDevice2AImpl_Unacquire(LPDIRECTINPUTDEVICE8A iface)
{ {
IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface; IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface;
HRESULT res;
if (!This->acquired) return DI_NOEFFECT; EnterCriticalSection(&This->crit);
res = !This->acquired ? DI_NOEFFECT : DI_OK;
This->acquired = 0; This->acquired = 0;
LeaveCriticalSection(&This->crit);
return DI_OK; return res;
} }
/****************************************************************************** /******************************************************************************
@ -524,8 +530,10 @@ HRESULT WINAPI IDirectInputDevice2AImpl_SetCooperativeLevel(
return DIERR_UNSUPPORTED; return DIERR_UNSUPPORTED;
/* Store the window which asks for the mouse */ /* Store the window which asks for the mouse */
EnterCriticalSection(&This->crit);
This->win = hwnd; This->win = hwnd;
This->dwCoopLevel = dwflags; This->dwCoopLevel = dwflags;
LeaveCriticalSection(&This->crit);
return DI_OK; return DI_OK;
} }
@ -540,7 +548,9 @@ HRESULT WINAPI IDirectInputDevice2AImpl_SetEventNotification(
TRACE("(%p) %p\n", This, event); TRACE("(%p) %p\n", This, event);
EnterCriticalSection(&This->crit);
This->hEvent = event; This->hEvent = event;
LeaveCriticalSection(&This->crit);
return DI_OK; return DI_OK;
} }

View File

@ -33,6 +33,7 @@ struct IDirectInputDevice2AImpl
const void *lpVtbl; const void *lpVtbl;
LONG ref; LONG ref;
GUID guid; GUID guid;
CRITICAL_SECTION crit;
HANDLE hEvent; HANDLE hEvent;
DWORD dwCoopLevel; DWORD dwCoopLevel;
HWND win; HWND win;

View File

@ -115,7 +115,6 @@ struct JoystickImpl
int axes; int axes;
int buttons; int buttons;
POV povs[4]; POV povs[4];
CRITICAL_SECTION crit;
BOOL overflow; BOOL overflow;
}; };
@ -500,6 +499,8 @@ static HRESULT alloc_device(REFGUID rguid, const void *jvt, IDirectInputImpl *di
newDevice->dinput = dinput; newDevice->dinput = dinput;
newDevice->overflow = FALSE; newDevice->overflow = FALSE;
CopyMemory(&newDevice->base.guid, rguid, sizeof(*rguid)); CopyMemory(&newDevice->base.guid, rguid, sizeof(*rguid));
InitializeCriticalSection(&newDevice->base.crit);
newDevice->base.crit.DebugInfo->Spare[0] = (DWORD_PTR)"DINPUT_joystick";
/* setup_dinput_options may change these */ /* setup_dinput_options may change these */
newDevice->deadzone = 5000; newDevice->deadzone = 5000;
@ -560,8 +561,6 @@ static HRESULT alloc_device(REFGUID rguid, const void *jvt, IDirectInputImpl *di
calculate_ids(newDevice); calculate_ids(newDevice);
IDirectInputDevice_AddRef((LPDIRECTINPUTDEVICE8A)newDevice->dinput); IDirectInputDevice_AddRef((LPDIRECTINPUTDEVICE8A)newDevice->dinput);
InitializeCriticalSection(&(newDevice->crit));
newDevice->crit.DebugInfo->Spare[0] = (DWORD_PTR)"DINPUT_Mouse";
newDevice->devcaps.dwSize = sizeof(newDevice->devcaps); newDevice->devcaps.dwSize = sizeof(newDevice->devcaps);
newDevice->devcaps.dwFlags = DIDC_ATTACHED; newDevice->devcaps.dwFlags = DIDC_ATTACHED;
@ -697,8 +696,8 @@ static ULONG WINAPI JoystickAImpl_Release(LPDIRECTINPUTDEVICE8A iface)
/* release the data transform filter */ /* release the data transform filter */
release_DataFormat(This->transform); release_DataFormat(This->transform);
This->crit.DebugInfo->Spare[0] = 0; This->base.crit.DebugInfo->Spare[0] = 0;
DeleteCriticalSection(&(This->crit)); DeleteCriticalSection(&This->base.crit);
IDirectInputDevice_Release((LPDIRECTINPUTDEVICE8A)This->dinput); IDirectInputDevice_Release((LPDIRECTINPUTDEVICE8A)This->dinput);
HeapFree(GetProcessHeap(),0,This); HeapFree(GetProcessHeap(),0,This);
@ -1040,7 +1039,7 @@ static HRESULT WINAPI JoystickAImpl_GetDeviceData(
return DIERR_NOTACQUIRED; return DIERR_NOTACQUIRED;
} }
EnterCriticalSection(&(This->crit)); EnterCriticalSection(&This->base.crit);
joy_polldev(This); joy_polldev(This);
@ -1060,7 +1059,7 @@ static HRESULT WINAPI JoystickAImpl_GetDeviceData(
} else { } else {
if (dodsize < sizeof(DIDEVICEOBJECTDATA_DX3)) { if (dodsize < sizeof(DIDEVICEOBJECTDATA_DX3)) {
ERR("Wrong structure size !\n"); ERR("Wrong structure size !\n");
LeaveCriticalSection(&(This->crit)); LeaveCriticalSection(&This->base.crit);
return DIERR_INVALIDPARAM; return DIERR_INVALIDPARAM;
} }
@ -1091,7 +1090,7 @@ static HRESULT WINAPI JoystickAImpl_GetDeviceData(
if (!(flags & DIGDD_PEEK)) if (!(flags & DIGDD_PEEK))
This->queue_tail = nqtail; This->queue_tail = nqtail;
LeaveCriticalSection(&(This->crit)); LeaveCriticalSection(&This->base.crit);
return hr; return hr;
} }

View File

@ -377,6 +377,7 @@ static JoystickImpl *alloc_device(REFGUID rguid, const void *jvt, IDirectInputIm
newDevice->base.lpVtbl = jvt; newDevice->base.lpVtbl = jvt;
newDevice->base.ref = 1; newDevice->base.ref = 1;
memcpy(&newDevice->base.guid, rguid, sizeof(*rguid)); memcpy(&newDevice->base.guid, rguid, sizeof(*rguid));
InitializeCriticalSection(&newDevice->base.crit);
newDevice->joyfd = -1; newDevice->joyfd = -1;
newDevice->dinput = dinput; newDevice->dinput = dinput;
newDevice->joydev = joydev; newDevice->joydev = joydev;
@ -543,6 +544,8 @@ static ULONG WINAPI JoystickAImpl_Release(LPDIRECTINPUTDEVICE8A iface)
/* release the data transform filter */ /* release the data transform filter */
release_DataFormat(This->transform); release_DataFormat(This->transform);
DeleteCriticalSection(&This->base.crit);
HeapFree(GetProcessHeap(),0,This); HeapFree(GetProcessHeap(),0,This);
return 0; return 0;
} }

View File

@ -57,7 +57,6 @@ struct SysKeyboardImpl
int queue_head; /* position to write new event into queue */ int queue_head; /* position to write new event into queue */
int queue_tail; /* next event to read from queue */ int queue_tail; /* next event to read from queue */
BOOL overflow; /* return DI_BUFFEROVERFLOW in 'GetDeviceData' */ BOOL overflow; /* return DI_BUFFEROVERFLOW in 'GetDeviceData' */
CRITICAL_SECTION crit;
}; };
static SysKeyboardImpl* current_lock = NULL; static SysKeyboardImpl* current_lock = NULL;
@ -94,9 +93,9 @@ LRESULT CALLBACK KeyboardCallback( int code, WPARAM wparam, LPARAM lparam )
DInputKeyState[dik_code] = new_diks; DInputKeyState[dik_code] = new_diks;
TRACE(" setting %02X to %02X\n", dik_code, DInputKeyState[dik_code]); TRACE(" setting %02X to %02X\n", dik_code, DInputKeyState[dik_code]);
EnterCriticalSection(&This->crit); EnterCriticalSection(&This->base.crit);
GEN_EVENT(dik_code, new_diks, hook->time, This->dinput->evsequence++); GEN_EVENT(dik_code, new_diks, hook->time, This->dinput->evsequence++);
LeaveCriticalSection(&This->crit); LeaveCriticalSection(&This->base.crit);
if (This->base.hEvent) SetEvent(This->base.hEvent); if (This->base.hEvent) SetEvent(This->base.hEvent);
@ -203,7 +202,7 @@ static SysKeyboardImpl *alloc_device(REFGUID rguid, const void *kvt, IDirectInpu
newDevice->base.ref = 1; newDevice->base.ref = 1;
memcpy(&newDevice->base.guid, rguid, sizeof(*rguid)); memcpy(&newDevice->base.guid, rguid, sizeof(*rguid));
newDevice->dinput = dinput; newDevice->dinput = dinput;
InitializeCriticalSection(&(newDevice->crit)); InitializeCriticalSection(&newDevice->base.crit);
return newDevice; return newDevice;
} }
@ -266,7 +265,7 @@ static ULONG WINAPI SysKeyboardAImpl_Release(LPDIRECTINPUTDEVICE8A iface)
/* Free the data queue */ /* Free the data queue */
HeapFree(GetProcessHeap(), 0, This->data_queue); HeapFree(GetProcessHeap(), 0, This->data_queue);
DeleteCriticalSection(&(This->crit)); DeleteCriticalSection(&This->base.crit);
HeapFree(GetProcessHeap(),0,This); HeapFree(GetProcessHeap(),0,This);
return DI_OK; return DI_OK;
@ -348,7 +347,7 @@ static HRESULT WINAPI SysKeyboardAImpl_GetDeviceState(
MsgWaitForMultipleObjectsEx(0, NULL, 0, QS_ALLINPUT, 0); MsgWaitForMultipleObjectsEx(0, NULL, 0, QS_ALLINPUT, 0);
EnterCriticalSection(&(This->crit)); EnterCriticalSection(&This->base.crit);
if (TRACE_ON(dinput)) { if (TRACE_ON(dinput)) {
int i; int i;
@ -360,7 +359,7 @@ static HRESULT WINAPI SysKeyboardAImpl_GetDeviceState(
} }
memcpy(ptr, DInputKeyState, WINE_DINPUT_KEYBOARD_MAX_KEYS); memcpy(ptr, DInputKeyState, WINE_DINPUT_KEYBOARD_MAX_KEYS);
LeaveCriticalSection(&(This->crit)); LeaveCriticalSection(&This->base.crit);
return DI_OK; return DI_OK;
} }
@ -387,7 +386,7 @@ static HRESULT WINAPI SysKeyboardAImpl_GetDeviceData(
return DIERR_INVALIDPARAM; return DIERR_INVALIDPARAM;
MsgWaitForMultipleObjectsEx(0, NULL, 0, QS_ALLINPUT, 0); MsgWaitForMultipleObjectsEx(0, NULL, 0, QS_ALLINPUT, 0);
EnterCriticalSection(&This->crit); EnterCriticalSection(&This->base.crit);
len = ((This->queue_head < This->queue_tail) ? This->queue_len : 0) + len = ((This->queue_head < This->queue_tail) ? This->queue_len : 0) +
This->queue_head - This->queue_tail; This->queue_head - This->queue_tail;
@ -414,7 +413,7 @@ static HRESULT WINAPI SysKeyboardAImpl_GetDeviceData(
This->overflow = FALSE; This->overflow = FALSE;
} }
LeaveCriticalSection(&This->crit); LeaveCriticalSection(&This->base.crit);
TRACE("Returning %d events queued\n", *entries); TRACE("Returning %d events queued\n", *entries);
return ret; return ret;

View File

@ -133,7 +133,6 @@ struct SysMouseImpl
* reach window borders (for e.g. shooters, "surface movement" games) */ * reach window borders (for e.g. shooters, "surface movement" games) */
WARP_STATUS need_warp; WARP_STATUS need_warp;
DWORD last_warped; DWORD last_warped;
CRITICAL_SECTION crit;
/* This is for mouse reporting. */ /* This is for mouse reporting. */
Wine_InternalMouseData m_state; Wine_InternalMouseData m_state;
@ -249,7 +248,7 @@ static SysMouseImpl *alloc_device(REFGUID rguid, const void *mvt, IDirectInputIm
newDevice->base.ref = 1; newDevice->base.ref = 1;
newDevice->base.dwCoopLevel = DISCL_NONEXCLUSIVE | DISCL_BACKGROUND; newDevice->base.dwCoopLevel = DISCL_NONEXCLUSIVE | DISCL_BACKGROUND;
memcpy(&newDevice->base.guid, rguid, sizeof(*rguid)); memcpy(&newDevice->base.guid, rguid, sizeof(*rguid));
InitializeCriticalSection(&(newDevice->crit)); InitializeCriticalSection(&newDevice->base.crit);
/* Per default, Wine uses its internal data format */ /* Per default, Wine uses its internal data format */
newDevice->df = (DIDATAFORMAT *) &Wine_InternalMouseFormat; newDevice->df = (DIDATAFORMAT *) &Wine_InternalMouseFormat;
@ -329,7 +328,7 @@ static ULONG WINAPI SysMouseAImpl_Release(LPDIRECTINPUTDEVICE8A iface)
/* Free the data queue */ /* Free the data queue */
HeapFree(GetProcessHeap(),0,This->data_queue); HeapFree(GetProcessHeap(),0,This->data_queue);
DeleteCriticalSection(&(This->crit)); DeleteCriticalSection(&This->base.crit);
/* Free the DataFormat */ /* Free the DataFormat */
if (This->df != &(Wine_InternalMouseFormat)) { if (This->df != &(Wine_InternalMouseFormat)) {
@ -385,7 +384,7 @@ static LRESULT CALLBACK dinput_mouse_hook( int code, WPARAM wparam, LPARAM lpara
if (code != HC_ACTION) return CallNextHookEx( 0, code, wparam, lparam ); if (code != HC_ACTION) return CallNextHookEx( 0, code, wparam, lparam );
EnterCriticalSection(&(This->crit)); EnterCriticalSection(&This->base.crit);
dwCoop = This->base.dwCoopLevel; dwCoop = This->base.dwCoopLevel;
if (wparam == WM_MOUSEMOVE) { if (wparam == WM_MOUSEMOVE) {
@ -495,7 +494,7 @@ static LRESULT CALLBACK dinput_mouse_hook( int code, WPARAM wparam, LPARAM lpara
/* Mouse moved -> send event if asked */ /* Mouse moved -> send event if asked */
if (This->base.hEvent) SetEvent(This->base.hEvent); if (This->base.hEvent) SetEvent(This->base.hEvent);
LeaveCriticalSection(&(This->crit)); LeaveCriticalSection(&This->base.crit);
/* Ignore message */ /* Ignore message */
if (dwCoop & DISCL_EXCLUSIVE) return 1; if (dwCoop & DISCL_EXCLUSIVE) return 1;
@ -631,7 +630,7 @@ static HRESULT WINAPI SysMouseAImpl_GetDeviceState(
if(This->base.acquired == 0) return DIERR_NOTACQUIRED; if(This->base.acquired == 0) return DIERR_NOTACQUIRED;
EnterCriticalSection(&(This->crit)); EnterCriticalSection(&This->base.crit);
TRACE("(this=%p,0x%08x,%p):\n", This, len, ptr); TRACE("(this=%p,0x%08x,%p):\n", This, len, ptr);
TRACE("(X: %d - Y: %d - Z: %d L: %02x M: %02x R: %02x)\n", TRACE("(X: %d - Y: %d - Z: %d L: %02x M: %02x R: %02x)\n",
This->m_state.lX, This->m_state.lY, This->m_state.lZ, This->m_state.lX, This->m_state.lY, This->m_state.lZ,
@ -651,7 +650,7 @@ static HRESULT WINAPI SysMouseAImpl_GetDeviceState(
if (This->need_warp == WARP_NEEDED && (GetCurrentTime() - This->last_warped > 10)) { if (This->need_warp == WARP_NEEDED && (GetCurrentTime() - This->last_warped > 10)) {
if(!dinput_window_check(This)) if(!dinput_window_check(This))
{ {
LeaveCriticalSection(&(This->crit)); LeaveCriticalSection(&This->base.crit);
return DIERR_GENERIC; return DIERR_GENERIC;
} }
TRACE("Warping mouse to %d - %d\n", This->mapped_center.x, This->mapped_center.y); TRACE("Warping mouse to %d - %d\n", This->mapped_center.x, This->mapped_center.y);
@ -665,7 +664,7 @@ static HRESULT WINAPI SysMouseAImpl_GetDeviceState(
#endif #endif
} }
LeaveCriticalSection(&(This->crit)); LeaveCriticalSection(&This->base.crit);
return DI_OK; return DI_OK;
} }
@ -692,7 +691,7 @@ static HRESULT WINAPI SysMouseAImpl_GetDeviceData(LPDIRECTINPUTDEVICE8A iface,
return DIERR_NOTACQUIRED; return DIERR_NOTACQUIRED;
} }
EnterCriticalSection(&(This->crit)); EnterCriticalSection(&This->base.crit);
len = ((This->queue_head < This->queue_tail) ? This->queue_len : 0) len = ((This->queue_head < This->queue_tail) ? This->queue_len : 0)
+ (This->queue_head - This->queue_tail); + (This->queue_head - This->queue_tail);
@ -713,7 +712,7 @@ static HRESULT WINAPI SysMouseAImpl_GetDeviceData(LPDIRECTINPUTDEVICE8A iface,
} else { } else {
if (dodsize < sizeof(DIDEVICEOBJECTDATA_DX3)) { if (dodsize < sizeof(DIDEVICEOBJECTDATA_DX3)) {
ERR("Wrong structure size !\n"); ERR("Wrong structure size !\n");
LeaveCriticalSection(&(This->crit)); LeaveCriticalSection(&This->base.crit);
return DIERR_INVALIDPARAM; return DIERR_INVALIDPARAM;
} }
@ -743,7 +742,7 @@ static HRESULT WINAPI SysMouseAImpl_GetDeviceData(LPDIRECTINPUTDEVICE8A iface,
if (!(flags & DIGDD_PEEK)) if (!(flags & DIGDD_PEEK))
This->queue_tail = nqtail; This->queue_tail = nqtail;
LeaveCriticalSection(&(This->crit)); LeaveCriticalSection(&This->base.crit);
/* Check if we need to do a mouse warping */ /* Check if we need to do a mouse warping */
if (This->need_warp == WARP_NEEDED && (GetCurrentTime() - This->last_warped > 10)) { if (This->need_warp == WARP_NEEDED && (GetCurrentTime() - This->last_warped > 10)) {