|
NeoGraph 0.16.0
A C++20 Graph Agent Engine Library — LangGraph for C++
|
Lock-free task queue with a fixed worker thread pool and backpressure. More...
#include <request_queue.h>
Classes | |
| struct | Stats |
| Runtime statistics for monitoring queue health. More... | |
Public Member Functions | |
| void | close () |
| Stop accepting work, cancel queued tasks, and wait for workers. | |
| bool | is_closed () const noexcept |
| True once close() has started rejecting new work. | |
| RequestQueue (size_t num_workers=128, size_t max_queue_size=10000) | |
| Construct a request queue with a worker thread pool. | |
| Stats | stats () const |
| Get current queue statistics. | |
| template<typename F > | |
| std::pair< bool, std::future< void > > | submit (F &&task) |
| Submit a task to the queue. | |
| ~RequestQueue () | |
| Destructor: applies the same cancel-on-close policy as close(). | |
Lock-free task queue with a fixed worker thread pool and backpressure.
Tasks are submitted via submit() and executed asynchronously by worker threads. When the queue is full, new tasks are rejected (backpressure).
Definition at line 96 of file request_queue.h.
|
inline |
Construct a request queue with a worker thread pool.
| num_workers | Number of worker threads to spawn (default: 128). |
| max_queue_size | Maximum number of pending tasks before backpressure (default: 10000). |
| std::invalid_argument | if num_workers is zero. |
Definition at line 322 of file request_queue.h.
|
inline |
Stop accepting work, cancel queued tasks, and wait for workers.
The first caller transitions the queue to closed. Work a worker claimed before that transition may finish; all unclaimed work completes its future with std::runtime_error("RequestQueue is closed"). Concurrent and repeated external callers wait for that same shutdown to complete. A task may call close() to initiate shutdown, but cannot wait for itself.
Definition at line 381 of file request_queue.h.
Referenced by ~RequestQueue().
|
inline |
Get current queue statistics.
Definition at line 395 of file request_queue.h.
|
inline |
Submit a task to the queue.
Admission atomically reserves one pending slot before enqueueing, so concurrent submitters cannot exceed max_queue_size. A full queue returns {false, invalid_future}. If the underlying queue rejects an already reserved task, the reservation is rolled back and the returned future is valid but completes with an exception.
| F | Callable type (must be invocable with no arguments). |
| task | The task to execute. |
Definition at line 368 of file request_queue.h.