-
Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy pathlockwrap.hh
More file actions
56 lines (45 loc) · 745 Bytes
/
Copy pathlockwrap.hh
File metadata and controls
56 lines (45 loc) · 745 Bytes
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
49
50
51
52
53
54
55
56
#pragma once
#include "seqlock.hh"
template<typename T>
class ptr_wrap
{
public:
ptr_wrap(T* ptr) : ptr_(ptr) {}
T* operator->() const {
return ptr_;
}
T& operator*() const {
return *ptr_;
}
private:
T* ptr_;
};
template<typename T>
class seq_reader
{
public:
seq_reader(const T* v, const seqcount<u32>* seq) {
for (;;) {
auto r = seq->read_begin();
state_ = *v;
if (!r.need_retry())
return;
}
}
const T* operator->() const {
return &state_;
}
const T& operator*() const {
return state_;
}
private:
T state_;
};
class seq_writer
{
public:
seq_writer(seqcount<u32>* seq) : w_(seq->write_begin()) {}
seq_writer() {}
private:
seqcount<u32>::writer w_;
};