Lock joystick states for thread safety.

This commit is contained in:
Andrzej Kapolka 2014-05-16 11:18:21 -07:00
parent 5a2f61084e
commit 20eadab970
2 changed files with 9 additions and 1 deletions

View file

@ -44,10 +44,16 @@ JoystickManager::~JoystickManager() {
#endif
}
QVector<JoystickState> JoystickManager::getJoystickStates() {
QMutexLocker locker(&_joystickMutex);
return _joystickStates;
}
void JoystickManager::update() {
#ifdef HAVE_SDL
SDL_JoystickUpdate();
QMutexLocker locker(&_joystickMutex);
for (int i = 0; i < _joystickStates.size(); i++) {
SDL_Joystick* joystick = _joysticks.at(i);
JoystickState& state = _joystickStates[i];

View file

@ -12,6 +12,7 @@
#ifndef hifi_JoystickManager_h
#define hifi_JoystickManager_h
#include <QMutex>
#include <QObject>
#include <QVector>
@ -31,12 +32,13 @@ public:
JoystickManager();
virtual ~JoystickManager();
const QVector<JoystickState>& getJoystickStates() const { return _joystickStates; }
QVector<JoystickState> getJoystickStates();
void update();
private:
QVector<JoystickState> _joystickStates;
QMutex _joystickMutex;
#ifdef HAVE_SDL
QVector<SDL_Joystick*> _joysticks;