7#include <condition_variable>
64 State() : token(source.token()) {}
66 mutable std::mutex mutex;
67 std::condition_variable cv;
70 std::optional<BackgroundJobProgress> progress;
72 bool finished =
false;
77 std::shared_ptr<State> state_;
105 std::shared_ptr<BackgroundJobHandle::State>
state;
110 void prune_finished_jobs_locked();
111 static bool has_higher_priority(
const QueuedJob& a,
const QueuedJob& b);
113 mutable std::mutex mutex_;
114 std::condition_variable cv_;
115 std::deque<QueuedJob> queue_;
116 std::vector<std::shared_ptr<BackgroundJobHandle::State>> all_jobs_;
117 bool stopping_ =
false;
141template <
typename T, std::
size_t RetireCapacity>
143 static_assert(RetireCapacity > 0,
"RetireCapacity must be > 0");
152 const T*
get() const noexcept {
153 return current_.load(std::memory_order_acquire);
156 [[nodiscard]]
bool publish(std::unique_ptr<const T> next) {
162 std::unique_ptr<const T> next) {
165 auto previous = std::move(active_);
166 if (previous && !retired_.try_push(std::move(previous))) {
167 active_ = std::move(previous);
168 retire_overflow_count_.fetch_add(1, std::memory_order_relaxed);
172 const T* next_ptr = next.get();
173 active_ = std::move(next);
174 current_.store(next_ptr, std::memory_order_release);
179 std::size_t reclaimed = 0;
180 while (reclaimed < max_to_reclaim) {
181 auto retired = retired_.try_pop();
189 return retired_.size_approx();
193 return retire_overflow_count_.load(std::memory_order_relaxed);
197 std::atomic<const T*> current_{
nullptr};
198 std::unique_ptr<const T> active_;
199 SpscQueue<std::unique_ptr<const T>, RetireCapacity> retired_;
200 std::atomic<std::uint64_t> retire_overflow_count_{0};
Definition background_job.hpp:33
const CancelToken & cancellation_token() const
Definition background_job.hpp:39
BackgroundJobContext(CancelToken cancellation, std::function< void(BackgroundJobProgress)> progress)
void publish_progress(BackgroundJobProgress progress) const
bool is_cancelled() const
Definition background_job.hpp:51
bool is_cancelled() const
BackgroundJobHandle()=default
friend class BackgroundJobService
Definition background_job.hpp:79
std::optional< BackgroundJobProgress > latest_progress() const
BackgroundJobService(const BackgroundJobService &)=delete
BackgroundJobHandle submit(BackgroundJobOptions options, BackgroundJobFunction job)
std::size_t pending_count() const
BackgroundJobService & operator=(const BackgroundJobService &)=delete
Move-only owner of a cancellation state.
Definition cancel.hpp:126
RealtimeResourceSlotPublishStatus publish_with_status(std::unique_ptr< const T > next)
Definition background_job.hpp:161
RealtimeResourceSlot & operator=(const RealtimeResourceSlot &)=delete
const T * get() const noexcept
Definition background_job.hpp:152
std::size_t retired_count_approx() const
Definition background_job.hpp:188
std::size_t reclaim_retired(std::size_t max_to_reclaim=RetireCapacity)
Definition background_job.hpp:178
RealtimeResourceSlot(const RealtimeResourceSlot &)=delete
bool publish(std::unique_ptr< const T > next)
Definition background_job.hpp:156
RealtimeResourceSlot()=default
std::uint64_t retire_overflow_count() const
Definition background_job.hpp:192
~RealtimeResourceSlot()
Definition background_job.hpp:147
Definition generated_event_source.hpp:33
RealtimeResourceSlotPublishStatus
Definition background_job.hpp:121
@ Published
Definition background_job.hpp:122
@ RejectedEmptyResource
Definition background_job.hpp:123
@ RejectedRetireQueueFull
Definition background_job.hpp:124
std::function< void(BackgroundJobContext &)> BackgroundJobFunction
Definition background_job.hpp:49
constexpr bool realtime_resource_slot_publish_succeeded(RealtimeResourceSlotPublishStatus status) noexcept
Definition background_job.hpp:127
BackgroundJobPriority
Definition background_job.hpp:21
@ low
Definition background_job.hpp:22
@ high
Definition background_job.hpp:24
@ normal
Definition background_job.hpp:23
Definition host_transport_projector.hpp:8
SequencerStateChannel is the audio-safe transport for a plugin's structured NON-parameter state: the ...
Definition audio_device_manager.hpp:48
Definition background_job.hpp:82
BackgroundJobPriority priority
Definition background_job.hpp:84
std::string name
Definition background_job.hpp:83
Definition background_job.hpp:27
std::uint64_t total
Definition background_job.hpp:29
std::string label
Definition background_job.hpp:30
std::uint64_t completed
Definition background_job.hpp:28