Database System 0.1.0
Advanced C++20 Database System with Multi-Backend Support
Loading...
Searching...
No Matches
thread_pool_adapter.h
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
5#pragma once
6
30#ifdef USE_THREAD_SYSTEM
31 // thread_system is available - use high-performance implementation
32 #include <kcenon/thread/core/thread_pool.h>
33 #include <kcenon/thread/core/typed_thread_pool.h>
34 #include <kcenon/thread/core/job.h>
35 #include <kcenon/thread/interfaces/thread_context.h>
36 // Note: thread_system v3.0 removes monitoring_interface.h
37 // Use common_system interfaces instead
38 #include <kcenon/common/interfaces/logger_interface.h>
39 #include <kcenon/common/interfaces/monitoring_interface.h>
40
41 namespace database::async {
46 using thread_pool_type = kcenon::thread::thread_pool;
47
52 template<typename JobType = kcenon::thread::job_types>
53 using typed_thread_pool_type = kcenon::thread::typed_thread_pool_t<JobType>;
54
58 using job_type = kcenon::thread::job;
59
63 template<typename JobType>
64 using typed_job_type = kcenon::thread::typed_job_t<JobType>;
65
69 using thread_context_type = kcenon::thread::thread_context;
70
75 using monitoring_interface_type = kcenon::common::interfaces::IMonitor;
76
81 using logger_interface_type = kcenon::common::interfaces::ILogger;
82
87 template<typename T>
88 using result_type = kcenon::common::Result<T>;
89
94 using result_void_type = kcenon::common::VoidResult;
95
99 constexpr bool using_thread_system = true;
100
101 } // namespace database::async
102
103#else
104 // Fallback to standard library threading
105 #include <thread>
106 #include <mutex>
107 #include <condition_variable>
108 #include <atomic>
109 #include <queue>
110 #include <functional>
111 #include <memory>
112 #include <variant>
113 #include <string>
114
115 namespace database::async {
129
130 // Forward declarations for fallback implementations
131 class fallback_thread_pool;
132 class fallback_job;
133
138 using thread_pool_type = fallback_thread_pool;
139
143 template<typename JobType>
144 using typed_thread_pool_type = fallback_thread_pool;
145
149 using job_type = fallback_job;
150
154 template<typename JobType>
155 using typed_job_type = fallback_job;
156
161
166
171
175 template<typename T>
177 public:
178 result_type(T&& value) : value_(std::forward<T>(value)), has_value_(true) {}
179 result_type(const T& value) : value_(value), has_value_(true) {}
180 result_type(const std::string& error) : error_(error), has_value_(false) {}
181
182 bool is_ok() const { return has_value_; }
183 bool has_error() const { return !has_value_; }
184
185 const T& value() const { return value_; }
186 T& value() { return value_; }
187
188 const std::string& error() const { return error_; }
189
190 private:
192 std::string error_;
194 };
195
200 public:
202 result_void_type(const std::string& error) : error_(error), has_error_(true) {}
203
204 bool is_ok() const { return !has_error_; }
205 bool has_error() const { return has_error_; }
206 const std::string& error() const { return error_; }
207
208 private:
209 std::string error_;
211 };
212
216 constexpr bool using_thread_system = false;
217
218 } // namespace database::async
219
220#endif // USE_THREAD_SYSTEM
Fallback thread context (empty implementation) Provides a no-op context when thread_system is not ava...
fallback_context(const fallback_context &)=default
fallback_context(fallback_context &&)=default
fallback_context & operator=(fallback_context &&)=default
fallback_context & operator=(const fallback_context &)=default
Fallback Result<T> implementation.
result_type(const std::string &error)
const std::string & error() const
const std::string & error() const
result_void_type(const std::string &error)
void logger_interface_type
Fallback logger interface (no-op)
fallback_thread_pool typed_thread_pool_type
Fallback typed thread pool (delegates to regular pool)
fallback_thread_pool thread_pool_type
Fallback thread pool using std::thread Provides basic functionality when thread_system is not availab...
void monitoring_interface_type
Fallback monitoring interface (no-op)
fallback_context thread_context_type
Fallback thread context (empty)
fallback_job typed_job_type
Fallback typed job.
constexpr bool using_thread_system
Compile-time flag indicating fallback mode.
fallback_job job_type
Fallback job type.