Joedb 10.2.1
The Journal-Only Embedded Database
Loading...
Searching...
No Matches
Thread_Safe.h
Go to the documentation of this file.
1#ifndef joedb_Thread_Safe_declared
2#define joedb_Thread_Safe_declared
3
4#include <mutex>
5
6namespace joedb
7{
8 template<typename T> class Lock;
9
10 template<typename T> class Thread_Safe
11 {
12 friend class Lock<T>;
13
14 private:
15 std::mutex mutex;
16 T t;
17
18 public:
19 template<class... Arguments> Thread_Safe(Arguments &&... a): t(a...)
20 {
21 }
22 };
23
24 template<typename T> class Lock
25 {
26 private:
27 std::unique_lock<std::mutex> lock;
28 T t;
29
30 public:
31 Lock(Thread_Safe<T> &t): lock(t.mutex), t(t.t)
32 {
33 }
34
35 operator std::unique_lock<std::mutex> &() {return lock;}
36
37 auto *operator->() const {return &t;}
38 auto *operator->() {return &t;}
39 auto &operator*() const {return t;}
40 auto &operator*() {return t;}
41 };
42}
43
44#endif
Class for conveniently parsing command-line arguments.
Definition Arguments.h:19
auto & operator*() const
Definition Thread_Safe.h:39
Lock(Thread_Safe< T > &t)
Definition Thread_Safe.h:31
auto & operator*()
Definition Thread_Safe.h:40
auto * operator->() const
Definition Thread_Safe.h:37
auto * operator->()
Definition Thread_Safe.h:38
Thread_Safe(Arguments &&... a)
Definition Thread_Safe.h:19