2015-02-04 05:22:39 +08:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// platform-independant sleep macros
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#ifndef SLEEP_H__
|
|
|
|
#define SLEEP_H__
|
|
|
|
|
2017-03-07 02:11:08 +08:00
|
|
|
#ifdef _WIN32
|
2019-07-13 06:38:30 +08:00
|
|
|
#include <windows.h>
|
|
|
|
#define msleep(n) Sleep(n)
|
2015-02-04 05:22:39 +08:00
|
|
|
#else
|
2019-07-13 06:38:30 +08:00
|
|
|
#include <time.h>
|
|
|
|
#include <errno.h>
|
|
|
|
static void nsleep(uint64_t n) {
|
|
|
|
struct timespec timeout;
|
|
|
|
timeout.tv_sec = n / 1000000000;
|
|
|
|
timeout.tv_nsec = n % 1000000000;
|
|
|
|
while (nanosleep(&timeout, &timeout) && errno == EINTR);
|
|
|
|
}
|
|
|
|
#define msleep(n) nsleep(1000000 * (uint64_t)n)
|
2015-02-04 05:22:39 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif
|