-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathSync.h
73 lines (52 loc) · 1.12 KB
/
Sync.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#pragma once
#include "Ctu.h"
class Waitable : public KObject {
public:
Waitable();
void acquire();
void release();
void wait(function<int()> cb);
virtual void wait(function<int(bool)> cb);
void signal(bool one=false);
void cancel();
virtual void close() override {}
protected:
virtual bool presignalable() { return true; }
private:
recursive_mutex lock;
list<function<int(bool)>> waiters;
bool presignaled, canceled;
};
class InstantWaitable : public Waitable {
public:
virtual void wait(function<int(bool)> cb) {
Waitable::wait(cb);
signal(true);
}
};
class Semaphore : public Waitable {
public:
Semaphore(Guest<uint32_t> _vptr);
void increment();
void decrement();
uint32_t value();
protected:
bool presignalable() override { return false; }
private:
Guest<uint32_t> vptr;
};
class Mutex : public Waitable {
public:
Mutex(Guest<uint32_t> _vptr);
uint32_t value();
void value(uint32_t val);
ghandle owner();
void owner(ghandle val);
bool hasWaiters();
void hasWaiters(bool val);
void guestRelease();
protected:
bool presignalable() override { return false; }
private:
Guest<uint32_t> vptr;
};