NUMA++ 0.10.0
Loading...
Searching...
No Matches
thread.hpp
Go to the documentation of this file.
1/**
2 * @file
3 * @copyright
4 * (c) Copyright ESO 2024
5 * All Rights Reserved
6 * ESO (eso.org) is an Intergovernmental Organisation, and therefore special legal conditions apply.
7 */
8#ifndef NUMAPP_DETAIL_THREAD_HPP
9#define NUMAPP_DETAIL_THREAD_HPP
10
11#include <condition_variable>
12#include <functional>
13#include <mutex>
14
16
17namespace numapp::detail {
18
19template <bool>
20struct TokenPrepender;
21
22template <>
23struct TokenPrepender<true> {
24 template <class Func, class... Args>
25 static auto Bind(Func&& func, Args&&... args) {
26 return std::bind(std::forward<Func>(func), std::placeholders::_1, std::forward<Args>(args)...);
27 }
28};
29
30template <>
31struct TokenPrepender<false> {
32 template <class Func, class... Args>
33 static auto Bind(Func&& func, Args&&... args) {
34 return std::bind(std::forward<Func>(func), std::forward<Args>(args)...);
35 }
36};
37
38class ThreadInitializer {
39public:
40 ThreadInitializer(std::string_view name, NumaPolicies const& policies);
41
42 /**
43 * Wait for Initialize() to complete.
44 */
45 auto Wait() -> std::system_error const&;
46
47 /**
48 * Setup calling thread according to provided policies.
49 */
50 auto Initialize() -> std::error_code;
51
52private:
53 std::string_view m_name;
54 NumaPolicies const& m_policies;
55
56 std::optional<std::system_error> m_result;
57 std::condition_variable m_cond;
58 std::mutex m_mtx;
59 /**
60 * Lock used by thread owning ThreadInitializer which invokes Wait()
61 */
62 std::unique_lock<std::mutex> m_lck;
63};
64
65} // namespace numapp::detail
66
67#endif // NUMAPP_DETAIL_THREAD_HPP
Contains declarations for NumaPolicies.