Network System 0.1.1
High-performance modular networking library for scalable client-server applications
Loading...
Searching...
No Matches
thread_system_adapter.h
Go to the documentation of this file.
1// BSD 3-Clause License
2// Copyright (c) 2021-2025, 🍀☀🌕🌥 🌊
3// See the LICENSE file in the project root for full license information.
4
5#pragma once
6
8
23#include <memory>
24#include <future>
25#include <string>
26#include <functional>
27#include <chrono>
28
29#if KCENON_WITH_THREAD_SYSTEM
30// Suppress deprecation warnings from thread_system headers
31# pragma clang diagnostic push
32# pragma clang diagnostic ignored "-Wdeprecated-declarations"
33// Include format for thread_system headers that use std::format
34# include <format>
35# include <kcenon/thread/core/thread_pool.h>
36# include <kcenon/thread/interfaces/thread_context.h>
37# include <kcenon/thread/interfaces/service_container.h>
38# pragma clang diagnostic pop
39#endif
40
42
43#if KCENON_WITH_THREAD_SYSTEM
44
45class thread_system_pool_adapter : public thread_pool_interface {
46public:
47 explicit thread_system_pool_adapter(std::shared_ptr<kcenon::thread::thread_pool> pool);
48 ~thread_system_pool_adapter();
49
50 // Non-copyable, non-movable
51 thread_system_pool_adapter(const thread_system_pool_adapter&) = delete;
52 thread_system_pool_adapter& operator=(const thread_system_pool_adapter&) = delete;
53 thread_system_pool_adapter(thread_system_pool_adapter&&) = delete;
54 thread_system_pool_adapter& operator=(thread_system_pool_adapter&&) = delete;
55
56 // thread_pool_interface
57 std::future<void> submit(std::function<void()> task) override;
58 std::future<void> submit_delayed(std::function<void()> task,
59 std::chrono::milliseconds delay) override;
60 size_t worker_count() const override;
61 bool is_running() const override;
62 size_t pending_tasks() const override;
63
64 // Convenience helpers
65 static std::shared_ptr<thread_system_pool_adapter> create_default(
66 const std::string& pool_name = "network_pool");
67
68 // Try resolving from thread_system's service_container; fallback to default
69 static std::shared_ptr<thread_system_pool_adapter> from_service_or_default(
70 const std::string& pool_name = "network_pool");
71
72private:
80 std::shared_ptr<kcenon::thread::thread_pool> pool_;
81};
82
83bool bind_thread_system_pool_into_manager(const std::string& pool_name = "network_pool");
84
85#else // KCENON_WITH_THREAD_SYSTEM
86
87// Placeholder when thread_system is not available, to keep includes harmless
91
92#endif // KCENON_WITH_THREAD_SYSTEM
93
94} // namespace kcenon::network::integration
95
Feature flags for network_system.
Thread system integration interface for network_system.