mirror of
https://github.com/subsurface/subsurface.git
synced 2025-01-31 20:43:24 +00:00
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>
This commit is contained in:
parent
76c4fb3975
commit
f8e9fb72f1
1 changed files with 10 additions and 1 deletions
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue