Skip to content

Commit

Permalink
core: lowres_clock.hh: Reorder class members and add spacing
Browse files Browse the repository at this point in the history
  • Loading branch information
Jesse Haber-Kucharsky committed Jun 19, 2017
1 parent 05de808 commit 34b6807
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions core/lowres_clock.hh
Original file line number Diff line number Diff line change
Expand Up @@ -35,27 +35,33 @@ class lowres_clock;
class lowres_clock_impl final {
public:
typedef std::chrono::steady_clock base_clock;

typedef base_clock::rep rep;
// The lowres_clock's resolution is 10ms. However, to make it is easier to
// do calcuations with std::chrono::milliseconds, we make the clock's
// period to 1ms instead of 10ms.
typedef std::ratio<1, 1000> period;
typedef std::chrono::duration<rep, period> duration;
typedef std::chrono::time_point<lowres_clock, duration> time_point;
lowres_clock_impl();

static time_point now() {
auto nr = _now.load(std::memory_order_relaxed);
return time_point(duration(nr));
}

lowres_clock_impl();
private:
static void update();
// _now is updated by cpu0 and read by other cpus. Make _now on its own
// cache line to avoid false sharing.
alignas(64) static std::atomic<rep> _now;
// High resolution timer to drive this low resolution clock
timer<> _timer;

// High resolution timer expires every 10 milliseconds
static constexpr std::chrono::milliseconds _granularity{10};

// High resolution timer to drive this low resolution clock
timer<> _timer;

static void update();
};

/// \endcond
Expand Down

0 comments on commit 34b6807

Please sign in to comment.