ThreadSchedule 2.0.0
Modern C++ thread management library
Loading...
Searching...
No Matches
thread_registry.hpp File Reference

Process-wide thread registry, control blocks, and composite registry. More...

#include "expected.hpp"
#include "scheduler_policy.hpp"
#include "thread_wrapper.hpp"
#include <functional>
#include <memory>
#include <mutex>
#include <optional>
#include <shared_mutex>
#include <string>
#include <thread>
#include <tuple>
#include <unordered_map>
#include <utility>
#include <vector>
#include <pthread.h>
#include <sched.h>
#include <sys/types.h>
Include dependency graph for thread_registry.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  threadschedule::RegisteredThreadInfo
 Snapshot of metadata for a single registered thread. More...
class  threadschedule::ThreadControlBlock
 Per-thread control handle for OS-level scheduling operations. More...
class  threadschedule::detail::QueryFacadeMixin< Derived >
 CRTP mixin that provides functional-style query facade methods. More...
class  threadschedule::ThreadRegistry
 Central registry of threads indexed by OS-level thread ID (Tid). More...
class  threadschedule::ThreadRegistry::QueryView
 Lazy, functional-style query/filter view over a snapshot of registered threads. More...
class  threadschedule::CompositeThreadRegistry
 Aggregates multiple ThreadRegistry instances into a single queryable view. More...
class  threadschedule::AutoRegisterCurrentThread
 RAII guard that registers the current thread on construction and unregisters it on destruction. More...

Namespaces

namespace  threadschedule
namespace  threadschedule::detail

Macros

#define THREADSCHEDULE_API

Typedefs

using threadschedule::Tid = pid_t

Enumerations

enum class  threadschedule::BuildMode : std::uint8_t { threadschedule::HEADER_ONLY , threadschedule::RUNTIME }
 Indicates whether the library was compiled in header-only or runtime (shared library) mode. More...

Functions

auto threadschedule::build_mode () -> BuildMode
 Returns the build mode detected at compile time (header-only variant).
auto threadschedule::build_mode_string () -> char const *
 Returns a human-readable C string describing the active build mode.
auto threadschedule::cgroup_attach_tid (std::string const &cgroupDir, Tid tid) -> expected< void, std::error_code >
 Attaches a thread to a Linux cgroup by writing its TID to the appropriate control file.
Global registry access

These free functions provide access to a process-wide ThreadRegistry singleton and allow injecting a custom instance.

Header-only mode (default)
Both registry() and set_external_registry() are inline functions that use function-local statics (Meyer's singleton pattern). registry() returns the externally set registry if one was provided via set_external_registry(), otherwise a function-local static instance.
Runtime / shared-library mode (THREADSCHEDULE_RUNTIME defined)
The functions are declared here but defined in runtime_registry.cpp. This ensures a single registry instance across shared-library boundaries even when the header is included from multiple translation units in different DSOs.
auto threadschedule::registry () -> ThreadRegistry &
 Returns a reference to the process-wide ThreadRegistry.
void threadschedule::set_external_registry (ThreadRegistry *reg)
 Injects a custom ThreadRegistry as the global singleton.

Variables

constexpr bool threadschedule::is_runtime_build = false
 true when compiled with THREADSCHEDULE_RUNTIME.

Detailed Description

Process-wide thread registry, control blocks, and composite registry.

Definition in file thread_registry.hpp.

Macro Definition Documentation

◆ THREADSCHEDULE_API

#define THREADSCHEDULE_API

Definition at line 42 of file thread_registry.hpp.