diff --git a/libflow.c b/libflow.c index 89ac5cf..5efe3ff 100644 --- a/libflow.c +++ b/libflow.c @@ -6,7 +6,6 @@ #include #include #include -#include #include #include "libflow.h" @@ -205,37 +204,6 @@ static inline int flush_chunk(const struct flow *fw, int fd) return 0; } -static void msleep(double wait_ms) -{ - struct timespec req; - int ret; - - assert(!clock_gettime(CLOCK_MONOTONIC, &req)); - - /* Add @wait_ms to @req. */ - if (wait_ms > 1000) { - time_t sec = wait_ms / 1000; - wait_ms -= sec * 1000; - assert(wait_ms > 0); - req.tv_sec += sec; - } - req.tv_nsec += wait_ms * 1000000; - - /* Round @req up. */ - if (req.tv_nsec >= 1000000000) { - ldiv_t result = ldiv(req.tv_nsec, 1000000000); - req.tv_sec += result.quot; - req.tv_nsec = result.rem; - } - - do { - ret = clock_nanosleep(CLOCK_MONOTONIC, TIMER_ABSTIME, - &req, NULL); - } while (ret == EINTR); - - assert(ret == 0); -} - /* XXX Avoid duplicate this function, which was copied from libutils.h. */ static inline uint64_t diff_timeval_us(const struct timeval *t1, const struct timeval *t2) diff --git a/utils.c b/utils.c index 26975c8..ab0b715 100644 --- a/utils.c +++ b/utils.c @@ -179,4 +179,46 @@ int posix_fadvise(int fd, off_t offset, off_t len, int advice) } } -#endif /* Apple Macintosh */ +#include /* For usleep(). */ + +void msleep(double wait_ms) +{ + assert(!usleep(wait_ms * 1000)); +} + +#else + +#include /* For clock_gettime() and clock_nanosleep(). */ + +void msleep(double wait_ms) +{ + struct timespec req; + int ret; + + assert(!clock_gettime(CLOCK_MONOTONIC, &req)); + + /* Add @wait_ms to @req. */ + if (wait_ms > 1000) { + time_t sec = wait_ms / 1000; + wait_ms -= sec * 1000; + assert(wait_ms > 0); + req.tv_sec += sec; + } + req.tv_nsec += wait_ms * 1000000; + + /* Round @req up. */ + if (req.tv_nsec >= 1000000000) { + ldiv_t result = ldiv(req.tv_nsec, 1000000000); + req.tv_sec += result.quot; + req.tv_nsec = result.rem; + } + + do { + ret = clock_nanosleep(CLOCK_MONOTONIC, TIMER_ABSTIME, + &req, NULL); + } while (ret == EINTR); + + assert(ret == 0); +} + +#endif diff --git a/utils.h b/utils.h index a53939e..c0145ac 100644 --- a/utils.h +++ b/utils.h @@ -24,6 +24,8 @@ static inline int64_t delay_ms(const struct timeval *t1, (t2->tv_usec - t1->tv_usec) / 1000; } +void msleep(double wait_ms); + const long *ls_my_files(const char *path, long start_at, long end_at); void print_header(FILE *f, const char *name);