mirror of
https://github.com/overte-org/overte.git
synced 2025-04-25 19:36:44 +02:00
Lock joystick states for thread safety.
This commit is contained in:
parent
5a2f61084e
commit
20eadab970
2 changed files with 9 additions and 1 deletions
|
@ -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];
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue