Created
January 11, 2016 00:13
-
-
Save rzezeski/75ba1ccd9783f4f028ba to your computer and use it in GitHub Desktop.
spin sleep
This file contains hidden or 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
uint64_t | |
sl_getnsecs() | |
{ | |
struct timespec ts; | |
(void) clock_gettime(CLOCK_MONOTONIC, &ts); | |
return (((uint64_t)ts.tv_sec * 1000000000L) + ts.tv_nsec); | |
} | |
/* | |
* Spin until approximately ns nanoseconds have passed. The ns value | |
* must be at least 1 nanosecond. | |
*/ | |
static void | |
sl_spin(uint64_t ns) | |
{ | |
uint64_t passed = 0; | |
uint64_t start = sl_getnsecs(); | |
assert(ns > 0); | |
while (passed < ns) | |
passed = (sl_getnsecs()) - start; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment