-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgstm.hh
77 lines (56 loc) · 2.24 KB
/
gstm.hh
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
74
75
76
77
#ifndef GSTM_HH_
#define GSTM_HH_
#include <pthread.h>
#include <signal.h>
#include <functional>
#include <unordered_map>
#include <unordered_set>
#include "private_alloc.hh"
#include "share_alloc.hh"
// An internal class that provides useful utility functions for GThread to use
class Gstm {
friend class GThread;
public:
Gstm() = delete;
// An unordered_map that uses a custom allocator for private memory only
using share_mapping_t =
std::unordered_map<void*, size_t, std::hash<void*>, std::equal_to<void*>,
ShareAllocator<std::pair<void*, size_t>>>;
// An unordered_map that uses a custom allocator for share memory only
using private_mapping_t =
std::unordered_map<void*, size_t, std::hash<void*>, std::equal_to<void*>,
PrivateAllocator<std::pair<void*, size_t>>>;
// Initialize the internal system
static void Initialize();
// Wait until predecessor exited
static void WaitExited(pid_t predecessor);
// Checks whether local heap is concsistent with global heap
static bool IsHeapConsistent();
// Commit local heap view into global heap
static void CommitHeap();
// Handle segfaults
static void SegfaultHandler(int signal, siginfo_t* info, void* ctx);
// Keep track of how many rollbacks happened for the entire program
static size_t* rollback_count_;
private:
// Handle reads and writes when a segfault happens
static void HandleReads(void* page);
static void HandleWrites(void* page);
// Set up an inter-process mutex
static void SetupInterProcessMutex();
// Initialize both local and shared states being tracked by the system
static void InitMapping();
// Update the local view of memory to match the global view
static void UpdateHeap();
// A cross-process mutex that synchronizes the commit stage
static pthread_mutex_t* mutex;
// Reads and writes happened in current process
static private_mapping_t* read_set_version;
static private_mapping_t* write_set_version;
// a local view of each page's version
static private_mapping_t* local_page_version;
// A global process-shared view of each page's version
static share_mapping_t*
global_page_version; // A global process-shared page version mapping
};
#endif // GSTM_HH_