userver: userver/dist_lock/dist_locked_task.hpp Source File
Loading...
Searching...
No Matches
dist_locked_task.hpp
Go to the documentation of this file.
1#pragma once
2
5
6#include <chrono>
7#include <functional>
8#include <memory>
9#include <optional>
10#include <string>
11
17
18USERVER_NAMESPACE_BEGIN
19
20namespace dist_lock {
21namespace impl {
22
23class Locker;
24
25} // namespace impl
26
44class DistLockedTask final : public engine::TaskBase {
45public:
46 using WorkerFunc = std::function<void()>;
47
50 DistLockedTask() = default;
51
53 DistLockedTask& operator=(DistLockedTask&&) = delete;
54
55 DistLockedTask(const DistLockedTask&) = delete;
56 DistLockedTask& operator=(const DistLockedTask&&) = delete;
57
59
73 std::string name,
74 WorkerFunc worker_func,
75 std::shared_ptr<DistLockStrategyBase> strategy,
76 const DistLockSettings& settings = {},
80 );
81
84 engine::TaskProcessor& task_processor,
85 std::string name,
86 WorkerFunc worker_func,
87 std::shared_ptr<DistLockStrategyBase> strategy,
88 const DistLockSettings& settings = {},
92 );
93
96 std::optional<std::chrono::steady_clock::duration> GetLockedDuration() const;
97
98 void Get() noexcept(false);
99
100private:
101 DistLockedTask(engine::TaskProcessor&, std::shared_ptr<impl::Locker>, DistLockWaitingMode);
102
103 std::shared_ptr<impl::Locker> locker_ptr_;
104};
105
106} // namespace dist_lock
107
108USERVER_NAMESPACE_END