-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlcb.h
More file actions
44 lines (38 loc) · 1.02 KB
/
lcb.h
File metadata and controls
44 lines (38 loc) · 1.02 KB
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
#include "urb.hpp"
#include <list>
#include <algorithm>
#include <mutex>
#ifndef LCB_H_
#define LCB_H_
class lcb : public deliver_callback { // @suppress("Class has a virtual method and non-virtual destructor")
public:
int lsn;
int vector_clock[MAX_PROCESSES_NUM];
std::mutex vec_m;
std::list<Message>* pending;
std::mutex pen_m;
urb urb_instance;
void init();
void lcb_broadcast(Message message);
void lcb_deliver(Message message);
void deliver(Message message);
};
static bool compare_vector_clocks(int v1[], int v2[]) {
for(int i = 0; i < nb_of_processes; i++) {
if(v1[i] > v2[i]) {
return false;
}
}
return true;
}
struct MessageLCBComp {
bool operator ()(const Message & m1, const Message & m2) {
for(int i = 0; i < nb_of_processes; i++) {
if(m1.vector_clock[i] > m2.vector_clock[i]) {
return false;
}
}
return true;
}
};
#endif /* LCB_H_ */