diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2015-06-04 19:52:37 +0200 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2015-06-05 09:56:03 +0200 |
commit | 67710b224346b962fe2b53f84b7ab17c8ee52191 (patch) | |
tree | ef50ab586225f236c462a59ec6c891c7287f842d /opentrack | |
parent | 74b8483457b51727dba38aa05a5be9bc773d8a28 (diff) |
all: pin computation threads to specific cores
Diffstat (limited to 'opentrack')
-rw-r--r-- | opentrack/thread.hpp | 37 | ||||
-rw-r--r-- | opentrack/tracker.cpp | 3 |
2 files changed, 40 insertions, 0 deletions
diff --git a/opentrack/thread.hpp b/opentrack/thread.hpp new file mode 100644 index 00000000..f4e15c4e --- /dev/null +++ b/opentrack/thread.hpp @@ -0,0 +1,37 @@ +#pragma once + +#include <QDebug> + +enum { + CORE_WORK = 1, + CORE_IPC = 0, +}; + +#ifdef _WIN32 +#include <windows.h> + +class Affinity { +public: + Affinity(int core = CORE_WORK) + { + DWORD_PTR ret = SetThreadAffinityMask(GetCurrentThread(), 1 << core); + if (ret == 0) + qDebug() << "SetThreadAffinityMask" << GetLastError(); + last = ret; + } + ~Affinity() + { + if (last) + (void) SetThreadAffinityMask(GetCurrentThread(), last); + } +private: + DWORD_PTR last; +}; + +#else +class Affinity { +public: + Affinity() {} + ~Affinity() {} +} +#endif diff --git a/opentrack/tracker.cpp b/opentrack/tracker.cpp index a9475838..1990d613 100644 --- a/opentrack/tracker.cpp +++ b/opentrack/tracker.cpp @@ -14,6 +14,7 @@ #include "tracker.h" +#include "opentrack/thread.hpp" #include <cmath> #include <algorithm> @@ -183,6 +184,8 @@ void Tracker::logic() void Tracker::run() { const int sleep_ms = 3; + + Affinity thr(CORE_IPC); #if defined(_WIN32) (void) timeBeginPeriod(1); |