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
24#include <memory>
25#include <future>
26#include <string>
27#include <functional>
28#include <chrono>
29
30#if KCENON_WITH_THREAD_SYSTEM
31// Suppress deprecation warnings from thread_system headers
32# pragma clang diagnostic push
33# pragma clang diagnostic ignored "-Wdeprecated-declarations"
34// Include format for thread_system headers that use std::format
35# include <format>
36# include <kcenon/thread/core/thread_pool.h>
37# include <kcenon/thread/interfaces/thread_context.h>
38# include <kcenon/thread/interfaces/service_container.h>
39# pragma clang diagnostic pop
40#endif
41
43
44#if KCENON_WITH_THREAD_SYSTEM
45
46class thread_system_pool_adapter : public thread_pool_interface {
47public:
48 [[nodiscard]] static Result<std::shared_ptr<thread_system_pool_adapter>> create(
49 std::shared_ptr<kcenon::thread::thread_pool> pool);
50 ~thread_system_pool_adapter();
51
52 // Non-copyable, non-movable
53 thread_system_pool_adapter(const thread_system_pool_adapter&) = delete;
54 thread_system_pool_adapter& operator=(const thread_system_pool_adapter&) = delete;
55 thread_system_pool_adapter(thread_system_pool_adapter&&) = delete;
56 thread_system_pool_adapter& operator=(thread_system_pool_adapter&&) = delete;
57
58 // thread_pool_interface
59 std::future<void> submit(std::function<void()> task) override;
60 std::future<void> submit_delayed(std::function<void()> task,
61 std::chrono::milliseconds delay) override;
62 size_t worker_count() const override;
63 bool is_running() const override;
64 size_t pending_tasks() const override;
65
66 // Convenience helpers
67 static std::shared_ptr<thread_system_pool_adapter> create_default(
68 const std::string& pool_name = "network_pool");
69
70 // Try resolving from thread_system's service_container; fallback to default
71 static std::shared_ptr<thread_system_pool_adapter> from_service_or_default(
72 const std::string& pool_name = "network_pool");
73
74private:
75 explicit thread_system_pool_adapter(std::shared_ptr<kcenon::thread::thread_pool> pool);
83 std::shared_ptr<kcenon::thread::thread_pool> pool_;
84};
85
86bool bind_thread_system_pool_into_manager(const std::string& pool_name = "network_pool");
87
88#else // KCENON_WITH_THREAD_SYSTEM
89
90// Placeholder when thread_system is not available, to keep includes harmless
94
95#endif // KCENON_WITH_THREAD_SYSTEM
96
97} // namespace kcenon::network::integration
98
Feature flags for network_system.
Network-specific error and result type definitions.
Thread system integration interface for network_system.