diff options
author | Lubomir I. Ivanov <neolit123@gmail.com> | 2018-09-12 03:27:05 +0300 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2018-09-12 17:18:47 -0700 |
commit | f8e9fb72f12990ce5c89de94eeb4effa2757d38b (patch) | |
tree | 8aebf694fc63fa482e0030589de93b25934e8f6d /core | |
parent | 76c4fb39751283ecd734407709251f7bf16f7189 (diff) | |
download | subsurface-f8e9fb72f12990ce5c89de94eeb4effa2757d38b.tar.gz |
serial_ftdi: use Sleep() on Win32
Windows doesn't have nanosleep() unless libwinpthread is used.
Since the nanosleep() usage in serial_ftdi_sleep():
- does not break in case of EINTR
- has input in milliseconds
the WINAPI Sleep() should be a good alternative.
Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
Diffstat (limited to 'core')
-rw-r--r-- | core/serial_ftdi.c | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/core/serial_ftdi.c b/core/serial_ftdi.c index 86d27c9ff..b3f2f2f37 100644 --- a/core/serial_ftdi.c +++ b/core/serial_ftdi.c @@ -26,12 +26,17 @@ #include <string.h> // strerror #include <errno.h> // errno #include <sys/time.h> // gettimeofday -#include <time.h> // nanosleep #include <stdio.h> #include <libusb.h> #include <ftdi.h> +#ifdef _WIN32 +#include <windows.h> // Sleep +#else +#include <time.h> // nanosleep +#endif + #ifndef __ANDROID__ #define INFO(context, fmt, ...) fprintf(stderr, "INFO: " fmt "\n", ##__VA_ARGS__) #define ERROR(context, fmt, ...) fprintf(stderr, "ERROR: " fmt "\n", ##__VA_ARGS__) @@ -107,6 +112,9 @@ static dc_status_t serial_ftdi_sleep (void *io, unsigned int timeout) INFO (device->context, "Sleep: value=%u", timeout); +#ifdef _WIN32 + Sleep((DWORD)timeout); +#else struct timespec ts; ts.tv_sec = (timeout / 1000); ts.tv_nsec = (timeout % 1000) * 1000000; @@ -117,6 +125,7 @@ static dc_status_t serial_ftdi_sleep (void *io, unsigned int timeout) return DC_STATUS_IO; } } +#endif return DC_STATUS_SUCCESS; } |