Started splitting out the timer stuff into its own mini-library. Also I decided to drop the fallback stuff, since we run on new enough systems anyway, and nanosleep() is available on every version of macOS we need anyway.
This commit is contained in:
parent
99a0f9084c
commit
5537e823ef
|
@ -64,26 +64,9 @@ extern void testingTFailNow(testingT *t);
|
|||
extern void testingTSkipNow(testingT *t);
|
||||
extern void testingTDefer(testingT *t, void (*f)(testingT *t, void *data), void *data);
|
||||
|
||||
typedef struct testingTimer testingTimer;
|
||||
|
||||
#define testingNsecPerUsec ((int64_t) 1000)
|
||||
#define testingNsecPerMsec ((int64_t) 1000000)
|
||||
#define testingNsecPerSec ((int64_t) 1000000000)
|
||||
|
||||
extern testingTimer *testingNewTimer(void);
|
||||
extern void testingFreeTimer(testingTimer *t);
|
||||
extern void testingTimerStart(testingTimer *t);
|
||||
extern void testingTimerEnd(testingTimer *t);
|
||||
extern int64_t testingTimerNsec(testingTimer *t);
|
||||
|
||||
extern char *testingNsecString(int64_t nsec);
|
||||
extern void testingFreeNsecString(char *s);
|
||||
|
||||
#define testingRunWithTimeout(t, timeout, f, data, comment, failNowOnError) \
|
||||
testingprivRunWithTimeout(t, __FILE__, __LINE__, timeout, f, data, comment, failNowOnError)
|
||||
|
||||
extern void testingSleep(int64_t nsec);
|
||||
|
||||
// TODO I don't like this threading model, but let's use it for now so I can continue working
|
||||
typedef struct testingThread testingThread;
|
||||
extern testingThread *testingNewThread(void (*f)(void *data), void *data);
|
||||
|
|
|
@ -0,0 +1,32 @@
|
|||
// 2 may 2019
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
typedef int64_t timerDuration;
|
||||
typedef int64_t timerTime;
|
||||
|
||||
#define timerNanosecond ((Duration) 1)
|
||||
#define timerMicrosecond ((Duration) 1000)
|
||||
#define timerMillisecond ((Duration) 1000000)
|
||||
#define timerSecond ((Duration) 1000000000)
|
||||
|
||||
extern timerTime timerMonotonicNow(void);
|
||||
extern timerDuration timerTimeSub(timerTime start, timerTime end);
|
||||
|
||||
// The Go algorithm says 32 should be enough.
|
||||
// We use 33 to count the terminating NUL.
|
||||
#define timerTimeStringLen 33
|
||||
|
||||
extern void timerDurationString(timerDuration d, char buf[timerTimeStringLen]);
|
||||
|
||||
typedef uint64_t timerSysError;
|
||||
#ifdef _WIN32
|
||||
#define timerSysErrorFmt "0x%08I32X"
|
||||
#define timerSysErrorArg(x) ((uint32_t) x)
|
||||
#else
|
||||
#include <string.h>
|
||||
#define timerSysErrorFmt "%s (%d)"
|
||||
#define timerSysErrorArg(x) strerror((int) x), ((int) x)
|
||||
#endif
|
||||
|
||||
extern timerSysError timerSleep(timerDuration nsec);
|
Loading…
Reference in New Issue