Experimental new redoconf C/C++ build/autoconfiguration system.
To test it out, try this: ./do -j10 build cd docs/cookbook/c redo -j10 test It should detect all the compilers on your system and make three separate builds for each one: normal, debug, and optimized. Then it tries to run a test program under each one. If there are windows cross compilers and you also have 'wine' installed, it'll try running the test program under wine as well. redoconf currently has no documentation other than the example program. We'll fix that later.
This commit is contained in:
parent
5db883ac58
commit
6dae51f4d2
67 changed files with 1777 additions and 1 deletions
58
docs/cookbook/c/monotime.c
Normal file
58
docs/cookbook/c/monotime.c
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
#define __GNU_SOURCE
|
||||
/*
|
||||
* Returns the kernel monotonic timestamp in microseconds.
|
||||
* This function never returns the value 0; it returns 1 instead, so that
|
||||
* 0 can be used as a magic value.
|
||||
*/
|
||||
#include "monotime.h"
|
||||
#include "redoconf.h"
|
||||
|
||||
#if HAVE_CLOCK_GETTIME
|
||||
|
||||
#include <time.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
long long monotime(void) {
|
||||
struct timespec ts;
|
||||
if (clock_gettime(CLOCK_MONOTONIC, &ts) < 0) {
|
||||
perror("clock_gettime");
|
||||
exit(98); /* really should never happen, so don't try to recover */
|
||||
}
|
||||
long long result = ts.tv_sec * 1000000LL + ts.tv_nsec / 1000;
|
||||
return !result ? 1 : result;
|
||||
}
|
||||
|
||||
#elif HAVE_MACH_TIME_H
|
||||
|
||||
#include <mach/mach.h>
|
||||
#include <mach/mach_time.h>
|
||||
|
||||
long long monotime(void) {
|
||||
static mach_timebase_info_data_t timebase;
|
||||
if (!timebase.denom) mach_timebase_info(&timebase);
|
||||
long long result = (mach_absolute_time() * timebase.numer /
|
||||
timebase.denom / 1000);
|
||||
return !result ? 1 : result;
|
||||
}
|
||||
|
||||
#elif HAVE_WINDOWS_H
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
/* WARNING: Not carefully tested. It might wrap around unexpectedly.
|
||||
* Based on suggestions from:
|
||||
* https://stackoverflow.com/questions/211257/windows-monotonic-clock
|
||||
*/
|
||||
long long monotime(void) {
|
||||
LARGE_INTEGER tps, t;
|
||||
QueryPerformanceFrequency(&tps);
|
||||
QueryPerformanceCounter(&t);
|
||||
return t.QuadPart * 1000000LL / tps.QuadPart;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
#error "No monotonic time function is available"
|
||||
|
||||
#endif
|
||||
Loading…
Add table
Add a link
Reference in a new issue