summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--compat/thread-name.cpp80
-rw-r--r--compat/thread-name.hpp6
-rw-r--r--dinput/keybinding-worker.cpp3
-rw-r--r--logic/pipeline.cpp3
-rw-r--r--tracker-pt/ftnoir_tracker_pt.cpp3
-rw-r--r--video-opencv/video-property-page.cpp3
6 files changed, 98 insertions, 0 deletions
diff --git a/compat/thread-name.cpp b/compat/thread-name.cpp
new file mode 100644
index 00000000..f74ac505
--- /dev/null
+++ b/compat/thread-name.cpp
@@ -0,0 +1,80 @@
+#ifdef _WIN32
+# ifndef _WIN32_WINNT
+# define _WIN32_WINNT 0x0501
+# endif
+# include "thread-name.hpp"
+# include <QDebug>
+# include <windows.h>
+#else
+# include <QThread>
+#endif
+
+namespace portable {
+
+#if defined _MSC_VER
+
+struct THREADNAME_INFO
+{
+ DWORD dwType; // must be 0x1000
+ LPCSTR szName; // pointer to name (in user addr space)
+ HANDLE dwThreadID; // thread ID (-1=caller thread)
+ DWORD dwFlags; // reserved for future use, must be zero
+};
+
+static inline
+void set_curthread_name_old(const QString& name_)
+{
+ QByteArray str = name_.toLocal8Bit();
+ const char* name = str.constData();
+ HANDLE curthread = GetCurrentThread();
+
+ THREADNAME_INFO info; // NOLINT(cppcoreguidelines-pro-type-member-init)
+ info.dwType = 0x1000;
+ info.szName = name;
+ info.dwThreadID = curthread;
+ info.dwFlags = 0;
+ __try
+ {
+ static_assert(sizeof(info) % sizeof(unsigned) == 0);
+ unsigned sz = sizeof(info)/sizeof(unsigned);
+ RaiseException(0x406D1388, 0, sz, (const ULONG_PTR*)&info);
+ }
+ __except (EXCEPTION_CONTINUE_EXECUTION)
+ {
+ }
+}
+
+void set_curthread_name(const QString& name)
+{
+ static_assert(sizeof(wchar_t) == sizeof(decltype(*QString().utf16())));
+
+ HMODULE module;
+ HRESULT (__stdcall *fn)(HANDLE, const wchar_t*);
+ if (GetModuleHandleExA(0, "kernel32.dll", &module) &&
+ (fn = (decltype(fn))GetProcAddress(module, "SetThreadDescription")))
+ {
+ fn(GetCurrentThread(), (const wchar_t*)name.utf16());
+ }
+ else
+ {
+ set_curthread_name_old(name);
+ }
+}
+
+#elif defined _WIN32
+
+void set_curthread_name(const QString& name)
+{
+ (void)name;
+}
+
+#else
+
+void set_curthread_name(const QString& name)
+{
+ QThread::currentThread()->setObjectName(name);
+}
+
+#endif
+
+} // ns portable
diff --git a/compat/thread-name.hpp b/compat/thread-name.hpp
new file mode 100644
index 00000000..21256003
--- /dev/null
+++ b/compat/thread-name.hpp
@@ -0,0 +1,6 @@
+#pragma once
+#include "export.hpp"
+#include <QString>
+namespace portable {
+ OTR_COMPAT_EXPORT void set_curthread_name(const QString& name);
+}
diff --git a/dinput/keybinding-worker.cpp b/dinput/keybinding-worker.cpp
index 14676c05..0ceca789 100644
--- a/dinput/keybinding-worker.cpp
+++ b/dinput/keybinding-worker.cpp
@@ -10,6 +10,7 @@
#include "keybinding-worker.hpp"
#include "compat/macros.hpp"
+#include "compat/thread-name.hpp"
#include <QDebug>
#include <QMutexLocker>
@@ -112,6 +113,8 @@ KeybindingWorker& KeybindingWorker::make()
void KeybindingWorker::run()
{
+ portable::set_curthread_name("keybinding worker");
+
while (!isInterruptionRequested())
{
{
diff --git a/logic/pipeline.cpp b/logic/pipeline.cpp
index 75f91848..4cf52e54 100644
--- a/logic/pipeline.cpp
+++ b/logic/pipeline.cpp
@@ -16,6 +16,7 @@
#include "compat/math.hpp"
#include "compat/meta.hpp"
#include "compat/macros.hpp"
+#include "compat/thread-name.hpp"
#include "pipeline.hpp"
#include "logic/shortcuts.h"
@@ -515,6 +516,8 @@ static void debug_timings(float backlog_time)
void pipeline::run()
{
+ portable::set_curthread_name("tracking pipeline");
+
#if defined _WIN32
const MMRESULT mmres = timeBeginPeriod(1);
#endif
diff --git a/tracker-pt/ftnoir_tracker_pt.cpp b/tracker-pt/ftnoir_tracker_pt.cpp
index 73112522..d7484e9c 100644
--- a/tracker-pt/ftnoir_tracker_pt.cpp
+++ b/tracker-pt/ftnoir_tracker_pt.cpp
@@ -10,6 +10,7 @@
#include "video/video-widget.hpp"
#include "compat/math-imports.hpp"
#include "compat/check-visible.hpp"
+#include "compat/thread-name.hpp"
#include "pt-api.hpp"
@@ -51,6 +52,8 @@ Tracker_PT::~Tracker_PT()
void Tracker_PT::run()
{
+ portable::set_curthread_name("tracker/pt");
+
maybe_reopen_camera();
while(!isInterruptionRequested())
diff --git a/video-opencv/video-property-page.cpp b/video-opencv/video-property-page.cpp
index 375518db..a43a5ba0 100644
--- a/video-opencv/video-property-page.cpp
+++ b/video-opencv/video-property-page.cpp
@@ -13,6 +13,7 @@
#include "compat/sleep.hpp"
#include "compat/run-in-thread.hpp"
#include "compat/library-path.hpp"
+#include "compat/thread-name.hpp"
#include <cstring>
@@ -121,6 +122,8 @@ prop_settings_worker::~prop_settings_worker()
void prop_settings_worker::run()
{
+ portable::set_curthread_name("dshow video property page");
+
if (idx != -1)
{
while (cap.get(cv::CAP_PROP_SETTINGS) > 0)