Add a clock which gives deltas when polled
This commit is contained in:
parent
6ace3c8b1d
commit
9ff59f8130
19
time.cpp
19
time.cpp
@ -27,8 +27,8 @@
|
||||
|
||||
using namespace util;
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
#ifdef PLATFORM_WIN32
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
uint64_t
|
||||
@ -48,7 +48,6 @@ util::sleep (uint64_t ns) {
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
#include <ctime>
|
||||
|
||||
uint64_t
|
||||
@ -74,10 +73,24 @@ util::sleep (uint64_t ns) {
|
||||
req = rem;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
delta_clock::delta_clock():
|
||||
time { util::nanoseconds (), util::nanoseconds () }
|
||||
{ ; }
|
||||
|
||||
|
||||
double
|
||||
delta_clock::seconds (void) {
|
||||
time.prev = time.curr;
|
||||
time.curr = nanoseconds ();
|
||||
|
||||
return (time.curr - time.prev) / 1000000000.0;
|
||||
}
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
util::polled_duration::polled_duration (std::string name, uint64_t interval):
|
||||
m_name (name),
|
||||
m_interval (interval),
|
||||
|
15
time.hpp
15
time.hpp
@ -26,9 +26,24 @@
|
||||
#include "stats.hpp"
|
||||
|
||||
namespace util {
|
||||
// ------------------------------------------------------------------------
|
||||
uint64_t nanoseconds (void);
|
||||
void sleep (uint64_t ns);
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
class delta_clock {
|
||||
public:
|
||||
delta_clock ();
|
||||
double seconds (void);
|
||||
|
||||
protected:
|
||||
struct {
|
||||
uint64_t prev;
|
||||
uint64_t curr;
|
||||
} time;
|
||||
};
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
class polled_duration {
|
||||
public:
|
||||
polled_duration (std::string name, uint64_t interval);
|
||||
|
Loading…
Reference in New Issue
Block a user