Fix timer
This commit is contained in:
parent
6c2aaf897a
commit
ed188fd21c
1 changed files with 12 additions and 8 deletions
|
@ -7,11 +7,12 @@
|
|||
|
||||
typedef std::chrono::duration<int, std::milli> milliseconds_type;
|
||||
|
||||
class Counter {
|
||||
class Counter
|
||||
{
|
||||
private:
|
||||
int max;
|
||||
int n;
|
||||
std::chrono::_V2::system_clock::time_point last_time;
|
||||
std::chrono::system_clock::time_point last_time;
|
||||
milliseconds_type update_interval;
|
||||
|
||||
public:
|
||||
|
@ -24,16 +25,19 @@ public:
|
|||
|
||||
~Counter() {}
|
||||
|
||||
int get_counter() {
|
||||
int get_counter()
|
||||
{
|
||||
auto new_time = std::chrono::high_resolution_clock::now();
|
||||
milliseconds_type time_difference = std::chrono::duration_cast<milliseconds_type>(new_time - last_time);
|
||||
|
||||
if (time_difference.count() >= update_interval.count()) {
|
||||
if (time_difference.count() >= update_interval.count())
|
||||
{
|
||||
last_time += update_interval;
|
||||
|
||||
n++;
|
||||
|
||||
if (n >= max) {
|
||||
if (n >= max)
|
||||
{
|
||||
n = n - max;
|
||||
abort();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue