ThreadSchedule 3.0.0
Modern C++ thread management library
Loading...
Searching...
No Matches
native_thread.hpp
Go to the documentation of this file.
1#pragma once
2
8#include "../jthread.hpp"
9#include "../thread.hpp"
10#include "../thread_id.hpp"
11
12#include <cstdint>
13#include <limits>
14
15#ifndef _WIN32
16# include <sys/types.h>
17#endif
18
20{
21
23{
24 [[nodiscard]] static auto
25 get(thread& value) -> std::thread::native_handle_type
26 {
27 return value.impl_.native_handle();
28 }
29
30#if defined(__cpp_lib_jthread) && __cpp_lib_jthread >= 201911L
31 [[nodiscard]] static auto
32 get(jthread& value) -> std::jthread::native_handle_type
33 {
34 return value.impl_.native_handle();
35 }
36#endif
37};
38
39} // namespace threadschedule::detail
40
42{
43
44[[nodiscard]] inline auto
45native_handle(thread& value) -> std::thread::native_handle_type
46{
47 return ::threadschedule::detail::native_thread_access::get(value);
48}
49
50#if defined(__cpp_lib_jthread) && __cpp_lib_jthread >= 201911L
51[[nodiscard]] inline auto
52native_handle(jthread& value) -> std::jthread::native_handle_type
53{
54 return ::threadschedule::detail::native_thread_access::get(value);
55}
56#endif
57
58#ifdef _WIN32
59using native_thread_id = unsigned long;
60#else
61using native_thread_id = pid_t;
62#endif
63
64[[nodiscard]] inline auto
66{
68 auto const maximum = static_cast<std::uint64_t>((std::numeric_limits<native_thread_id>::max)());
69 if (value > maximum)
70 return unexpected(std::make_error_code(std::errc::invalid_argument));
71 return static_cast<native_thread_id>(value);
72}
73
74} // namespace threadschedule::advanced
Owning thread wrapper with result-based lifecycle/configuration API.
Definition thread.hpp:29
auto native_handle(thread &value) -> std::thread::native_handle_type
auto native_id(thread_id id) noexcept -> result< native_thread_id >
Aggregates multiple thread_registry_backend instances into a single queryable view.
static auto get(thread &value) -> std::thread::native_handle_type
static constexpr auto value(thread_id id) noexcept -> std::uint64_t
Definition thread_id.hpp:91