taco-db
0.1.0
utils
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
12
struct
MutexReleaseFunc
{
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
:
25
MutexGuard
():
26
ResourceGuard
() {}
27
28
MutexGuard
(std::mutex *m):
29
ResourceGuard
(
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
taco::MutexGuard
MutexGuard is similar to std::lock_guard but it stores a pointer to a mutex and allows one to store a...
Definition:
MutexGuard.h:22
taco
Definition:
datum.h:28
taco::MutexReleaseFunc
Definition:
MutexGuard.h:12
taco::MutexGuard::MutexGuard
MutexGuard(std::mutex *m)
Definition:
MutexGuard.h:28
taco::MutexGuard::MutexGuard
MutexGuard()
Definition:
MutexGuard.h:25
tdb.h
taco::ResourceGuard
ResourceGuard is used for automatically relinquishes some resource when it goes out of scope.
Definition:
ResourceGuard.h:72
taco::MutexReleaseFunc::operator()
void operator()(std::mutex *m) const
Definition:
MutexGuard.h:13
ResourceGuard.h
Generated by
1.8.17