rippled
ripple
basics
UptimeClock.h
1
//------------------------------------------------------------------------------
2
/*
3
This file is part of rippled: https://github.com/ripple/rippled
4
Copyright (c) 2012, 2013 Ripple Labs Inc.
5
6
Permission to use, copy, modify, and/or distribute this software for any
7
purpose with or without fee is hereby granted, provided that the above
8
copyright notice and this permission notice appear in all copies.
9
10
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17
*/
18
//==============================================================================
19
20
#ifndef RIPPLE_BASICS_UPTIMETIMER_H_INCLUDED
21
#define RIPPLE_BASICS_UPTIMETIMER_H_INCLUDED
22
23
#include <
atomic
>
24
#include <
chrono
>
25
#include <
ratio
>
26
#include <
thread
>
27
28
namespace
ripple
{
29
37
class
UptimeClock
38
{
39
public
:
40
using
rep
= int;
41
using
period
=
std::ratio<1>
;
42
using
duration
=
std::chrono::duration<rep, period>
;
43
using
time_point
=
std::chrono::time_point<UptimeClock>
;
44
static
constexpr
bool
is_steady
= std::chrono::system_clock::is_steady;
45
46
explicit
UptimeClock
() =
default
;
47
48
static
time_point
49
now
();
// seconds since rippled program start
50
51
private
:
52
static
std::atomic<rep>
now_
;
53
static
std::atomic<bool>
stop_
;
54
55
struct
update_thread
:
private
std::thread
56
{
57
~update_thread
();
58
update_thread
(
update_thread
&&) =
default
;
59
60
using
std::thread::thread
;
61
};
62
63
static
update_thread
64
start_clock
();
65
};
66
67
}
// namespace ripple
68
69
#endif
ripple::UptimeClock::stop_
static std::atomic< bool > stop_
Definition:
UptimeClock.h:53
ripple::UptimeClock::UptimeClock
UptimeClock()=default
std::chrono::duration< rep, period >
ripple::UptimeClock
Tracks program uptime to seconds precision.
Definition:
UptimeClock.h:37
ripple::UptimeClock::update_thread::~update_thread
~update_thread()
Definition:
UptimeClock.cpp:28
ripple::UptimeClock::now
static time_point now()
Definition:
UptimeClock.cpp:63
thread
ratio
chrono
ripple::UptimeClock::is_steady
static constexpr bool is_steady
Definition:
UptimeClock.h:44
std::chrono::time_point
atomic
ripple::UptimeClock::update_thread
Definition:
UptimeClock.h:55
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition:
RCLCensorshipDetector.h:29
ripple::UptimeClock::rep
int rep
Definition:
UptimeClock.h:40
ripple::UptimeClock::now_
static std::atomic< rep > now_
Definition:
UptimeClock.h:52
ripple::UptimeClock::update_thread::update_thread
update_thread(update_thread &&)=default
ripple::UptimeClock::start_clock
static update_thread start_clock()
Definition:
UptimeClock.cpp:41
Generated by
1.8.17