mirror of
https://github.com/RPCS3/rpcs3.git
synced 2024-11-22 02:32:36 +01:00
named_thread: use concepts, improve constructors
Better default thread name detection.
This commit is contained in:
parent
67649d7976
commit
61450335a5
@ -42,7 +42,7 @@ class named_thread;
|
||||
|
||||
class thread_base;
|
||||
|
||||
template <typename Ctx, typename X = void, typename... Args>
|
||||
template <typename Ctx, typename... Args>
|
||||
struct result_storage
|
||||
{
|
||||
static constexpr bool empty = true;
|
||||
@ -50,8 +50,8 @@ struct result_storage
|
||||
using type = void;
|
||||
};
|
||||
|
||||
template <typename Ctx, typename... Args>
|
||||
struct result_storage<Ctx, std::enable_if_t<!std::is_void_v<std::invoke_result_t<Ctx, Args&&...>>>, Args...>
|
||||
template <typename Ctx, typename... Args> requires (!std::is_void_v<std::invoke_result_t<Ctx, Args&&...>>)
|
||||
struct result_storage<Ctx, Args...>
|
||||
{
|
||||
using T = std::invoke_result_t<Ctx, Args&&...>;
|
||||
|
||||
@ -84,6 +84,12 @@ struct result_storage<Ctx, std::enable_if_t<!std::is_void_v<std::invoke_result_t
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
concept NamedThreadName = requires (T& t)
|
||||
{
|
||||
std::string_view(t.thread_name);
|
||||
};
|
||||
|
||||
// Base class for task queue (linked list)
|
||||
class thread_future
|
||||
{
|
||||
@ -110,12 +116,6 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T, typename = void>
|
||||
struct thread_thread_name : std::bool_constant<false> {};
|
||||
|
||||
template <typename T>
|
||||
struct thread_thread_name<T, std::void_t<decltype(named_thread<T>::thread_name)>> : std::bool_constant<true> {};
|
||||
|
||||
// Thread base class
|
||||
class thread_base
|
||||
{
|
||||
@ -479,16 +479,17 @@ class named_thread final : public Context, result_storage<Context>, thread_base
|
||||
friend class thread_ctrl;
|
||||
|
||||
public:
|
||||
// Default constructor
|
||||
named_thread() requires (std::is_default_constructible_v<Context>) && (thread_thread_name<Context>::value)
|
||||
: Context()
|
||||
// Forwarding constructor with default name (also potentially the default constructor)
|
||||
template <typename... Args> requires (std::is_constructible_v<Context, Args&&...>) && (NamedThreadName<Context>)
|
||||
named_thread(Args&&... args)
|
||||
: Context(std::forward<Args>(args)...)
|
||||
, thread(trampoline, Context::thread_name)
|
||||
{
|
||||
thread::start();
|
||||
}
|
||||
|
||||
// Normal forwarding constructor
|
||||
template <typename... Args, typename = std::enable_if_t<std::is_constructible_v<Context, Args&&...>>>
|
||||
template <typename... Args> requires (std::is_constructible_v<Context, Args&&...>) && (!NamedThreadName<Context>)
|
||||
named_thread(std::string_view name, Args&&... args)
|
||||
: Context(std::forward<Args>(args)...)
|
||||
, thread(trampoline, name)
|
||||
|
Loading…
Reference in New Issue
Block a user