ThreadSchedule 3.0.0
Modern C++ thread management library
Loading...
Searching...
No Matches
scheduled_task_backend.hpp
Go to the documentation of this file.
1#pragma once
2
8
9#include <cstdint>
10#include <memory>
11
13{
14
26{
27public:
28 explicit scheduled_task_backend(uint64_t id)
29 : id_(id), cancellation_(std::make_shared<detail::scheduled_cancellation_state>())
30 {
31 }
32
35
37 : id_(other.id_), cancellation_(std::move(other.cancellation_))
38 {
39 other.id_ = 0;
40 }
41
42 auto
44 {
45 if (this != &other)
46 {
47 id_ = other.id_;
48 cancellation_ = std::move(other.cancellation_);
49 other.id_ = 0;
50 }
51 return *this;
52 }
53
54 void
56 {
57 if (cancellation_)
58 cancellation_->user_cancelled.store(true, std::memory_order_release);
59 }
60
61 [[nodiscard]] auto
62 is_cancelled() const noexcept -> bool
63 {
64 return !cancellation_ || cancellation_->user_cancelled.load(std::memory_order_acquire)
65 || cancellation_->pool_stopped.load(std::memory_order_acquire);
66 }
67
68 [[nodiscard]] auto
69 id() const noexcept -> uint64_t
70 {
71 return id_;
72 }
73
74private:
75 uint64_t id_{ 0 };
76 std::shared_ptr<detail::scheduled_cancellation_state> cancellation_;
77
78 template <typename>
80 [[nodiscard]] auto
81 get_cancellation() const -> std::shared_ptr<detail::scheduled_cancellation_state>
82 {
83 return cancellation_;
84 }
85};
86
87} // namespace threadschedule::detail
Thread pool augmented with delayed and periodic task scheduling.
Copyable handle for a cancellable scheduled task.
scheduled_task_backend(scheduled_task_backend &&other) noexcept
auto operator=(scheduled_task_backend const &) -> scheduled_task_backend &=default
scheduled_task_backend(scheduled_task_backend const &)=default
auto operator=(scheduled_task_backend &&other) noexcept -> scheduled_task_backend &
Aggregates multiple thread_registry_backend instances into a single queryable view.
@ other
Standard round-robin time-sharing.
Shared cancellation flags for scheduled task handles.