-
-
Save qtxie/877ab6cd1f1f239654ebe28435dd5be2 to your computer and use it in GitHub Desktop.
Windows nanosleep
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
#include <windows.h> /* WinAPI */ | |
/* Windows sleep in 100ns units */ | |
BOOLEAN nanosleep(LONGLONG ns){ | |
/* Declarations */ | |
HANDLE timer; /* Timer handle */ | |
LARGE_INTEGER li; /* Time defintion */ | |
/* Create timer */ | |
if(!(timer = CreateWaitableTimer(NULL, TRUE, NULL))) | |
return FALSE; | |
/* Set timer properties */ | |
li.QuadPart = -ns; | |
if(!SetWaitableTimer(timer, &li, 0, NULL, NULL, FALSE)){ | |
CloseHandle(timer); | |
return FALSE; | |
} | |
/* Start & wait for timer */ | |
WaitForSingleObject(timer, INFINITE); | |
/* Clean resources */ | |
CloseHandle(timer); | |
/* Slept without problems */ | |
return TRUE; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment