|
Database System 0.1.0
Advanced C++20 Database System with Multi-Backend Support
|
Thread pool adapter for async database operations. More...
#include <thread_adapter.h>

Public Member Functions | |
| thread_adapter (const db_thread_config &config, thread_backend_type backend_type=thread_backend_type::auto_select) | |
| Construct thread adapter with configuration. | |
| ~thread_adapter () | |
| Destructor - ensures graceful shutdown. | |
| thread_adapter (const thread_adapter &)=delete | |
| thread_adapter & | operator= (const thread_adapter &)=delete |
| thread_adapter (thread_adapter &&) noexcept | |
| thread_adapter & | operator= (thread_adapter &&)=delete |
| common::VoidResult | initialize () |
| Initialize thread pool. | |
| common::VoidResult | shutdown () |
| Shutdown thread pool gracefully. | |
| bool | is_initialized () const |
| Check if thread pool is initialized. | |
| common::VoidResult | execute (std::function< void()> task) |
| Execute a task (fire-and-forget) | |
| template<typename F , typename... Args> requires concepts::SubmittableTask<F, Args...> | |
| auto | submit (F &&f, Args &&... args) -> std::future< std::invoke_result_t< F, Args... > > |
| Submit a task and get a future. | |
| void | wait_for_completion () |
| Wait for all pending tasks to complete. | |
| bool | wait_for_completion_timeout (std::chrono::milliseconds timeout) |
| Wait for tasks with timeout. | |
| std::size_t | worker_count () const |
| Get number of worker threads. | |
| std::size_t | queue_size () const |
| Get current queue size. | |
| bool | is_idle () const |
| Check if thread pool is idle. | |
Static Private Member Functions | |
| static std::unique_ptr< backends::thread_backend > | create_backend (const db_thread_config &config, thread_backend_type backend_type) |
| Create appropriate backend based on type. | |
Private Attributes | |
| const db_thread_config & | config_ |
| std::unique_ptr< backends::thread_backend > | backend_ |
| Thread backend implementation. | |
Thread pool adapter for async database operations.
Provides unified async execution with runtime backend selection. No longer uses conditional compilation - backend is selected at runtime.
Thread Safety: All methods are thread-safe Exception Safety: Strong guarantee - failed operations don't affect pool state
Definition at line 98 of file thread_adapter.h.
|
explicit |
Construct thread adapter with configuration.
| config | Thread pool configuration |
| backend_type | Backend type to use (default: auto_select) |
Definition at line 43 of file thread_adapter.cpp.
| database::integrated::adapters::thread_adapter::~thread_adapter | ( | ) |
Destructor - ensures graceful shutdown.
Definition at line 51 of file thread_adapter.cpp.
References backend_.
|
delete |
|
defaultnoexcept |
|
staticprivate |
Create appropriate backend based on type.
Definition at line 21 of file thread_adapter.cpp.
References database::integrated::adapters::auto_select, database::integrated::adapters::fallback, and database::integrated::adapters::null.
| common::VoidResult database::integrated::adapters::thread_adapter::execute | ( | std::function< void()> | task | ) |
Execute a task (fire-and-forget)
| task | Task to execute |
Definition at line 91 of file thread_adapter.cpp.
References backend_.
Referenced by submit().

| common::VoidResult database::integrated::adapters::thread_adapter::initialize | ( | ) |
Initialize thread pool.
Definition at line 61 of file thread_adapter.cpp.
References initialize().
Referenced by initialize(), test_api_availability_priority(), test_api_availability_submit(), test_destructor_safety(), test_double_initialization(), and test_move_semantics().


| bool database::integrated::adapters::thread_adapter::is_idle | ( | ) | const |
Check if thread pool is idle.
Definition at line 148 of file thread_adapter.cpp.
References backend_.
| bool database::integrated::adapters::thread_adapter::is_initialized | ( | ) | const |
Check if thread pool is initialized.
Definition at line 82 of file thread_adapter.cpp.
References backend_.
|
delete |
|
delete |
| std::size_t database::integrated::adapters::thread_adapter::queue_size | ( | ) | const |
Get current queue size.
Definition at line 138 of file thread_adapter.cpp.
References backend_.
Referenced by test_api_availability_stats().

| common::VoidResult database::integrated::adapters::thread_adapter::shutdown | ( | ) |
Shutdown thread pool gracefully.
Waits for all pending tasks to complete before shutting down. After shutdown, no new tasks can be submitted.
Definition at line 72 of file thread_adapter.cpp.
References backend_, and common::ok().
Referenced by test_api_availability_priority(), test_api_availability_submit(), test_double_initialization(), test_move_semantics(), and test_shutdown_without_init().


| auto database::integrated::adapters::thread_adapter::submit | ( | F && | f, |
| Args &&... | args ) -> std::future<std::invoke_result_t<F, Args...>> |
Submit a task and get a future.
| F | Function type - constrained by SubmittableTask concept |
| Args | Argument types |
| f | Function to execute |
| args | Arguments to pass to function |
Uses SubmittableTask concept for compile-time validation:
Definition at line 227 of file thread_adapter.h.
References execute().
Referenced by test_api_availability_priority(), test_api_availability_submit(), and test_destructor_safety().


| void database::integrated::adapters::thread_adapter::wait_for_completion | ( | ) |
Wait for all pending tasks to complete.
Blocks until all submitted tasks finish execution.
Definition at line 106 of file thread_adapter.cpp.
References backend_.
| bool database::integrated::adapters::thread_adapter::wait_for_completion_timeout | ( | std::chrono::milliseconds | timeout | ) |
Wait for tasks with timeout.
| timeout | Maximum time to wait |
Definition at line 114 of file thread_adapter.cpp.
References backend_, and database::timeout.
| std::size_t database::integrated::adapters::thread_adapter::worker_count | ( | ) | const |
Get number of worker threads.
Definition at line 128 of file thread_adapter.cpp.
References backend_.
Referenced by test_api_availability_stats().

|
private |
Thread backend implementation.
Definition at line 218 of file thread_adapter.h.
Referenced by execute(), is_idle(), is_initialized(), queue_size(), shutdown(), wait_for_completion(), wait_for_completion_timeout(), worker_count(), and ~thread_adapter().
|
private |
Definition at line 217 of file thread_adapter.h.