Derecho  0.9
Distributed systems toolkit for RDMA
HLC.hpp
Go to the documentation of this file.
1 #ifndef HLC_HPP
2 #define HLC_HPP
3 #include <inttypes.h>
4 #include <pthread.h>
5 #include <sys/types.h>
6 
7 class HLC {
8 private:
9  pthread_spinlock_t m_oLck; // spinlock
10 
11 public:
12  uint64_t m_rtc_us; // real-time clock in microseconds
13  uint64_t m_logic; // logic clock
14 
15  // constructors
16  HLC()
17  noexcept(false);
18 
19  HLC(uint64_t _r, uint64_t _l);
20 
21  // destructors
22  virtual ~HLC() noexcept(false);
23 
24  // ticking method - thread safe
25  virtual void tick(bool thread_safe = true) noexcept(false);
26  virtual void tick(const HLC& msgHlc, bool thread_safe = true) noexcept(false);
27 
28  // comparators
29  virtual bool operator>(const HLC& hlc) const noexcept(true);
30  virtual bool operator<(const HLC& hlc) const noexcept(true);
31  virtual bool operator==(const HLC& hlc) const noexcept(true);
32  virtual bool operator>=(const HLC& hlc) const noexcept(true);
33  virtual bool operator<=(const HLC& hlc) const noexcept(true);
34 
35  // evaluator
36  virtual void operator=(const HLC& hlc) noexcept(true);
37 };
38 
39 #define HLC_EXP(errcode, usercode) \
40  ((((errcode)&0xffffffffull) << 32) | ((usercode)&0xffffffffull))
41 #define HLC_EXP_USERCODE(x) ((uint32_t)((x)&0xffffffffull))
42 #define HLC_EXP_READ_RTC(x) HLC_EXP(0, (x))
43 #define HLC_EXP_SPIN_INIT(x) HLC_EXP(1, (x))
44 #define HLC_EXP_SPIN_DESTROY(x) HLC_EXP(2, (x))
45 #define HLC_EXP_SPIN_LOCK(x) HLC_EXP(3, (x))
46 #define HLC_EXP_SPIN_UNLOCK(x) HLC_EXP(4, (x))
47 
48 // read the rtc clock in microseconds
49 uint64_t read_rtc_us() noexcept(false);
50 
51 #endif //HLC_HPP
pthread_spinlock_t m_oLck
Definition: HLC.hpp:9
HLC(uint64_t _r, uint64_t _l)
Definition: HLC.cpp:15
Definition: HLC.hpp:7
virtual void tick(bool thread_safe=true) noexcept(false)
Definition: HLC.cpp:44
noexcept(false)
uint64_t read_rtc_us() noexcept(false)
Definition: HLC.cpp:6
uint64_t m_logic
Definition: HLC.hpp:13
uint64_t m_rtc_us
Definition: HLC.hpp:12