Thread System 0.3.1
High-performance C++20 thread pool with work stealing and DAG scheduling
Loading...
Searching...
No Matches
common_executor_adapter.h File Reference

Adapter to bridge thread_system pools with common IExecutor interface. More...

#include <kcenon/thread/core/callback_job.h>
#include <kcenon/thread/core/error_handling.h>
#include <kcenon/thread/core/thread_pool.h>
#include <atomic>
#include <chrono>
#include <exception>
#include <functional>
#include <future>
#include <memory>
#include <optional>
#include <sstream>
#include <string>
#include <thread>
#include <utility>
Include dependency graph for common_executor_adapter.h:

Go to the source code of this file.

Classes

class  kcenon::thread::adapters::thread_pool_executor_adapter
 Adapter exposing thread_pool through common::interfaces::IExecutor. More...
 
class  kcenon::thread::adapters::common_executor_factory
 Factory for creating IExecutor adapters from thread_pool instances. More...
 

Namespaces

namespace  kcenon
 
namespace  kcenon::thread
 Core threading foundation of the thread system library.
 
namespace  kcenon::thread::adapters
 
namespace  kcenon::thread::adapters::detail
 

Functions

common::error_info kcenon::thread::adapters::detail::make_error_info (int code, std::string message, std::string module="thread_system")
 
common::error_info kcenon::thread::adapters::detail::make_error_info (kcenon::thread::error_code code, std::string message)
 
std::exception_ptr kcenon::thread::adapters::detail::to_exception (const common::error_info &info)
 
common::VoidResult kcenon::thread::adapters::detail::make_error (const common::error_info &info)
 
common::VoidResult kcenon::thread::adapters::detail::make_error (kcenon::thread::error_code code, std::string message)
 
common::error_info kcenon::thread::adapters::detail::unexpected_pool_error ()
 
common::VoidResult kcenon::thread::adapters::detail::wrap_user_task (const std::function< void()> &task)
 
std::optional< common::error_info > kcenon::thread::adapters::detail::enqueue_job (const std::shared_ptr< kcenon::thread::thread_pool > &pool, const std::shared_ptr< std::promise< void > > &promise, std::function< common::VoidResult()> body)
 
common::Result< std::future< void > > kcenon::thread::adapters::detail::schedule_task (const std::shared_ptr< kcenon::thread::thread_pool > &pool, std::function< common::VoidResult()> body)
 
void kcenon::thread::adapters::detail::schedule_task_async (std::shared_ptr< kcenon::thread::thread_pool > pool, std::shared_ptr< std::promise< void > > promise, std::function< common::VoidResult()> body, std::chrono::milliseconds delay)
 

Detailed Description

Adapter to bridge thread_system pools with common IExecutor interface.

This adapter provides the recommended way to use thread_pool with the common::interfaces::IExecutor interface. Direct inheritance of IExecutor by thread_pool is deprecated and will be removed in v2.0.

Migration Guide
If you were previously using thread_pool directly as an IExecutor:
// Old way (deprecated):
auto pool = std::make_shared<kcenon::thread::thread_pool>("my_pool");
kcenoncommon::interfaces::IExecutor* executor = pool.get();
executor->execute(std::move(job));
// New way (recommended):
auto pool = std::make_shared<kcenon::thread::thread_pool>("my_pool");
auto executor = std::make_shared<kcenon::thread::adapters::thread_pool_executor_adapter>(pool);
executor->execute(std::move(job));
Benefits of the Adapter Approach
  • Cleaner separation of concerns: thread_pool focuses on thread management
  • Easier maintenance: IExecutor changes don't affect thread_pool core
  • Better testability: adapter can be mocked independently
  • Reduced compilation dependencies: conditional compilation isolated to adapter
See also
thread_pool_executor_adapter The main adapter class
common_executor_factory Factory for creating adapters

Definition in file common_executor_adapter.h.