-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclock_failure.h
61 lines (45 loc) · 1.4 KB
/
clock_failure.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
#ifndef _CLOCK_FAILURE
#define _CLOCK_FAILURE
#include"clock_sync.h"
/*
clock_failure.cpp provides a wrapper for clock_sync.cpp to support failure handling. You can use clock_sync.cpp purely if there is no need for failure recovery.
*/
// the failure-resistant timer
class fr_timer{
public:
void init(int local_port, int id1, int id2);
void failure_handle();
ts_t get_timestamp(int* state);
void finalize();
GlobalTimer* current_timer;
GlobalTimer* backup_timer;
ts_t virtual_x[2];
ts_t virtual_y[2];
double k;
ts_t shift;
ts_t switch_delta;
pthread_t f_thread;
int state; // -1 for warmuping of current, 0 for current timer, 1 for virutal time, 2 for smoothing phase, 3 for backup timer
int timer_id;
char backup_ip[64];
};
// this contains the previous root and backup root. An offset is calculated after failure, and this will be send to fr_timer as a fixed value
class fr_root{
public:
GlobalTimer* current_timer;
GlobalTimer* backup_timer;
void run(); // we assign port and NODE id in function
void failure_handle();
void finalize();
ts_t offset; // the clock offset when previous root fails
pthread_t t[2];
};
// the center of fr-timer.
// We don't take into account the failure of fr-center
class fr_center{
public:
void run();
void build_current_connect();
void build_backup_connect();
};
#endif