diff --git a/Utilities/Thread.h b/Utilities/Thread.h index f3cf11a9cb..d9ad7f28e8 100644 --- a/Utilities/Thread.h +++ b/Utilities/Thread.h @@ -102,6 +102,12 @@ struct thread_on_wait : std::bool_constant {}; template struct thread_on_wait&>().on_wait())> : std::bool_constant {}; +template +struct thread_thread_name : std::bool_constant {}; + +template +struct thread_thread_name::thread_name)>> : std::bool_constant {}; + // Thread base class class thread_base { @@ -380,6 +386,18 @@ class named_thread final : public Context, result_storage_t, thread_bas return thread::finalize(0); } + static decltype(auto) get_default_thread_name() + { + if constexpr (thread_thread_name()) + { + return Context::thread_name; + } + else + { + return "Unnamed Thread"; + } + } + // Detached thread constructor named_thread(thread_state s, std::string_view name, Context&& f) : Context(std::forward(f)) @@ -392,6 +410,14 @@ class named_thread final : public Context, result_storage_t, thread_bas friend class thread_ctrl; public: + // Default constructor + named_thread() + : Context() + , thread(get_default_thread_name()) + { + thread::start(&named_thread::entry_point); + } + // Normal forwarding constructor template >> named_thread(std::string_view name, Args&&... args)