diff --git a/include/wx/thread.h b/include/wx/thread.h index ca3db2db72..24006b27bf 100644 --- a/include/wx/thread.h +++ b/include/wx/thread.h @@ -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); diff --git a/interface/wx/thread.h b/interface/wx/thread.h index 9c60ad0cf0..af0c7125ea 100644 --- a/interface/wx/thread.h +++ b/interface/wx/thread.h @@ -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); }; diff --git a/src/msw/thread.cpp b/src/msw/thread.cpp index 79acec9bfb..df0dace1da 100644 --- a/src/msw/thread.cpp +++ b/src/msw/thread.cpp @@ -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 diff --git a/src/unix/threadpsx.cpp b/src/unix/threadpsx.cpp index fdf2af59bb..7d59acc6f6 100644 --- a/src/unix/threadpsx.cpp +++ b/src/unix/threadpsx.cpp @@ -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__)