|
Database System 0.1.0
Advanced C++20 Database System with Multi-Backend Support
|
Simple thread pool using std::thread. More...
#include <fallback_thread_backend.h>


Public Member Functions | |
| fallback_thread_backend (const db_thread_config &config) | |
| ~fallback_thread_backend () override | |
| fallback_thread_backend (const fallback_thread_backend &)=delete | |
| fallback_thread_backend & | operator= (const fallback_thread_backend &)=delete |
| fallback_thread_backend (fallback_thread_backend &&)=delete | |
| fallback_thread_backend & | operator= (fallback_thread_backend &&)=delete |
| common::VoidResult | initialize () override |
| Initialize the thread backend. | |
| common::VoidResult | shutdown () override |
| Shutdown the thread backend gracefully. | |
| bool | is_initialized () const override |
| Check if backend is initialized. | |
| common::VoidResult | execute (std::function< void()> task) override |
| Execute a task (fire-and-forget) | |
| void | wait_for_completion () override |
| Wait for all pending tasks to complete. | |
| bool | wait_for_completion_timeout (std::chrono::milliseconds timeout) override |
| Wait for completion with timeout. | |
| std::size_t | worker_count () const override |
| Get number of worker threads. | |
| std::size_t | queue_size () const override |
| Get current queue size. | |
| bool | is_idle () const override |
| Check if thread pool is idle. | |
Public Member Functions inherited from database::integrated::adapters::backends::thread_backend | |
| virtual | ~thread_backend ()=default |
Private Member Functions | |
| void | worker_thread () |
| Worker thread function. | |
Private Attributes | |
| const db_thread_config & | config_ |
| bool | initialized_ |
| std::atomic< bool > | shutdown_requested_ |
| std::vector< std::thread > | workers_ |
| std::queue< std::function< void()> > | task_queue_ |
| std::mutex | queue_mutex_ |
| std::condition_variable | queue_cv_ |
| std::atomic< std::size_t > | active_tasks_ |
| std::mutex | completion_mutex_ |
| std::condition_variable | completion_cv_ |
Simple thread pool using std::thread.
This backend provides basic thread pooling when thread_system is unavailable. Uses std::thread and std::queue for task management.
Definition at line 46 of file fallback_thread_backend.h.
|
explicit |
Definition at line 26 of file fallback_thread_backend.cpp.
|
override |
Definition at line 34 of file fallback_thread_backend.cpp.
References initialized_, and shutdown().

|
delete |
|
delete |
|
overridevirtual |
Execute a task (fire-and-forget)
| task | Task to execute |
Implements database::integrated::adapters::backends::thread_backend.
Definition at line 127 of file fallback_thread_backend.cpp.
References config_, initialized_, database::integrated::db_thread_config::max_queue_size, common::ok(), queue_cv_, queue_mutex_, shutdown_requested_, and task_queue_.

|
overridevirtual |
Initialize the thread backend.
Implements database::integrated::adapters::backends::thread_backend.
Definition at line 42 of file fallback_thread_backend.cpp.
References active_tasks_, config_, initialized_, common::ok(), shutdown_requested_, database::integrated::db_thread_config::thread_count, worker_count(), worker_thread(), and workers_.

|
overridevirtual |
Check if thread pool is idle.
Implements database::integrated::adapters::backends::thread_backend.
Definition at line 199 of file fallback_thread_backend.cpp.
References active_tasks_, queue_mutex_, and task_queue_.
|
overridevirtual |
Check if backend is initialized.
Implements database::integrated::adapters::backends::thread_backend.
Definition at line 122 of file fallback_thread_backend.cpp.
References initialized_.
|
delete |
|
delete |
|
overridevirtual |
Get current queue size.
Implements database::integrated::adapters::backends::thread_backend.
Definition at line 193 of file fallback_thread_backend.cpp.
References queue_mutex_, and task_queue_.
|
overridevirtual |
Shutdown the thread backend gracefully.
Implements database::integrated::adapters::backends::thread_backend.
Definition at line 77 of file fallback_thread_backend.cpp.
References initialized_, common::ok(), queue_cv_, queue_mutex_, shutdown_requested_, task_queue_, worker(), and workers_.
Referenced by ~fallback_thread_backend().


|
overridevirtual |
Wait for all pending tasks to complete.
Implements database::integrated::adapters::backends::thread_backend.
Definition at line 160 of file fallback_thread_backend.cpp.
References active_tasks_, completion_cv_, completion_mutex_, initialized_, queue_mutex_, and task_queue_.
|
overridevirtual |
Wait for completion with timeout.
| timeout | Maximum wait time |
Implements database::integrated::adapters::backends::thread_backend.
Definition at line 174 of file fallback_thread_backend.cpp.
References active_tasks_, completion_cv_, completion_mutex_, initialized_, queue_mutex_, task_queue_, and database::timeout.
|
overridevirtual |
Get number of worker threads.
Implements database::integrated::adapters::backends::thread_backend.
Definition at line 188 of file fallback_thread_backend.cpp.
References workers_.
Referenced by initialize().

|
private |
Worker thread function.
Definition at line 205 of file fallback_thread_backend.cpp.
References active_tasks_, completion_cv_, completion_mutex_, queue_cv_, queue_mutex_, shutdown_requested_, and task_queue_.
Referenced by initialize().

|
private |
Definition at line 86 of file fallback_thread_backend.h.
Referenced by initialize(), is_idle(), wait_for_completion(), wait_for_completion_timeout(), and worker_thread().
|
private |
Definition at line 88 of file fallback_thread_backend.h.
Referenced by wait_for_completion(), wait_for_completion_timeout(), and worker_thread().
|
mutableprivate |
Definition at line 87 of file fallback_thread_backend.h.
Referenced by wait_for_completion(), wait_for_completion_timeout(), and worker_thread().
|
private |
Definition at line 76 of file fallback_thread_backend.h.
Referenced by execute(), and initialize().
|
private |
Definition at line 77 of file fallback_thread_backend.h.
Referenced by execute(), initialize(), is_initialized(), shutdown(), wait_for_completion(), wait_for_completion_timeout(), and ~fallback_thread_backend().
|
private |
Definition at line 84 of file fallback_thread_backend.h.
Referenced by execute(), shutdown(), and worker_thread().
|
mutableprivate |
Definition at line 83 of file fallback_thread_backend.h.
Referenced by execute(), is_idle(), queue_size(), shutdown(), wait_for_completion(), wait_for_completion_timeout(), and worker_thread().
|
private |
Definition at line 78 of file fallback_thread_backend.h.
Referenced by execute(), initialize(), shutdown(), and worker_thread().
|
private |
Definition at line 81 of file fallback_thread_backend.h.
Referenced by execute(), is_idle(), queue_size(), shutdown(), wait_for_completion(), wait_for_completion_timeout(), and worker_thread().
|
private |
Definition at line 80 of file fallback_thread_backend.h.
Referenced by initialize(), shutdown(), and worker_count().