cxxmcp 1.1.6
C++ MCP SDK
Loading...
Searching...
No Matches
mcp::core::Executor Class Reference

Thread pool executor with priority queues and a timer wheel. More...

#include <executor.hpp>

Public Types

using ExceptionHandler = std::function< void(std::exception_ptr)>
 
using Options = ExecutorOptions
 

Public Member Functions

 Executor (Options options={})
 
 Executor (std::size_t worker_count, std::size_t max_queue_size)
 Backward-compatible constructor matching BoundedExecutor's signature.
 
 Executor (std::size_t worker_count, std::size_t max_queue_size, ExceptionHandler exception_handler)
 Backward-compatible constructor matching BoundedExecutor's signature.
 
 Executor (const Executor &)=delete
 
Executoroperator= (const Executor &)=delete
 
core::Result< Unitenqueue (std::function< void()> task)
 Backward-compatible enqueue (equivalent to post with DEFAULT priority).
 
core::Result< Unitpost (std::function< void()> task, TaskPriority prio=TaskPriority::DEFAULT)
 Post a task for execution at the given priority.
 
TimerHandle post_after (std::chrono::milliseconds delay, std::function< void()> task, TaskPriority prio=TaskPriority::DEFAULT)
 Schedule a task to run after a delay.
 
TimerHandle post_at (std::chrono::steady_clock::time_point when, std::function< void()> task, TaskPriority prio=TaskPriority::DEFAULT)
 Schedule a task to run at an absolute time point.
 
void shutdown () noexcept
 Graceful shutdown: complete all queued tasks, then join threads.
 
void stop ()
 Backward-compatible stop (equivalent to shutdown).
 
void cancel_and_stop ()
 Cancel pending tasks and stop immediately.
 

Detailed Description

Thread pool executor with priority queues and a timer wheel.

The executor owns a fixed number of worker threads and a dedicated timer thread. Worker threads dequeue tasks from three priority-ordered queues. The timer thread sleeps until the next scheduled timer fires and moves due tasks into the appropriate priority queue.

Executor exec(ExecutorOptions{4, 256});
exec.post([]{ do_work(); }, TaskPriority::DEFAULT);
exec.post_after(100ms, []{ delayed(); });
exec.shutdown(); // drain and join
Thread pool executor with priority queues and a timer wheel.
Definition executor.hpp:55
core::Result< Unit > post(std::function< void()> task, TaskPriority prio=TaskPriority::DEFAULT)
Post a task for execution at the given priority.
Definition executor.hpp:103
Options for the Executor class.
Definition executor.hpp:36

The documentation for this class was generated from the following file: