-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathvclock.cc
61 lines (53 loc) · 1.35 KB
/
vclock.cc
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
/*
* ===============================================================
* Description: Implementation of vclock
*
* Created: 2014-06-19 13:14:44
*
* Author: Ayush Dubey, [email protected]
*
* Copyright (C) 2013, Cornell University, see the LICENSE file
* for licensing agreement
* ===============================================================
*/
#include "common/vclock.h"
#include "common/config_constants.h"
using vc::vclock;
vclock :: vclock(uint64_t vtid, uint64_t clk_init)
: vt_id(vtid)
, clock(std::vector<uint64_t>(ClkSz, clk_init))
{
assert(vt_id < NumVts || vt_id == UINT64_MAX);
}
vclock :: vclock(uint64_t vtid, vclock_t &vclk)
: vt_id(vtid)
, clock(vclk)
{
assert(vt_id < NumVts || vt_id == UINT64_MAX);
}
void
vclock :: new_epoch(uint64_t new_epoch)
{
assert(clock[0] < new_epoch);
clock = vclock_t(ClkSz, 0);
clock[0] = new_epoch;
}
void
vclock :: update_clock(vc::vclock &other)
{
uint64_t vtid = other.vt_id;
assert(vtid < NumVts);
if (clock[0] == other.clock[0] && clock[vtid+1] < other.clock[vtid+1]) {
clock[vtid+1] = other.clock[vtid+1];
}
}
bool
vclock :: operator==(const vclock &other) const
{
return vt_id == other.vt_id && clock == other.clock;
}
bool
vclock :: operator!=(const vclock &other) const
{
return !(*this==other);
}