userver: userver/engine/impl/detached_tasks_sync_block.hpp Source File
Loading...
Searching...
No Matches
detached_tasks_sync_block.hpp
1#pragma once
2
3#include <cstdint>
4#include <utility>
5
6#include <userver/engine/task/cancel.hpp>
7#include <userver/engine/task/task.hpp>
8#include <userver/utils/fast_pimpl.hpp>
9
10USERVER_NAMESPACE_BEGIN
11
12namespace engine::impl {
13
14class TaskContext;
15
16class DetachedTasksSyncBlock final {
17 public:
18 enum class StopMode { kCancelAndWait, kCancel };
19
20 explicit DetachedTasksSyncBlock(StopMode stop_mode);
21
22 DetachedTasksSyncBlock(const DetachedTasksSyncBlock&) = delete;
23 DetachedTasksSyncBlock(DetachedTasksSyncBlock&&) = delete;
24 ~DetachedTasksSyncBlock();
25
26 void Add(TaskContext& context);
27 void Add(Task&& task);
28
29 void RequestCancellation(TaskCancellationReason reason) noexcept;
30
31 void WaitAllTasksCompleteDebug() noexcept;
32
33 std::int64_t ActiveTasksApprox() const noexcept;
34
35 struct Token;
36
37 static void Dispose(Token& token) noexcept;
38
39 private:
40 struct Impl;
41 utils::FastPimpl<Impl, 96, 16> impl_;
42};
43
44} // namespace engine::impl
45
46USERVER_NAMESPACE_END