mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-19 02:25:52 +00:00
Per XLS-0095, we are taking steps to rename ripple(d) to xrpl(d). This change specifically removes all copyright notices referencing Ripple, XRPLF, and certain affiliated contributors upon mutual agreement, so the notice in the LICENSE.md file applies throughout. Copyright notices referencing external contributions remain as-is. Duplicate verbiage is also removed.
51 lines
1.1 KiB
C++
51 lines
1.1 KiB
C++
#ifndef XRPL_BASICS_UPTIMETIMER_H_INCLUDED
|
|
#define XRPL_BASICS_UPTIMETIMER_H_INCLUDED
|
|
|
|
#include <atomic>
|
|
#include <chrono>
|
|
#include <ratio>
|
|
#include <thread>
|
|
|
|
namespace ripple {
|
|
|
|
/** Tracks program uptime to seconds precision.
|
|
|
|
The timer caches the current time as a performance optimization.
|
|
This allows clients to query the current time thousands of times
|
|
per second.
|
|
*/
|
|
|
|
class UptimeClock
|
|
{
|
|
public:
|
|
using rep = int;
|
|
using period = std::ratio<1>;
|
|
using duration = std::chrono::duration<rep, period>;
|
|
using time_point = std::chrono::time_point<UptimeClock>;
|
|
static constexpr bool is_steady = std::chrono::system_clock::is_steady;
|
|
|
|
explicit UptimeClock() = default;
|
|
|
|
static time_point
|
|
now(); // seconds since rippled program start
|
|
|
|
private:
|
|
static std::atomic<rep> now_;
|
|
static std::atomic<bool> stop_;
|
|
|
|
struct update_thread : private std::thread
|
|
{
|
|
~update_thread();
|
|
update_thread(update_thread&&) = default;
|
|
|
|
using std::thread::thread;
|
|
};
|
|
|
|
static update_thread
|
|
start_clock();
|
|
};
|
|
|
|
} // namespace ripple
|
|
|
|
#endif
|