12#ifndef NUMAPP_THREAD_HPP_
13#define NUMAPP_THREAD_HPP_
18#include <system_error>
55void SetThreadName(std::string_view thread_name, std::error_code& ec) noexcept;
79[[nodiscard]] std::
string GetThreadName(std::error_code& ec) noexcept;
136template <class Func, class... Args>
137[[nodiscard]] std::thread
MakeThread(std::string_view thread_name,
141 auto trampoline = detail::ThreadInitializer(thread_name, policies);
142 auto thr = std::thread(
143 [&, func = std::bind(std::forward<Func>(func), std::forward<Args>(args)...)]()
mutable {
144 if (trampoline.Initialize() != std::error_code()) {
152 auto result = trampoline.Wait();
156 throw std::system_error(result);
167template <
class Func,
class... Args>
168[[nodiscard]] std::thread
170 return MakeThread(std::string_view(thread_name),
172 std::forward<Func>(func),
173 std::forward<Args>(args)...);
176#ifdef __cpp_lib_jthread
187template <
class Func,
class... Args>
188[[nodiscard]] std::jthread MakeJthread(std::string_view thread_name,
189 NumaPolicies
const& policies,
192 constexpr bool wants_stop_token = std::is_invocable_v<Func, std::stop_token
const&, Args...>;
194 auto trampoline = detail::ThreadInitializer(thread_name, policies);
195 auto thr = std::jthread([&,
196 func = detail::TokenPrepender<wants_stop_token>::Bind(
197 std::forward<Func>(func), std::forward<Args>(args)...)](
198 std::stop_token
const& token)
mutable {
199 if (trampoline.Initialize() != std::error_code()) {
204 if constexpr (wants_stop_token) {
211 auto result = trampoline.Wait();
215 throw std::system_error(result);
Combines the the available NUMA policy types in one object.
pid_t GetThreadId() noexcept
Query the thread id "TID" of the current thread.
std::thread MakeThread(std::string_view thread_name, NumaPolicies const &policies, Func &&func, Args &&... args)
Primary overload accepting string-view for thread_name.
void SetThreadName(std::string_view thread_name, std::error_code &ec) noexcept
Set thread name for current thread.
std::string GetThreadName()
Get name of current thread (throwing version).
Contains declarations for NumaPolicies.