Permalink
Browse files

[win32] Input: Make WINJoystick initialization multithread-safe

  • Loading branch information...
1 parent 2d2e9b8 commit 97b509bac35fc49bec644eca764ac2235d668fc2 @Karlson2k Karlson2k committed Oct 1, 2012
Showing with 5 additions and 0 deletions.
  1. +3 −0 xbmc/input/windows/WINJoystick.cpp
  2. +2 −0 xbmc/input/windows/WINJoystick.h
@@ -50,6 +50,7 @@ extern HWND g_hWnd;
CJoystick::CJoystick()
{
+ CSingleLock lock(m_critSection);
Reset(true);
m_joystickEnabled = false;
m_NumAxes = 0;
@@ -73,6 +74,7 @@ CJoystick::~CJoystick()
void CJoystick::ReleaseJoysticks()
{
+ CSingleLock lock(m_critSection);
// Unacquire the device one last time just in case
// the app tried to exit while the device is still acquired.
for(std::vector<LPDIRECTINPUTDEVICE8>::iterator it = m_pJoysticks.begin(); it != m_pJoysticks.end(); ++it)
@@ -182,6 +184,7 @@ void CJoystick::Initialize()
// clear old joystick names
ReleaseJoysticks();
+ CSingleLock lock(m_critSection);
if( FAILED( hr = DirectInput8Create( GetModuleHandle( NULL ), DIRECTINPUT_VERSION, IID_IDirectInput8, ( VOID** )&m_pDI, NULL ) ) )
{
@@ -21,6 +21,7 @@
#include <vector>
#include <string>
+#include "threads/CriticalSection.h"
#define JACTIVE_BUTTON 0x00000001
#define JACTIVE_AXIS 0x00000002
@@ -84,6 +85,7 @@ class CJoystick
uint8_t m_ActiveFlags;
uint32_t m_lastPressTicks;
uint32_t m_lastTicks;
+ CCriticalSection m_critSection;
LPDIRECTINPUT8 m_pDI;
std::vector<LPDIRECTINPUTDEVICE8> m_pJoysticks;

0 comments on commit 97b509b

Please sign in to comment.