userver: userver/engine/mutex.hpp Source File
Loading...
Searching...
No Matches
mutex.hpp
Go to the documentation of this file.
1#pragma once
2
5
6#include <atomic>
7#include <chrono>
8#include <mutex> // for std locks
9
11#include <userver/engine/impl/wait_list_fwd.hpp>
12
13USERVER_NAMESPACE_BEGIN
14
15namespace engine {
16
28class Mutex final {
29public:
30 Mutex();
31 ~Mutex();
32
33 Mutex(const Mutex&) = delete;
34 Mutex(Mutex&&) = delete;
35 Mutex& operator=(const Mutex&) = delete;
36 Mutex& operator=(Mutex&&) = delete;
37
44 void lock();
45
50 void unlock();
51
56 [[nodiscard]] bool try_lock() noexcept;
57
66 template <typename Rep, typename Period>
67 [[nodiscard]] bool try_lock_for(const std::chrono::duration<Rep, Period>&);
68
77 template <typename Clock, typename Duration>
78 [[nodiscard]] bool try_lock_until(const std::chrono::time_point<Clock, Duration>&);
79
81 [[nodiscard]] bool try_lock_until(Deadline deadline);
82
83private:
84 class Impl;
85
86 utils::FastPimpl<Impl, 104, alignof(void*)> impl_;
87};
88
89template <typename Rep, typename Period>
90bool Mutex::try_lock_for(const std::chrono::duration<Rep, Period>& duration) {
91 return try_lock_until(Deadline::FromDuration(duration));
92}
93
94template <typename Clock, typename Duration>
95bool Mutex::try_lock_until(const std::chrono::time_point<Clock, Duration>& until) {
97}
98
99} // namespace engine
100
101USERVER_NAMESPACE_END