2019-05-02 11:13:29 -05:00
|
|
|
// 2 may 2019
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
|
|
|
|
typedef int64_t timerDuration;
|
|
|
|
typedef int64_t timerTime;
|
|
|
|
|
2019-05-02 21:03:57 -05:00
|
|
|
#define timerNanosecond ((timerDuration) 1)
|
|
|
|
#define timerMicrosecond ((timerDuration) 1000)
|
|
|
|
#define timerMillisecond ((timerDuration) 1000000)
|
|
|
|
#define timerSecond ((timerDuration) 1000000000)
|
2019-05-02 11:13:29 -05:00
|
|
|
|
|
|
|
extern timerTime timerMonotonicNow(void);
|
2019-05-02 11:38:59 -05:00
|
|
|
extern timerDuration timerTimeSub(timerTime end, timerTime start);
|
2019-05-02 11:13:29 -05:00
|
|
|
|
|
|
|
// The Go algorithm says 32 should be enough.
|
|
|
|
// We use 33 to count the terminating NUL.
|
2019-05-02 11:38:59 -05:00
|
|
|
#define timerDurationStringLen 33
|
|
|
|
extern void timerDurationString(timerDuration d, char buf[timerDurationStringLen]);
|
2019-05-02 11:13:29 -05:00
|
|
|
|
|
|
|
typedef uint64_t timerSysError;
|
|
|
|
#ifdef _WIN32
|
|
|
|
#define timerSysErrorFmt "0x%08I32X"
|
2019-05-03 01:02:20 -05:00
|
|
|
#define timerSysErrorFmtArg(x) ((uint32_t) x)
|
2019-05-02 11:13:29 -05:00
|
|
|
#else
|
|
|
|
#include <string.h>
|
|
|
|
#define timerSysErrorFmt "%s (%d)"
|
2019-05-03 01:02:20 -05:00
|
|
|
#define timerSysErrorFmtArg(x) strerror((int) x), ((int) x)
|
2019-05-02 11:13:29 -05:00
|
|
|
#endif
|
|
|
|
|
2019-05-02 22:15:49 -05:00
|
|
|
extern timerSysError timerRunWithTimeout(timerDuration d, void (*f)(void *data), void *data, int *timedOut);
|
|
|
|
|
|
|
|
extern timerSysError timerSleep(timerDuration d);
|