-
Notifications
You must be signed in to change notification settings - Fork 0
/
comm_seq.h
84 lines (67 loc) · 1.49 KB
/
comm_seq.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
74
75
76
77
78
79
80
81
82
83
/*
* File: comm_window.h
* Author: agung
*
* Created on February 18, 2018, 5:04 PM
*/
#ifndef COMM_SEQ_H
#define COMM_SEQ_H
#include <sys/types.h>
//#include <unordered_map>
//#include <vector>
//define MAXTHREADS 512
//static const int CMAXTHREADS = MAXTHREADS;
#define MAX_SEQ 1000000000
class CommSeq {
private:
PIN_MUTEX mtx;
public:
UINT32 first;
UINT32 second;
CommSeq() {
first = 0;
second = 0;
PIN_MutexInit(&mtx);
}
~CommSeq() {
PIN_MutexFini(&mtx);
}
/**
* Update method is synchronized,
* because the update() and get() can be called from many threads simultaneously.
* @param tid
*/
void update(THREADID tid) {
PIN_MutexLock(&mtx);
THREADID tmp = first;
first = tid;
second = tmp;
PIN_MutexUnlock(&mtx);
}
};
class CommSequences {
private:
//PIN_MUTEX mapLock;
//CommSeq sequences[MAX_SEQ];
CommSeq* sequences;
//vector<CommSeq> sequences;
//unordered_map<UINT64, size_t> regionMap;
public:
CommSequences() {
}
~CommSequences() {
//PIN_MutexFini(&mapLock);
if (sequences != NULL)
delete[] sequences;
}
void init(UINT64 size) {
sequences = new CommSeq[size];
}
void insert(UINT64 line, THREADID tid) {
sequences[line].update(tid);
}
CommSeq getSeq(UINT64 line) {
return sequences[line];
}
};
#endif /* COMM_SEQ_H */