ThreadSchedule 3.0.0
Modern C++ thread management library
Loading...
Searching...
No Matches
composite_thread_registry.hpp
Go to the documentation of this file.
1#pragma once
2
8#include "../detail/try_result.hpp"
9#include "../thread_registry.hpp"
10
11#include <mutex>
12#include <vector>
13
15{
16
25{
26public:
30
32 void
34 {
35 if (!registry.has_native())
36 throw std::system_error(std::make_error_code(std::errc::operation_canceled),
37 "composite_thread_registry::attach: moved-from registry");
38 implementation_.attach(&registry.native());
39 }
40
42 [[nodiscard]] auto
43 snapshot() const -> result<std::vector<registered_thread>>
44 {
45 return ::threadschedule::detail::try_result(
46 [this]() -> result<std::vector<registered_thread>>
47 {
48 auto entries = implementation_.query().entries();
49 std::vector<registered_thread> result_entries;
50 result_entries.reserve(entries.size());
51 for (auto const& entry : entries)
52 result_entries.push_back({ detail::thread_id_access::make(static_cast<std::uint64_t>(entry.tid)),
53 entry.std_id, entry.name, entry.component, entry.alive });
54 return result_entries;
55 });
56 }
57
59 [[nodiscard]] auto
60 count() const -> std::size_t
61 {
62 return implementation_.count();
63 }
64
66 [[nodiscard]] auto
67 empty() const -> bool
68 {
69 return implementation_.empty();
70 }
71
72private:
74};
75
76} // namespace threadschedule::advanced
Non-owning facade that merges snapshots from multiple registries.
auto snapshot() const -> result< std::vector< registered_thread > >
Return one portable snapshot containing every attached registry.
void attach(thread_registry &registry)
Attach a registry without transferring ownership.
auto empty() const -> bool
Whether a newly merged snapshot contains no entries.
auto count() const -> std::size_t
Number of entries in a newly merged snapshot.
composite_thread_registry(composite_thread_registry const &)=delete
auto operator=(composite_thread_registry const &) -> composite_thread_registry &=delete
Registry for named/configurable threads.
static constexpr auto make(std::uint64_t value) -> thread_id
Definition thread_id.hpp:84
Snapshot entry returned by thread_registry::snapshot.