Add static SetNameForCurrent for setting name of non-wxThreads

Co-authored-by: PB <PBforDev@gmail.com>
This commit is contained in:
Lauri Nurmi
2021-11-02 19:53:29 +02:00
parent fc756d06a6
commit aace36b17f
4 changed files with 26 additions and 0 deletions

View File

@@ -596,6 +596,9 @@ public:
// Delete() instead (or leave the thread terminate by itself)
virtual ~wxThread();
// sets name to assist debugging
static bool SetNameForCurrent(const wxString &name);
protected:
// sets name to assist debugging
bool SetName(const wxString &name);

View File

@@ -1407,6 +1407,18 @@ protected:
@since 3.1.6
*/
bool SetName(const wxString &name);
/**
Sets an internal name for the current thread, which may be a wxThread
or any other kind of thread; e.g. an std::thread.
@return Either:
- @false: Failure or missing implementation for this OS.
- @true: Success or undetectable failure.
@since 3.1.6
*/
static bool SetNameForCurrent(const wxString &name);
};

View File

@@ -1194,6 +1194,12 @@ bool wxThread::SetName(const wxString &name)
wxCHECK_MSG(this == This(), false,
"SetName() must be called in the context of the thread to be named");
return SetNameForCurrent(name);
}
/* static */
bool wxThread::SetNameForCurrent(const wxString &name)
{
bool retval = wxSetThreadNameOnWindows10(name.wc_str());
// Even if the method above succeeded, we can set

View File

@@ -1685,7 +1685,12 @@ bool wxThread::SetName(const wxString &name)
wxCHECK_MSG(this == This(), false,
"SetName() must be called from inside the thread to be named");
return SetNameForCurrent(name);
}
/* static */
bool wxThread::SetNameForCurrent(const wxString &name)
{
// the API is nearly the same on different *nix, but not quite:
#if defined(__DARWIN__)