From 67710b224346b962fe2b53f84b7ab17c8ee52191 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Thu, 4 Jun 2015 19:52:37 +0200 Subject: all: pin computation threads to specific cores --- opentrack/thread.hpp | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 opentrack/thread.hpp (limited to 'opentrack/thread.hpp') 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 + +enum { + CORE_WORK = 1, + CORE_IPC = 0, +}; + +#ifdef _WIN32 +#include + +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 -- cgit v1.2.3