diff options
-rw-r--r-- | ftnoir_tracker_aruco/ftnoir_tracker_aruco.cpp | 3 | ||||
-rw-r--r-- | ftnoir_tracker_pt/ftnoir_tracker_pt.cpp | 3 | ||||
-rw-r--r-- | opentrack/thread.hpp | 37 | ||||
-rw-r--r-- | opentrack/tracker.cpp | 3 |
4 files changed, 46 insertions, 0 deletions
diff --git a/ftnoir_tracker_aruco/ftnoir_tracker_aruco.cpp b/ftnoir_tracker_aruco/ftnoir_tracker_aruco.cpp index 793469e2..2447e24a 100644 --- a/ftnoir_tracker_aruco/ftnoir_tracker_aruco.cpp +++ b/ftnoir_tracker_aruco/ftnoir_tracker_aruco.cpp @@ -16,6 +16,7 @@ #include <opencv2/core/core.hpp> #include <opencv2/highgui/highgui.hpp> #include "opentrack/camera-names.hpp" +#include "opentrack/thread.hpp" typedef struct { int width; @@ -73,6 +74,8 @@ void Tracker::getRT(cv::Matx33d& r_, cv::Vec3d& t_) void Tracker::run() { + Affinity thr; + int rint = s.resolution; if (rint < 0 || rint >= (int)(sizeof(resolution_choices) / sizeof(resolution_tuple))) rint = 0; diff --git a/ftnoir_tracker_pt/ftnoir_tracker_pt.cpp b/ftnoir_tracker_pt/ftnoir_tracker_pt.cpp index 24867a4c..c6f14527 100644 --- a/ftnoir_tracker_pt/ftnoir_tracker_pt.cpp +++ b/ftnoir_tracker_pt/ftnoir_tracker_pt.cpp @@ -12,6 +12,7 @@ #include <QDebug> #include <QFile> #include <QCoreApplication> +#include "opentrack/thread.hpp" using namespace std; using namespace cv; @@ -64,6 +65,8 @@ void Tracker::run() if (!log_file.open(QIODevice::WriteOnly | QIODevice::Text)) return; QTextStream log_stream(&log_file); #endif + + Affinity thr; while((commands & ABORT) == 0) { 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); |