From 07ea73dbc3e71eb68ed6b5c10c6fd83f2357c9f1 Mon Sep 17 00:00:00 2001 From: fireice-uk Date: Fri, 26 May 2017 18:59:49 +0100 Subject: Add the get_key() guard from the other branch --- cli-miner.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'cli-miner.cpp') diff --git a/cli-miner.cpp b/cli-miner.cpp index 2cbe6d9..2f9a635 100644 --- a/cli-miner.cpp +++ b/cli-miner.cpp @@ -155,6 +155,9 @@ int main(int argc, char *argv[]) executor::inst()->ex_start(); + using namespace std::chrono; + uint64_t lastTime = time_point_cast(high_resolution_clock::now()).time_since_epoch().count(); + int key; while(true) { @@ -174,6 +177,13 @@ int main(int argc, char *argv[]) default: break; } + + uint64_t currentTime = time_point_cast(high_resolution_clock::now()).time_since_epoch().count(); + + /* Hard guard to make sure we never get called more than twice per second */ + if( currentTime - lastTime < 500) + std::this_thread::sleep_for(std::chrono::milliseconds(500 - (currentTime - lastTime))); + lastTime = currentTime; } return 0; -- cgit v1.1