29 , shutdown_requested_(false)
58 worker_count = std::max(1u, std::thread::hardware_concurrency());
71 catch (
const std::exception& e)
73 return make_error(std::string(
"Thread pool initialization failed: ") + e.what());
109 std::queue<std::function<void()>> empty;
116 catch (
const std::exception& e)
118 return make_error(std::string(
"Thread pool shutdown failed: ") + e.what());
131 return make_error(
"Thread pool not initialized");
136 return make_error(
"Invalid task");
141 return make_error(
"Thread pool is shutting down");
150 return make_error(
"Task queue full");
209 std::function<void()> task;
common::VoidResult execute(std::function< void()> task) override
Execute a task (fire-and-forget)
std::size_t queue_size() const override
Get current queue size.
~fallback_thread_backend() override
std::atomic< bool > shutdown_requested_
std::size_t worker_count() const override
Get number of worker threads.
bool is_initialized() const override
Check if backend is initialized.
void worker_thread()
Worker thread function.
bool is_idle() const override
Check if thread pool is idle.
common::VoidResult initialize() override
Initialize the thread backend.
std::condition_variable completion_cv_
const db_thread_config & config_
common::VoidResult shutdown() override
Shutdown the thread backend gracefully.
std::mutex completion_mutex_
std::atomic< std::size_t > active_tasks_
std::condition_variable queue_cv_
std::vector< std::thread > workers_
fallback_thread_backend(const db_thread_config &config)
bool wait_for_completion_timeout(std::chrono::milliseconds timeout) override
Wait for completion with timeout.
void wait_for_completion() override
Wait for all pending tasks to complete.
std::queue< std::function< void()> > task_queue_
static void worker(int thread_id, const std::string &connection_string)
Worker function: creates its own connection, inserts data, reads it back, and disconnects.
Fallback thread backend using std::thread.
Result< std::monostate > VoidResult
Thread pool configuration for async operations.
std::size_t max_queue_size
Maximum queued tasks (0 = unlimited)
std::size_t thread_count
Number of worker threads (0 = auto-detect from hardware)