BRICKS
Small, useful blocks of code, to build bigger things.
Loading...
Searching...
No Matches
rw_lock.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <shared_mutex>
4
7
8namespace bricks {
9
27template <class Class>
28class rw_lock : private Class {
29 private:
30 friend class detail::read_guard<rw_lock>;
31 friend class detail::write_guard<rw_lock, std::shared_mutex>;
32
33 public:
34 using value_type = Class;
35
36 using read_guard = detail::read_guard<rw_lock>;
37 using write_guard = detail::write_guard<rw_lock, std::shared_mutex>;
38
39 using Class::Class;
40
47 auto read() const noexcept -> read_guard { return read_guard{*this, mutex_}; }
48
55 auto write() noexcept -> write_guard { return write_guard{*this, mutex_}; }
56
57 private:
58 mutable std::shared_mutex mutex_;
59};
60
61} // namespace bricks
A reader-writer lock.
Definition rw_lock.hpp:28
detail::write_guard< rw_lock, std::shared_mutex > write_guard
Definition rw_lock.hpp:37
auto read() const noexcept -> read_guard
Locks the resource for reading, blocking until the lock is acquired.
Definition rw_lock.hpp:47
Class value_type
Definition rw_lock.hpp:34
auto write() noexcept -> write_guard
Locks the resource for writing, blocking until the lock is acquired.
Definition rw_lock.hpp:55
detail::read_guard< rw_lock > read_guard
Definition rw_lock.hpp:36
Definition algorithm.hpp:12