Logger System 0.1.3
High-performance C++20 thread-safe logging system with asynchronous capabilities
Loading...
Searching...
No Matches
thread_system_integration.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
35#pragma once
36
38
39#include <atomic>
40#include <functional>
41#include <memory>
42#include <mutex>
43#include <string>
44
45// Conditional include for thread_system
46// LOGGER_HAS_THREAD_SYSTEM is defined by CMake when thread_system is available
47#ifdef LOGGER_HAS_THREAD_SYSTEM
48#include <kcenon/thread/core/thread_pool.h>
49#endif
50
52
69
84};
85
86#ifdef LOGGER_HAS_THREAD_SYSTEM
87
125class LOGGER_SYSTEM_API thread_system_integration {
126public:
146 static void enable(std::shared_ptr<kcenon::thread::thread_pool> pool = nullptr);
147
157 static void disable();
158
165 [[nodiscard]] static bool is_enabled() noexcept;
166
173 [[nodiscard]] static async_backend_type get_backend() noexcept;
174
187 static void set_thread_pool(std::shared_ptr<kcenon::thread::thread_pool> pool);
188
195 [[nodiscard]] static std::shared_ptr<kcenon::thread::thread_pool> get_thread_pool() noexcept;
196
217 [[nodiscard]] static bool submit_task(std::function<void()> task);
218
226 [[nodiscard]] static std::string get_backend_name() noexcept;
227
228private:
229 // Prevent instantiation - all methods are static
230 thread_system_integration() = delete;
231 ~thread_system_integration() = delete;
232 thread_system_integration(const thread_system_integration&) = delete;
233 thread_system_integration& operator=(const thread_system_integration&) = delete;
234
235 // Internal state
236 static std::atomic<async_backend_type> current_backend_;
237 static std::shared_ptr<kcenon::thread::thread_pool> thread_pool_;
238 static std::mutex pool_mutex_;
239
244 static std::shared_ptr<kcenon::thread::thread_pool> create_default_pool();
245};
246
247#else // !LOGGER_HAS_THREAD_SYSTEM
248
261public:
265 static void enable() noexcept {
266 // No-op: thread_system not available
267 }
268
272 static void disable() noexcept {
273 // No-op: thread_system not available
274 }
275
280 [[nodiscard]] static constexpr bool is_enabled() noexcept {
281 return false;
282 }
283
288 [[nodiscard]] static constexpr async_backend_type get_backend() noexcept {
289 return async_backend_type::standalone;
290 }
291
297 [[nodiscard]] static bool submit_task(std::function<void()> /*task*/) noexcept {
298 return false;
299 }
300
305 [[nodiscard]] static std::string get_backend_name() noexcept {
306 return "standalone";
307 }
308
309private:
314};
315
316#endif // LOGGER_HAS_THREAD_SYSTEM
317
333[[nodiscard]] constexpr bool has_thread_system_support() noexcept {
334#ifdef LOGGER_HAS_THREAD_SYSTEM
335 return true;
336#else
337 return false;
338#endif
339}
340
341} // namespace kcenon::logger::integration
Stub implementation when thread_system is not available.
static std::string get_backend_name() noexcept
Always returns "standalone" when thread_system is not available.
static void disable() noexcept
No-op when thread_system is not available.
static void enable() noexcept
No-op when thread_system is not available.
thread_system_integration & operator=(const thread_system_integration &)=delete
static constexpr async_backend_type get_backend() noexcept
Always returns standalone when thread_system is not available.
static constexpr bool is_enabled() noexcept
Always returns false when thread_system is not available.
static bool submit_task(std::function< void()>) noexcept
Always returns false when thread_system is not available.
thread_system_integration(const thread_system_integration &)=delete
DLL export/import macros for logger_system shared library support.
#define LOGGER_SYSTEM_API
constexpr bool has_thread_system_support() noexcept
Helper function to check if thread_system integration is available.
async_backend_type
Backend type enumeration for async processing.
@ standalone
Standalone backend using std::jthread.
@ thread_pool
Thread pool backend using thread_system.