Botcraft 1.21.5
Loading...
Searching...
No Matches
ScopeLockedWrapper.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <mutex>
4
6{
7 /// @brief Mutex protected reference, will be locked until destroyed
8 /// @tparam T Class to store
9 /// @tparam Mutex Mutex type to use
10 /// @tparam Lock Lock type to use
11 template<
12 class T,
13 class Mutex = std::mutex,
14 template<class...> class Lock = std::scoped_lock
15 >
17 {
18 public:
19 ScopeLockedWrapper(T& val, Mutex& mutex) : v(val), lock(mutex) { }
20
21 T* operator->() const { return &v; }
22 T& operator*() const { return v; }
23 private:
24 T& v;
25 Lock<Mutex> lock;
26 };
27}
Mutex protected reference, will be locked until destroyed.