Skip to content

Commit

Permalink
Misc: Move os_set_thread_name method
Browse files Browse the repository at this point in the history
  • Loading branch information
univrsal committed Aug 20, 2022
1 parent 8cfe277 commit 828190f
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 25 deletions.
27 changes: 2 additions & 25 deletions src/network/mg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,8 @@
#include "../util/log.h"
#include "../util/settings.h"

#if _WIN32
#include <windows.h>
const DWORD MS_VC_EXCEPTION = 0x406D1388;
#pragma pack(push, 8)
typedef struct tagTHREADNAME_INFO {
DWORD dwType; // Must be 0x1000.
LPCSTR szName; // Pointer to name (in user addr space).
DWORD dwThreadID; // Thread ID (-1=caller thread).
DWORD dwFlags; // Reserved for future use, must be zero.
} THREADNAME_INFO;
#pragma pack(pop)

inline void os_set_thread_name(const char *name)
{
THREADNAME_INFO info;
info.dwType = 0x1000;
info.szName = name;
info.dwThreadID = GetCurrentThreadId();
info.dwFlags = 0;

__try {
RaiseException(0x406D1388, 0, sizeof(info) / sizeof(DWORD), (const ULONG_PTR *)&info);
} __except (EXCEPTION_CONTINUE_EXECUTION) {
}
}
#ifdef _WIN32
#include "../util/obs_util.hpp"
#else
#include <util/threading.h>
#endif
Expand Down
27 changes: 27 additions & 0 deletions src/util/obs_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,30 @@ bool util_write_json(const QString &path, const QJsonDocument &doc)
}
return result;
}

#if _WIN32
#include <windows.h>
const DWORD MS_VC_EXCEPTION = 0x406D1388;
#pragma pack(push, 8)
typedef struct tagTHREADNAME_INFO {
DWORD dwType; // Must be 0x1000.
LPCSTR szName; // Pointer to name (in user addr space).
DWORD dwThreadID; // Thread ID (-1=caller thread).
DWORD dwFlags; // Reserved for future use, must be zero.
} THREADNAME_INFO;
#pragma pack(pop)

inline void os_set_thread_name(const char *name)
{
THREADNAME_INFO info;
info.dwType = 0x1000;
info.szName = name;
info.dwThreadID = GetCurrentThreadId();
info.dwFlags = 0;

__try {
RaiseException(0x406D1388, 0, sizeof(info) / sizeof(DWORD), (const ULONG_PTR *)&info);
} __except (EXCEPTION_CONTINUE_EXECUTION) {
}
}
#endif
5 changes: 5 additions & 0 deletions src/util/obs_util.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,8 @@ QString util_get_data_file(const QString &file_name);
extern void GetWindowList(std::vector<std::string> &windows);

extern void GetCurrentWindowTitle(std::string &title);


#if _WIN32
extern void os_set_thread_name(const char *);
#endif

0 comments on commit 828190f

Please sign in to comment.