summaryrefslogtreecommitdiffhomepage
path: root/opentrack/win32-joystick.cpp
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2015-12-17 22:52:54 +0100
committerStanislaw Halik <sthalik@misaki.pl>2015-12-17 22:52:54 +0100
commit3e543b11f57aa6c010045fb9614eb2638ac6ae81 (patch)
tree2975fccb82dc638d303ae6a6208c3e20ac448a0b /opentrack/win32-joystick.cpp
parentf38541f1956133be9b093d5439128d3481b7e5fa (diff)
api/joy: refresh only manually on certain events
Refresh joylist when new listener arrives, and when the joy singleton just gets created. Enumerating joys all the time causes high CPU usage for some of the users. Issue: #279 Backtrace-by: @exulant Reported-by: @aka2k
Diffstat (limited to 'opentrack/win32-joystick.cpp')
-rw-r--r--opentrack/win32-joystick.cpp25
1 files changed, 7 insertions, 18 deletions
diff --git a/opentrack/win32-joystick.cpp b/opentrack/win32-joystick.cpp
index 728e2f68..5e6f2011 100644
--- a/opentrack/win32-joystick.cpp
+++ b/opentrack/win32-joystick.cpp
@@ -6,7 +6,7 @@
void win32_joy_ctx::poll(fn f)
{
- refresh(false);
+ //refresh(false);
QMutexLocker l(&mtx);
@@ -94,7 +94,7 @@ win32_joy_ctx::win32_joy_ctx()
qDebug() << "setup DirectInput8 Creation failed!" << GetLastError();
assert(!"direct input handle can't be created");
}
- refresh(true);
+ refresh();
}
void win32_joy_ctx::release()
@@ -104,18 +104,12 @@ void win32_joy_ctx::release()
di = nullptr;
}
-void win32_joy_ctx::refresh(bool first)
+void win32_joy_ctx::refresh()
{
- if (!first)
- {
- // accessing struct Timer without a lock. worst can happen is seconds
- // and nanoseconds getting out of sync. no big deal.
- if (timer_joylist.elapsed_ms() < joylist_refresh_ms)
- return;
- timer_joylist.start();
- }
+ QMutexLocker l(&mtx);
- enum_state st(joys, mtx, fake_main_window, di);
+ qDebug() << "joy list refresh";
+ enum_state st(joys, fake_main_window, di);
}
QString win32_joy_ctx::guid_to_string(const GUID guid)
@@ -184,16 +178,12 @@ bool win32_joy_ctx::joy::poll(fn f)
}
win32_joy_ctx::enum_state::enum_state(std::unordered_map<QString, std::shared_ptr<joy>> &joys,
- QMutex& mtx,
QMainWindow &fake_main_window,
LPDIRECTINPUT8 di) :
fake_main_window(fake_main_window),
di(di)
{
- {
- QMutexLocker l(&mtx);
- this->joys = joys;
- }
+ this->joys = joys;
HRESULT hr;
@@ -216,7 +206,6 @@ win32_joy_ctx::enum_state::enum_state(std::unordered_map<QString, std::shared_pt
it++;
}
- QMutexLocker l(&mtx);
joys = this->joys;
}