Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Windows nanosleep
#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;
}
@phuicy

This comment has been minimized.

Copy link

phuicy commented Nov 5, 2015

Awesome

@Janonard

This comment has been minimized.

Copy link

Janonard commented Sep 13, 2016

Thanks alot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.