18#if defined(__cpp_lib_jthread) && __cpp_lib_jthread >= 201911L
34#if defined(__cpp_lib_jthread) && __cpp_lib_jthread >= 201911L
38 template <
typename Function>
40 with_impl(Function&& function)
42 return std::visit(std::forward<Function>(function), impl_);
45 template <
typename Function>
47 with_impl(Function&& function)
const
49 return std::visit(std::forward<Function>(function), impl_);
52 std::variant<std_thread_view, jthread_view> impl_;
54 template <
typename Function>
56 with_impl(Function&& function)
58 return std::forward<Function>(function)(impl_);
61 template <
typename Function>
63 with_impl(Function&& function)
const
65 return std::forward<Function>(function)(impl_);
72#if defined(__cpp_lib_jthread) && __cpp_lib_jthread >= 201911L
80 : impl_(std::in_place_type<std_thread_view>, value)
85 : impl_(std::in_place_type<std_thread_view>, value.impl_.get(), value.impl_.native_id())
95 : impl_(std::in_place_type<jthread_view>, value)
100 : impl_(std::in_place_type<jthread_view>, value.impl_, value.native_id_)
113 : impl_(value.impl_.get(), value.impl_.native_id())
122 return with_impl([](
auto const& value) {
return value.joinable(); });
129 return with_impl([](
auto const& value) {
return value.get_id(); });
157 return with_impl([](
auto const& value)
165 return with_impl([](
auto const& value)
173 return with_impl([&](
auto& value) {
return value.set_name(name); });
180 return with_impl([](
auto const& value) {
return value.get_name(); });
194 return with_impl([](
auto const& value)
Polymorphic base providing common thread management operations.
Non-owning view over an externally managed std::thread.
Strongly-typed nice value in the POSIX range $[-20, 19]$.
Portable thread configuration bundle.
auto set_priority(priority_level level) -> result< void >
Set portable priority preset on viewed thread.
auto joinable() const noexcept -> bool
Return whether viewed thread is joinable.
auto get_priority() const -> result< priority_level >
Query portable priority preset of viewed thread.
thread_view(std::thread &value THREADSCHEDULE_LIFETIMEBOUND) noexcept
Create a view over an existing std::thread.
auto set_nice(nice_value value) -> result< void >
Set explicit nice value on viewed thread.
auto get_id() const noexcept -> std::thread::id
Return std::thread id of viewed thread.
auto get_name() const -> result< std::string >
Query viewed thread name.
auto configure(thread_config const &config THREADSCHEDULE_NOESCAPE) -> result< void >
Apply full portable configuration to viewed thread.
auto get_affinity() const -> result< thread_affinity >
Query viewed thread CPU affinity.
auto get_nice() const -> result< nice_value >
Query nice value of viewed thread.
thread_view(thread &value THREADSCHEDULE_LIFETIMEBOUND) noexcept
Create a view over a threadschedule::thread.
auto set_affinity(thread_affinity const &affinity THREADSCHEDULE_NOESCAPE) -> result< void >
Set viewed thread CPU affinity.
auto set_name(std::string const &name THREADSCHEDULE_NOESCAPE) -> result< void >
Set viewed thread name.
Owning thread wrapper with result-based lifecycle/configuration API.
Owning std::jthread wrapper with portable configuration helpers.
Optional compiler diagnostics for borrowed references and pointers.
#define THREADSCHEDULE_LIFETIMEBOUND
#define THREADSCHEDULE_POINTER
#define THREADSCHEDULE_NOESCAPE
auto set_nice(Control &control, nice_value value) -> result< void >
auto get_affinity(result< native_thread_affinity > affinity) -> result< thread_affinity >
auto set_priority(Control &control, priority_level level) -> result< void >
auto get_priority(result< int > value) -> result< priority_level >
auto get_nice(result< int > value) -> result< nice_value >
auto configure(Control &control, thread_config const &config) -> result< void >
auto set_affinity(Control &control, thread_affinity const &affinity) -> result< void >
priority_level
Portable non-realtime priority levels.
expected< T, std::error_code > result
Standard result type used by public APIs.
Owning std::thread wrapper with portable configuration helpers.
C++17 thread wrappers and non-owning views.
Portable thread startup and runtime configuration.