8#include <condition_variable>
47 std::size_t available_;
49 std::condition_variable cv_;
57 using Task = std::function<void()>;
66 std::size_t queueCapacity,
67 std::shared_ptr<core::ports::diagnostics::IErrorReporter> errorReporter);
105 std::condition_variable cvNotEmpty_;
106 std::condition_variable cvNotFull_;
108 bool stopping_ =
false;
109 std::vector<std::thread> workers_;
110 std::shared_ptr<core::ports::diagnostics::IErrorReporter> errorReporter_;
void enqueue(Task t)
Enqueue a task, blocking when the queue is full.
Scheduler(const Scheduler &)=delete
Copying a scheduler is disabled.
std::function< void()> Task
Scheduler & operator=(const Scheduler &)=delete
Copy-assigning a scheduler is disabled.
Scheduler(std::size_t workers, std::size_t queueCapacity, std::shared_ptr< core::ports::diagnostics::IErrorReporter > errorReporter)
Create a scheduler with bounded workers and queue capacity.
void stop()
Stop accepting new tasks and join all worker threads.
~Scheduler()
Stop workers and destroy the scheduler.
void release()
Release one acquired slot and wake a waiting caller.
SlotLimiter(std::size_t slots)
Create a limiter with at least one available slot.
void acquire()
Block until a slot is available and acquire it.
Port for reporting structured diagnostic error events.