ThreadSchedule 3.0.0
Modern C++ thread management library
Loading...
Searching...
No Matches
registration_guard_backend.hpp
Go to the documentation of this file.
1#pragma once
2
8
9#include <memory>
10#include <string>
11#include <utility>
12
14{
17{
18public:
19 explicit registration_guard_backend(std::string const& name = std::string(),
20 std::string const& component = std::string())
21 : registry_(&runtime_registry())
22 {
24 tid_ = block->tid();
25 (void)block->set_name(name);
26 active_ = registry_->register_guard(block, name, component);
27 control_ = std::move(block);
28 }
29
30 explicit registration_guard_backend(thread_registry_backend& reg, std::string const& name = std::string(),
31 std::string const& component = std::string())
32 : registry_(&reg)
33 {
35 tid_ = block->tid();
36 (void)block->set_name(name);
37 active_ = registry_->register_guard(block, name, component);
38 control_ = std::move(block);
39 }
41 {
42 if (active_)
43 registry_->unregister_thread(tid_, control_.get());
44 }
48 : active_(other.active_), registry_(other.registry_), tid_(other.tid_), control_(std::move(other.control_))
49 {
50 other.active_ = false;
51 other.registry_ = nullptr;
52 other.tid_ = {};
53 }
54 auto
56 {
57 if (this != &other)
58 {
59 if (active_)
60 registry_->unregister_thread(tid_, control_.get());
61 active_ = other.active_;
62 registry_ = other.registry_;
63 tid_ = other.tid_;
64 control_ = std::move(other.control_);
65 other.active_ = false;
66 other.registry_ = nullptr;
67 other.tid_ = {};
68 }
69 return *this;
70 }
71
72private:
73 bool active_{ false };
74 thread_registry_backend* registry_{ nullptr };
75 native_thread_id tid_{};
76 std::shared_ptr<thread_control_block> control_;
77};
78
79} // namespace threadschedule::detail
Internal movable RAII guard for worker registration.
auto operator=(registration_guard_backend const &) -> registration_guard_backend &=delete
registration_guard_backend(thread_registry_backend &reg, std::string const &name=std::string(), std::string const &component=std::string())
registration_guard_backend(registration_guard_backend &&other) noexcept
registration_guard_backend(std::string const &name=std::string(), std::string const &component=std::string())
auto operator=(registration_guard_backend &&other) noexcept -> registration_guard_backend &
registration_guard_backend(registration_guard_backend const &)=delete
static auto create_for_current_thread() -> std::shared_ptr< thread_control_block >
Central registry of threads indexed by OS-level thread ID (native_thread_id).
Aggregates multiple thread_registry_backend instances into a single queryable view.
@ other
Standard round-robin time-sharing.
auto runtime_registry() -> thread_registry_backend &
Registry storage, mutation, snapshots, and private runtime hooks.