taco-db  0.1.0
MutexGuard.h
Go to the documentation of this file.
1 #ifndef UTILS_MUTEXGUARD_H
2 #define UTILS_MUTEXGUARD_H
3 
4 #include "tdb.h"
5 
6 #include <mutex>
7 
8 #include "utils/ResourceGuard.h"
9 
10 namespace taco {
11 
13  void operator()(std::mutex* m) const {
14  m->unlock();
15  }
16 };
17 
22 class MutexGuard: public ResourceGuard<std::mutex*, MutexReleaseFunc,
23  std::mutex*, nullptr> {
24 public:
26  ResourceGuard() {}
27 
28  MutexGuard(std::mutex *m):
30  // make sure we lock the mutex first before we pass it to the
31  // ResourceGuard
32  m ? (m->lock(), m) : nullptr
33  ) {}
34 };
35 
36 } // namespace taco
37 
38 #endif // UTILS_MUTEXGUARD_H
MutexGuard is similar to std::lock_guard but it stores a pointer to a mutex and allows one to store a...
Definition: MutexGuard.h:23
MutexGuard(std::mutex *m)
Definition: MutexGuard.h:28
MutexGuard()
Definition: MutexGuard.h:25
ResourceGuard is used for automatically relinquishes some resource when it goes out of scope.
Definition: ResourceGuard.h:72
Definition: datum.h:28
Definition: MutexGuard.h:12
void operator()(std::mutex *m) const
Definition: MutexGuard.h:13