17#if defined(__cpp_lib_jthread) && __cpp_lib_jthread >= 201911L
31#if defined(__cpp_lib_jthread) && __cpp_lib_jthread >= 201911L
35 template <
typename Function>
37 with_impl(Function&& function)
39 return std::visit(std::forward<Function>(function), impl_);
42 template <
typename Function>
44 with_impl(Function&& function)
const
46 return std::visit(std::forward<Function>(function), impl_);
49 std::variant<std_thread_view, jthread_view> impl_;
51 template <
typename Function>
53 with_impl(Function&& function)
55 return std::forward<Function>(function)(impl_);
58 template <
typename Function>
60 with_impl(Function&& function)
const
62 return std::forward<Function>(function)(impl_);
69#if defined(__cpp_lib_jthread) && __cpp_lib_jthread >= 201911L
76 explicit thread_view(std::thread& value) noexcept : impl_(std::in_place_type<std_thread_view>, value) {}
79 : impl_(std::in_place_type<std_thread_view>, value.impl_.get(), value.impl_.native_id())
88 explicit thread_view(std::jthread& value) noexcept : impl_(std::in_place_type<jthread_view>, value) {}
90 explicit thread_view(jthread& value) noexcept : impl_(std::in_place_type<jthread_view>, value.impl_, value.native_id_)
100 explicit thread_view(std::thread& value) noexcept : impl_(value) {}
102 explicit thread_view(
thread& value) noexcept : impl_(value.impl_.get(), value.impl_.native_id()) {}
109 return with_impl([](
auto const& value) {
return value.joinable(); });
116 return with_impl([](
auto const& value) {
return value.get_id(); });
123 return with_impl([&](
auto& value) {
return detail::portable_thread_control::configure(value, config); });
130 return with_impl([&](
auto& value) {
return detail::portable_thread_control::set_priority(value, level); });
137 return with_impl([&](
auto& impl) {
return detail::portable_thread_control::set_nice(impl, value); });
144 return with_impl([](
auto const& value)
145 {
return detail::portable_thread_control::get_priority(value.get_nice_value()); });
152 return with_impl([](
auto const& value)
153 {
return detail::portable_thread_control::get_nice(value.get_nice_value()); });
160 return with_impl([&](
auto& value) {
return value.set_name(name); });
167 return with_impl([](
auto const& value) {
return value.get_name(); });
174 return with_impl([&](
auto& value) {
return detail::portable_thread_control::set_affinity(value, affinity); });
181 return with_impl([](
auto const& value)
182 {
return detail::portable_thread_control::get_affinity(value.get_affinity()); });
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.
Non-owning view over a running thread or jthread.
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.
auto set_nice(nice_value value) -> result< void >
Set explicit nice value on viewed thread.
auto set_name(std::string const &name) -> result< void >
Set viewed thread name.
thread_view(std::thread &value) noexcept
Create a view over an existing std::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 set_affinity(thread_affinity const &affinity) -> result< void >
Set viewed thread CPU affinity.
thread_view(thread &value) noexcept
Create a view over a threadschedule::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.
auto configure(thread_config const &config) -> result< void >
Apply full portable configuration to viewed thread.
Owning thread wrapper with result-based lifecycle/configuration API.
Owning std::jthread wrapper with portable configuration helpers.
priority_level
Portable non-realtime priority levels.
Owning std::thread wrapper with portable configuration helpers.
C++17 thread wrappers and non-owning views.
Portable thread startup and runtime configuration.