Last active
December 21, 2022 11:38
-
-
Save bitsmanent/be98dca58b40fabb1e72ad41a09ea3e9 to your computer and use it in GitHub Desktop.
Sleep for a specified number of milliseconds
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
int | |
msleep(int ms) { | |
struct timespec req = {0}, rem; | |
int r = ms / 1000; | |
if(r >= 1) { | |
req.tv_sec = r; | |
ms -= r * 1000; | |
} | |
if(ms) | |
req.tv_nsec = ms * 1000000; | |
while((r = nanosleep(&req, &rem)) == -1 && errno == EINTR) | |
req = rem; | |
return r; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment