forked from efficient/cicada-exp-sigmod2017-silo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ownership_checker.h
48 lines (43 loc) · 1.03 KB
/
ownership_checker.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#pragma once
#include <vector>
#include "macros.h"
/**
* T - node type. needs to implement is_lock_owner()
*/
template <typename Scope, typename T>
class ownership_checker {
public:
static void
NodeLockRegionBegin()
{
MyLockedNodes(true)->clear();
}
// is used to signal the end of a tuple lock region
static void
AssertAllNodeLocksReleased()
{
std::vector<const T *> *nodes = MyLockedNodes(false);
ALWAYS_ASSERT(nodes);
for (auto p : *nodes)
ALWAYS_ASSERT(!p->is_lock_owner());
nodes->clear();
}
static void
AddNodeToLockRegion(const T *n)
{
ALWAYS_ASSERT(n->is_locked());
ALWAYS_ASSERT(n->is_lock_owner());
std::vector<const T *> *nodes = MyLockedNodes(false);
if (nodes)
nodes->push_back(n);
}
private:
static std::vector<const T *> *
MyLockedNodes(bool create)
{
static __thread std::vector<const T *> *tl_locked_nodes = nullptr;
if (unlikely(!tl_locked_nodes) && create)
tl_locked_nodes = new std::vector<const T *>;
return tl_locked_nodes;
}
};