os_sleep: Use nanosleep for POSIX versions 2008 and higher
uClibc-ng optionally disabled deprecated POSIX functions like usleep, causing compilation failures. This switches to nanosleep while retaining support for older libcs that do not support nanosleep. Signed-off-by: Rosen Penev <rosenp@gmail.com>
This commit is contained in:
parent
a69742c2f8
commit
39042d7f7c
2 changed files with 12 additions and 0 deletions
|
@ -25,10 +25,16 @@
|
||||||
|
|
||||||
void os_sleep(os_time_t sec, os_time_t usec)
|
void os_sleep(os_time_t sec, os_time_t usec)
|
||||||
{
|
{
|
||||||
|
#if defined(_POSIX_C_SOURCE) && (_POSIX_C_SOURCE >= 200809L)
|
||||||
|
const struct timespec req = { sec, usec * 1000 };
|
||||||
|
|
||||||
|
nanosleep(&req, NULL);
|
||||||
|
#else
|
||||||
if (sec)
|
if (sec)
|
||||||
sleep(sec);
|
sleep(sec);
|
||||||
if (usec)
|
if (usec)
|
||||||
usleep(usec);
|
usleep(usec);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -49,10 +49,16 @@ struct os_alloc_trace {
|
||||||
|
|
||||||
void os_sleep(os_time_t sec, os_time_t usec)
|
void os_sleep(os_time_t sec, os_time_t usec)
|
||||||
{
|
{
|
||||||
|
#if defined(_POSIX_C_SOURCE) && (_POSIX_C_SOURCE >= 200809L)
|
||||||
|
const struct timespec req = { sec, usec * 1000 };
|
||||||
|
|
||||||
|
nanosleep(&req, NULL);
|
||||||
|
#else
|
||||||
if (sec)
|
if (sec)
|
||||||
sleep(sec);
|
sleep(sec);
|
||||||
if (usec)
|
if (usec)
|
||||||
usleep(usec);
|
usleep(usec);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue