mirror of
https://github.com/gnif/LookingGlass.git
synced 2025-10-20 14:28:09 +00:00
[all] moved time and locking methods to the common library
This commit is contained in:
@@ -25,9 +25,10 @@ Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
#include <windows.h>
|
||||
#else
|
||||
#include <time.h>
|
||||
#include <stdint.h>
|
||||
#endif
|
||||
|
||||
static inline uint64_t getMicrotime()
|
||||
static inline uint64_t microtime()
|
||||
{
|
||||
#if defined(_WIN32)
|
||||
static LARGE_INTEGER freq = { 0 };
|
||||
@@ -42,4 +43,24 @@ static inline uint64_t getMicrotime()
|
||||
clock_gettime(CLOCK_MONOTONIC, &time);
|
||||
return (uint64_t)time.tv_sec * 1000000LL + time.tv_nsec / 1000LL;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
#if !defined(_WIN32)
|
||||
//FIXME: make win32 versions
|
||||
static inline uint64_t nanotime()
|
||||
{
|
||||
struct timespec time;
|
||||
clock_gettime(CLOCK_MONOTONIC_RAW, &time);
|
||||
return ((uint64_t)time.tv_sec * 1e9) + time.tv_nsec;
|
||||
}
|
||||
|
||||
static inline void nsleep(uint64_t ns)
|
||||
{
|
||||
const struct timespec ts =
|
||||
{
|
||||
.tv_sec = ns / 1e9,
|
||||
.tv_nsec = ns - ((ns / 1e9) * 1e9)
|
||||
};
|
||||
nanosleep(&ts, NULL);
|
||||
}
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user