Idris2/support/refc/clock.c
madman-bob 98d67499db
RefC Integer Support (#1480)
* Add utility functions to treat All as a heterogeneous container
* Distinguish RefC Int and Bits types
* Change RefC Integers to be arbitrary precision
* Add RefC Bits maths operations
* Make RefC div and mod Euclidean
* Add RefC bit-ops tests
* Add RefC integer comparison tests
* Add RefC IntN support
2021-06-03 10:44:42 +01:00

53 lines
869 B
C

#include "clock.h"
#define NSEC_PER_SEC 1000000000
#define CLOCKS_PER_NSEC ((float)(CLOCKS_PER_SEC / NSEC_PER_SEC))
Value *clockTimeMonotonic()
{
return clockTimeUtc();
}
Value *clockTimeUtc()
{
return (Value *)makeBits64(time(NULL) * NSEC_PER_SEC);
}
Value *clockTimeProcess()
{
uint64_t time_ns = clock() / CLOCKS_PER_NSEC;
return (Value *)makeBits64(time_ns);
}
Value *clockTimeThread()
{
return clockTimeProcess();
}
Value *clockTimeGcCpu()
{
return NULL;
}
Value *clockTimeGcReal()
{
return NULL;
}
int clockValid(Value *clock)
{
return clock != NULL;
}
uint64_t clockSecond(Value *clock)
{
uint64_t totalNano = ((Value_Bits64 *)clock)->ui64;
return totalNano / NSEC_PER_SEC;
}
uint64_t clockNanosecond(Value *clock)
{
uint64_t totalNano = ((Value_Bits64 *)clock)->ui64;
return totalNano % NSEC_PER_SEC;
}