| e8555c89 Andy McCall |
1 |
#include "Timer.hh" |
| 2 |
|
| 3 |
#include <chrono> |
| 4 |
#include <thread> |
| 5 |
|
| 6 |
namespace openmsx::Timer { |
| 7 |
|
| 8 |
uint64_t getTime() |
| 9 |
{ |
| 10 |
static uint64_t lastTime = 0; |
| 11 |
|
| 12 |
using namespace std::chrono; |
| 13 |
uint64_t now = duration_cast<microseconds>( |
| 14 |
steady_clock::now().time_since_epoch()).count(); |
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
if (now < lastTime) return lastTime; |
| 24 |
lastTime = now; |
| 25 |
return now; |
| 26 |
} |
| 27 |
|
| 28 |
void sleep(uint64_t us) |
| 29 |
{ |
| 30 |
std::this_thread::sleep_for(std::chrono::microseconds(us)); |
| 31 |
} |
| 32 |
|
| 33 |
} |