Thread System 0.3.1
High-performance C++20 thread pool with work stealing and DAG scheduling
Loading...
Searching...
No Matches
core.cppm
Go to the documentation of this file.
1// BSD 3-Clause License
2// Copyright (c) 2025, 🍀☀🌕🌥 🌊
3// See the LICENSE file in the project root for full license information.
4
23module;
24
25// Standard library includes needed before module declaration
26#include <atomic>
27#include <chrono>
28#include <condition_variable>
29#include <deque>
30#include <functional>
31#include <future>
32#include <memory>
33#include <mutex>
34#include <optional>
35#include <string>
36#include <string_view>
37#include <thread>
38#include <tuple>
39#include <type_traits>
40#include <vector>
41
42// Include existing headers in the global module fragment
79
80export module kcenon.thread:core;
81
82import kcenon.common;
83
84// ============================================================================
85// Core Configuration and Error Handling
86// ============================================================================
87
88export namespace kcenon::thread {
89
90// Re-export configuration types
91using ::kcenon::thread::thread_config;
92
93// Re-export error handling types
94using ::kcenon::thread::error_code;
95using ::kcenon::thread::make_error;
96using ::kcenon::thread::is_retriable;
97
98// Re-export cancellation types
99using ::kcenon::thread::cancellation_token;
100using ::kcenon::thread::cancellation_token_source;
101
102// Re-export synchronization primitives
103using ::kcenon::thread::sync::spin_lock;
104using ::kcenon::thread::sync::scoped_spin_lock;
105
106} // namespace kcenon::thread
107
108// ============================================================================
109// Memory Management (Hazard Pointers)
110// ============================================================================
111
112export namespace kcenon::thread {
113
114// Re-export hazard pointer utilities
115using ::kcenon::thread::hazard_pointer;
116using ::kcenon::thread::safe_hazard_pointer;
117using ::kcenon::thread::atomic_shared_ptr;
118
119} // namespace kcenon::thread
120
121// ============================================================================
122// Job Classes
123// ============================================================================
124
125export namespace kcenon::thread {
126
127// Re-export job types
128using ::kcenon::thread::job;
129using ::kcenon::thread::callback_job;
130using ::kcenon::thread::job_priority;
131
132} // namespace kcenon::thread
133
134// ============================================================================
135// Thread Classes
136// ============================================================================
137
138export namespace kcenon::thread {
139
140// Re-export thread types
141using ::kcenon::thread::thread_base;
142using ::kcenon::thread::thread_worker;
143using ::kcenon::thread::thread_pool;
144
145// Re-export thread conditions
146using ::kcenon::thread::start_condition;
147using ::kcenon::thread::stop_condition;
148
149// Re-export worker policy
150using ::kcenon::thread::worker_policy;
151using ::kcenon::thread::steal_policy;
152
153// Re-export pool traits
154using ::kcenon::thread::pool_traits;
155using ::kcenon::thread::is_pool_like;
156
157} // namespace kcenon::thread
158
159// ============================================================================
160// Future Extensions
161// ============================================================================
162
163export namespace kcenon::thread {
164
165// Re-export future utilities
166using ::kcenon::thread::when_all;
167using ::kcenon::thread::when_any;
168using ::kcenon::thread::future_status_result;
169
170} // namespace kcenon::thread
171
172// ============================================================================
173// Configuration and Services
174// ============================================================================
175
176export namespace kcenon::thread {
177
178// Re-export configuration manager
179using ::kcenon::thread::configuration_manager;
180using ::kcenon::thread::service_registry;
181
182// Re-export log level
183using ::kcenon::thread::log_level;
184using ::kcenon::thread::thread_logger;
185
186// Re-export event bus
187using ::kcenon::thread::event_bus;
188
189} // namespace kcenon::thread
190
191// ============================================================================
192// Interfaces
193// ============================================================================
194
195export namespace kcenon::thread {
196
197// Re-export interfaces
198using ::kcenon::thread::thread_context;
199using ::kcenon::thread::scheduler_interface;
200using ::kcenon::thread::error_handler;
201using ::kcenon::thread::crash_handler;
202using ::kcenon::thread::service_container;
203
204} // namespace kcenon::thread
205
206// ============================================================================
207// Metrics
208// ============================================================================
209
210export namespace kcenon::thread::metrics {
211
212// Re-export metrics types
213using ::kcenon::thread::metrics::ThreadPoolMetrics;
214using ::kcenon::thread::metrics::WorkerMetrics;
215
216} // namespace kcenon::thread::metrics
217
218// ============================================================================
219// Concepts
220// ============================================================================
221
222export namespace kcenon::thread::concepts {
223
224// Re-export concepts (if available)
225#if __cpp_concepts >= 201907L
226using ::kcenon::thread::concepts::Executable;
227using ::kcenon::thread::concepts::JobLike;
228using ::kcenon::thread::concepts::PoolLike;
229#endif
230
231} // namespace kcenon::thread::concepts
232
233// ============================================================================
234// Utilities
235// ============================================================================
236
238
239// Re-export utility types
240using ::utility_module::convert_string;
241
242} // namespace kcenon::thread::utility_module
Thread-safe atomic shared_ptr wrapper with explicit memory ordering.
C++17-compatible atomic wait/notify implementation.
Specialized job class that encapsulates user-defined callbacks.
Backward-compatible type aliases for renamed thread system components.
Runtime configuration management with typed key-value storage.
Central configuration for thread_pool module.
Job priority levels and type definitions for type-based scheduling.
Core thread pool implementation with work stealing and auto-scaling.
Crash safety levels and handler interface for thread failure recovery.
Error handler interface for customizable error handling strategies.
Type-safe publish-subscribe event bus for thread system events.
Forward declarations for thread system types.
Future and promise utilities for thread pool.
Hazard pointer implementation for lock-free memory reclamation.
Implementation of a cancellation token for cooperative cancellation.
Error codes and utilities for the thread system.
RAII-based synchronization primitives including scoped lock with timeout.
String encoding conversion, Base64 encoding/decoding utilities.
Generic formatter for enum types using user-provided converter functors.
Base job class for schedulable work units in the thread system.
Logging severity levels for the thread system.
Core threading foundation of the thread system library.
Definition thread_impl.h:17
CPU architecture and platform detection utilities.
Type traits and metaprogramming utilities for thread pool.
Thread-local hazard pointer with explicit memory ordering for safe reclamation.
Abstract scheduler interface for queuing and retrieving jobs.
Service container for dependency injection within the thread system.
Lightweight service registry for dependency lookup within the thread system.
C++17-compatible synchronization primitives with C++20 fallback.
Foundational worker thread class with lifecycle management.
C++20 Concepts for thread_system.
Enumeration of thread lifecycle states (starting, running, stopping, stopped).
Context object providing access to optional thread system services.
Internal logging interface for the thread system.
Lightweight metrics container shared between thread_pool and workers.
Specialized worker thread that processes jobs from a job_queue.
Worker behavior policies and configuration.