-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #45 from daltonrpruitt/cross-platform-ify
Cross-platform-ify
- Loading branch information
Showing
32 changed files
with
397 additions
and
198 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/** | ||
* @file clock_gettime_windows.h | ||
* @author Dalton Winans-Pruitt ([email protected]) | ||
* @brief Uses a SO post about porting the clock_gettime() function | ||
* @version 0.1 | ||
* @date 2022-09-17 | ||
* | ||
* Based on https://stackoverflow.com/questions/5404277/porting-clock-gettime-to-windows, | ||
* which seems to be the established answer to this problem. | ||
* Also, this is only relevant due to trying to run on Windows. | ||
* | ||
* @copyright Copyright (c) 2022 | ||
* | ||
*/ | ||
#include <windows.h> | ||
#include <time.h> | ||
|
||
LARGE_INTEGER | ||
getFILETIMEoffset() | ||
{ | ||
SYSTEMTIME s; | ||
FILETIME f; | ||
LARGE_INTEGER t; | ||
|
||
s.wYear = 1970; | ||
s.wMonth = 1; | ||
s.wDay = 1; | ||
s.wHour = 0; | ||
s.wMinute = 0; | ||
s.wSecond = 0; | ||
s.wMilliseconds = 0; | ||
SystemTimeToFileTime(&s, &f); | ||
t.QuadPart = f.dwHighDateTime; | ||
t.QuadPart <<= 32; | ||
t.QuadPart |= f.dwLowDateTime; | ||
return (t); | ||
} | ||
|
||
int | ||
clock_gettime(int X, struct timespec *tv) | ||
{ | ||
LARGE_INTEGER t; | ||
FILETIME f; | ||
double microseconds; | ||
static LARGE_INTEGER offset; | ||
static double frequencyToMicroseconds; | ||
static int initialized = 0; | ||
static BOOL usePerformanceCounter = 0; | ||
|
||
if (!initialized) { | ||
LARGE_INTEGER performanceFrequency; | ||
initialized = 1; | ||
usePerformanceCounter = QueryPerformanceFrequency(&performanceFrequency); | ||
if (usePerformanceCounter) { | ||
QueryPerformanceCounter(&offset); | ||
frequencyToMicroseconds = (double)performanceFrequency.QuadPart / 1000000.; | ||
} else { | ||
offset = getFILETIMEoffset(); | ||
frequencyToMicroseconds = 10.; | ||
} | ||
} | ||
if (usePerformanceCounter) QueryPerformanceCounter(&t); | ||
else { | ||
GetSystemTimeAsFileTime(&f); | ||
t.QuadPart = f.dwHighDateTime; | ||
t.QuadPart <<= 32; | ||
t.QuadPart |= f.dwLowDateTime; | ||
} | ||
|
||
t.QuadPart -= offset.QuadPart; | ||
microseconds = (double)t.QuadPart / frequencyToMicroseconds; | ||
t.QuadPart = microseconds; | ||
tv->tv_sec = t.QuadPart / 1000000; | ||
tv->tv_nsec = t.QuadPart % 1000000 * 1000; | ||
return (0); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.