Give all of the Aegisub-created threads names

This commit is contained in:
Thomas Goyne 2013-01-27 16:50:59 -08:00
parent a0d3dbc550
commit bc5417de4a
6 changed files with 39 additions and 33 deletions

View file

@ -18,6 +18,8 @@
#include "libaegisub/dispatch.h" #include "libaegisub/dispatch.h"
#include "libaegisub/util.h"
#include <boost/asio/io_service.hpp> #include <boost/asio/io_service.hpp>
#include <boost/asio/strand.hpp> #include <boost/asio/strand.hpp>
#include <condition_variable> #include <condition_variable>
@ -60,7 +62,10 @@ void Init(std::function<void (Thunk)> invoke_main) {
::invoke_main = invoke_main; ::invoke_main = invoke_main;
for (unsigned i = 0; i < std::max<unsigned>(1, std::thread::hardware_concurrency()); ++i) for (unsigned i = 0; i < std::max<unsigned>(1, std::thread::hardware_concurrency()); ++i)
std::thread([]{ ::service->run(); }).detach(); std::thread([]{
util::SetThreadName("Dispatch Worker");
::service->run();
}).detach();
} }
void Queue::Async(Thunk thunk) { void Queue::Async(Thunk thunk) {

View file

@ -55,5 +55,9 @@ namespace agi {
} }
} }
/// Set the name of the calling thread in the Visual Studio debugger
/// @param name New name for the thread
void SetThreadName(const char *name);
} // namespace util } // namespace util
} // namespace agi } // namespace agi

View file

@ -28,4 +28,6 @@ timeval time_log() {
return tv; return tv;
} }
void SetThreadName(const char *) { }
} } } }

View file

@ -23,6 +23,9 @@
#include "libaegisub/charset_conv_win.h" #include "libaegisub/charset_conv_win.h"
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
namespace agi { namespace agi {
namespace util { namespace util {
@ -74,5 +77,27 @@ agi_timeval time_log() {
return tv; return tv;
} }
#define MS_VC_EXCEPTION 0x406d1388
/// Parameters for setting the thread name
struct THREADNAME_INFO {
DWORD dwType; ///< must be 0x1000
LPCSTR szName; ///< pointer to name (in same addr space)
DWORD dwThreadID; ///< thread ID (-1 caller thread)
DWORD dwFlags; ///< reserved for future use, most be zero
};
void SetThreadName(LPCSTR szThreadName) {
THREADNAME_INFO info;
info.dwType = 0x1000;
info.szName = szThreadName;
info.dwThreadID = -1;
info.dwFlags = 0;
__try {
RaiseException(MS_VC_EXCEPTION, 0, sizeof(info) / sizeof(DWORD), (ULONG_PTR *)&info);
}
__except (EXCEPTION_CONTINUE_EXECUTION) {}
}
} // namespace io } // namespace io
} // namespace agi } // namespace agi

View file

@ -90,37 +90,6 @@ static const char *LastStartupState = nullptr;
#define StartupLog(a) LastStartupState = a #define StartupLog(a) LastStartupState = a
#endif #endif
#ifdef __VISUALC__
#define MS_VC_EXCEPTION 0x406d1388
/// Parameters for setting the thread name
struct THREADNAME_INFO {
DWORD dwType; ///< must be 0x1000
LPCSTR szName; ///< pointer to name (in same addr space)
DWORD dwThreadID; ///< thread ID (-1 caller thread)
DWORD dwFlags; ///< reserved for future use, most be zero
};
/// Set the name of a thread in the visual studio debugger
/// @param dwThreadID Thread ID, or -1 for caller
/// @param szThreadName New name for the thread
void SetThreadName(DWORD dwThreadID, LPCSTR szThreadName) {
THREADNAME_INFO info;
info.dwType = 0x1000;
info.szName = szThreadName;
info.dwThreadID = dwThreadID;
info.dwFlags = 0;
__try {
RaiseException(MS_VC_EXCEPTION, 0, sizeof(info) / sizeof(DWORD), (ULONG_PTR *)&info);
}
__except (EXCEPTION_CONTINUE_EXECUTION) {}
}
#else
void SetThreadName(int dwThreadID, const char *szThreadName) {
}
#endif
void AegisubApp::OnAssertFailure(const wxChar *file, int line, const wxChar *func, const wxChar *cond, const wxChar *msg) { void AegisubApp::OnAssertFailure(const wxChar *file, int line, const wxChar *func, const wxChar *cond, const wxChar *msg) {
LOG_A("wx/assert") << file << ":" << line << ":" << func << "() " << cond << ": " << msg; LOG_A("wx/assert") << file << ":" << line << ":" << func << "() " << cond << ": " << msg;
wxApp::OnAssertFailure(file, line, func, cond, msg); wxApp::OnAssertFailure(file, line, func, cond, msg);
@ -214,7 +183,7 @@ bool AegisubApp::OnInit() {
StartupLog("Load MRU"); StartupLog("Load MRU");
config::mru = new agi::MRUManager(StandardPaths::DecodePath("?user/mru.json"), GET_DEFAULT_CONFIG(default_mru), config::opt); config::mru = new agi::MRUManager(StandardPaths::DecodePath("?user/mru.json"), GET_DEFAULT_CONFIG(default_mru), config::opt);
SetThreadName(-1, "AegiMain"); agi::util::SetThreadName("AegiMain");
StartupLog("Inside OnInit"); StartupLog("Inside OnInit");
frame = nullptr; frame = nullptr;

View file

@ -275,6 +275,7 @@ size_t MaxLineLength(std::string const& text) {
return std::max(max_line_length, current_line_length); return std::max(max_line_length, current_line_length);
} }
// OS X implementation in osx_utils.mm // OS X implementation in osx_utils.mm
#ifndef __WXOSX_COCOA__ #ifndef __WXOSX_COCOA__
void AddFullScreenButton(wxWindow *) { } void AddFullScreenButton(wxWindow *) { }