16#ifdef LOGGER_HAS_THREAD_SYSTEM
18#include <kcenon/thread/core/callback_job.h>
23std::atomic<async_backend_type> thread_system_integration::current_backend_{
26std::shared_ptr<kcenon::thread::thread_pool> thread_system_integration::thread_pool_{
nullptr};
27std::mutex thread_system_integration::pool_mutex_{};
30 std::lock_guard<std::mutex> lock(pool_mutex_);
33 thread_pool_ = std::move(pool);
34 }
else if (!thread_pool_) {
36 thread_pool_ = create_default_pool();
43 std::lock_guard<std::mutex> lock(pool_mutex_);
56 return current_backend_.load(std::memory_order_acquire);
59void thread_system_integration::set_thread_pool(
60 std::shared_ptr<kcenon::thread::thread_pool> pool) {
61 std::lock_guard<std::mutex> lock(pool_mutex_);
64 thread_pool_ = std::move(pool);
72std::shared_ptr<kcenon::thread::thread_pool> thread_system_integration::get_thread_pool() noexcept {
73 std::lock_guard<std::mutex> lock(pool_mutex_);
82 std::shared_ptr<kcenon::thread::thread_pool> pool;
84 std::lock_guard<std::mutex> lock(pool_mutex_);
88 if (!pool || !pool->is_running()) {
93 auto job = std::make_unique<kcenon::thread::callback_job>(
101 auto result = pool->enqueue(std::move(job));
102 return result.is_ok();
106 return is_enabled() ?
"thread_pool" :
"standalone";
109std::shared_ptr<kcenon::thread::thread_pool> thread_system_integration::create_default_pool() {
110 auto pool = std::make_shared<kcenon::thread::thread_pool>(
115 auto result = pool->start();
116 if (!result.is_ok()) {
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.
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.
async_backend_type
Backend type enumeration for async processing.
@ standalone
Standalone backend using std::jthread.
@ thread_pool
Thread pool backend using thread_system.
Optional thread_system integration for advanced async processing.