summaryrefslogtreecommitdiff
path: root/os/windows/posix.c
diff options
context:
space:
mode:
authorBruce Cran <bruce@cran.org.uk>2012-08-15 20:24:24 +0200
committerJens Axboe <axboe@kernel.dk>2012-08-15 20:24:24 +0200
commit21c753874722ceff6e78c9e57768932436bce35b (patch)
treec8a271dd4ce6da47508c5e3ed4891606cf0d1d24 /os/windows/posix.c
parent31dc09d7f3f684fc6b3629235633cff76aca7e85 (diff)
downloadfio-21c753874722ceff6e78c9e57768932436bce35b.tar.gz
fio-21c753874722ceff6e78c9e57768932436bce35b.tar.bz2
fio: add nanosleep() to Windows
I've attached a patch which adds an implementation of nanosleep() to Windows, fixing rate-limiting. Signed-off-by: Jens Axboe <axboe@kernel.dk>
Diffstat (limited to 'os/windows/posix.c')
-rwxr-xr-xos/windows/posix.c30
1 files changed, 27 insertions, 3 deletions
diff --git a/os/windows/posix.c b/os/windows/posix.c
index 41bcb2d4..27260ce6 100755
--- a/os/windows/posix.c
+++ b/os/windows/posix.c
@@ -20,6 +20,9 @@
#include "../os-windows.h"
+extern unsigned long mtime_since_now(struct timeval *);
+extern void fio_gettime(struct timeval *, void *);
+
long sysconf(int name)
{
long long val = -1;
@@ -631,9 +634,30 @@ int poll(struct pollfd fds[], nfds_t nfds, int timeout)
int nanosleep(const struct timespec *rqtp, struct timespec *rmtp)
{
- log_err("%s is not implemented\n", __func__);
- errno = ENOSYS;
- return -1;
+ struct timeval tv;
+ DWORD ms_remaining;
+ DWORD ms_total = (rqtp->tv_sec * 1000) + (rqtp->tv_nsec / 1000000.0);
+
+ if (ms_total == 0)
+ ms_total = 1;
+
+ ms_remaining = ms_total;
+
+ /* Since Sleep() can sleep for less than the requested time, add a loop to
+ ensure we only return after the requested length of time has elapsed */
+ do {
+ fio_gettime(&tv, NULL);
+ Sleep(ms_remaining);
+ ms_remaining = ms_total - mtime_since_now(&tv);
+ } while (ms_remaining > 0 && ms_remaining < ms_total);
+
+ /* this implementation will never sleep for less than the requested time */
+ if (rmtp != NULL) {
+ rmtp->tv_sec = 0;
+ rmtp->tv_nsec = 0;
+ }
+
+ return 0;
}
DIR *opendir(const char *dirname)