ThreadSchedule 4.1.0
Modern C++ thread management library
Loading...
Searching...
No Matches
thread_config.hpp
Go to the documentation of this file.
1#pragma once
2
7
8#include "detail/lifetime.hpp"
9#include "scheduling.hpp"
10#include "thread_affinity.hpp"
11
12#include <optional>
13#include <string>
14#include <utility>
15
16namespace threadschedule
17{
18
26{
27public:
28 thread_config() = default;
29
34 auto
35 set_name(std::string name) -> thread_config&
36 {
37 name_ = std::move(name);
38 return *this;
39 }
40
42 auto
44 {
45 name_.reset();
46 return *this;
47 }
48
53 auto
55 {
56 scheduling_ = scheduling;
57 return *this;
58 }
59
61 auto
63 {
64 scheduling_.reset();
65 return *this;
66 }
67
72 auto
74 {
75 affinity_ = std::move(affinity);
76 return *this;
77 }
78
80 auto
82 {
83 affinity_.reset();
84 return *this;
85 }
86
88 [[nodiscard]] auto
89 get_name() const noexcept THREADSCHEDULE_LIFETIMEBOUND -> std::optional<std::string> const&
90 {
91 return name_;
92 }
93
94 [[nodiscard]] auto
96 {
97 return scheduling_;
98 }
99
100 [[nodiscard]] auto
101 get_affinity() const noexcept THREADSCHEDULE_LIFETIMEBOUND -> std::optional<thread_affinity> const&
102 {
103 return affinity_;
104 }
105
106 [[nodiscard]] auto
107 empty() const noexcept -> bool
108 {
109 return !name_ && !scheduling_ && !affinity_;
110 }
111
112private:
113 std::optional<std::string> name_;
114 std::optional<scheduling_config> scheduling_;
115 std::optional<thread_affinity> affinity_;
116};
117
118} // namespace threadschedule
Immutable scheduling request passed to thread creation/configuration APIs.
auto clear_name() noexcept -> thread_config &
Clear previously configured thread name.
auto set_name(std::string name) -> thread_config &
Set thread name.
auto clear_affinity() noexcept -> thread_config &
Clear previously configured CPU affinity.
auto empty() const noexcept -> bool
Return whether no settings are currently configured.
auto get_name() const noexcept THREADSCHEDULE_LIFETIMEBOUND -> std::optional< std::string > const &
Return configured thread name if present.
auto set_affinity(thread_affinity affinity) -> thread_config &
Set CPU affinity mask.
auto get_scheduling() const noexcept THREADSCHEDULE_LIFETIMEBOUND -> std::optional< scheduling_config > const &
Return configured scheduling request if present.
auto clear_scheduling() noexcept -> thread_config &
Clear previously configured scheduling request.
auto set_scheduling(scheduling_config scheduling) noexcept -> thread_config &
Set scheduling configuration.
auto get_affinity() const noexcept THREADSCHEDULE_LIFETIMEBOUND -> std::optional< thread_affinity > const &
Return configured affinity set if present.
Optional compiler diagnostics for borrowed references and pointers.
#define THREADSCHEDULE_LIFETIMEBOUND
Definition lifetime.hpp:28
Portable scheduling intents and priority configuration.
Portable normalized CPU-affinity value type.