Thread System 0.3.1
High-performance C++20 thread pool with work stealing and DAG scheduling
Loading...
Searching...
No Matches
pool_policy.h
Go to the documentation of this file.
1// BSD 3-Clause License
2// Copyright (c) 2024, 🍀☀🌕🌥 🌊
3// See the LICENSE file in the project root for full license information.
4
11#pragma once
12
18 // end of pool_policies
19
20#include <kcenon/common/patterns/result.h>
21
22#include <memory>
23#include <string>
24
25namespace kcenon::thread
26{
27 // Forward declarations
28 class job;
29
81 {
82 public:
86 virtual ~pool_policy() = default;
87
102 virtual auto on_enqueue(job& j) -> common::VoidResult = 0;
103
117 virtual void on_job_start(job& j) = 0;
118
134 virtual void on_job_complete(job& j, bool success, const std::exception* error = nullptr) = 0;
135
140 [[nodiscard]] virtual auto get_name() const -> std::string = 0;
141
146 [[nodiscard]] virtual auto is_enabled() const -> bool { return true; }
147
154 virtual void set_enabled(bool enabled) { (void)enabled; }
155 };
156
157} // namespace kcenon::thread
Represents an error in the thread system.
Represents a unit of work (task) to be executed, typically by a job queue.
Definition job.h:136
Base interface for thread pool policies.
Definition pool_policy.h:81
virtual auto on_enqueue(job &j) -> common::VoidResult=0
Called before a job is enqueued.
virtual ~pool_policy()=default
Virtual destructor for proper cleanup.
virtual void on_job_start(job &j)=0
Called when a worker starts executing a job.
virtual void on_job_complete(job &j, bool success, const std::exception *error=nullptr)=0
Called when a job completes (success or failure).
virtual auto get_name() const -> std::string=0
Gets the policy name for identification and logging.
virtual auto is_enabled() const -> bool
Checks if the policy is currently enabled.
virtual void set_enabled(bool enabled)
Enables or disables the policy.
Core threading foundation of the thread system library.
Definition thread_impl.h:17
STL namespace.