mirror of
https://github.com/libsdl-org/SDL.git
synced 2025-10-15 22:35:59 +00:00
Convert ticks to 64-bit, added nanosecond precision to the API
Fixes https://github.com/libsdl-org/SDL/issues/5512 Fixes https://github.com/libsdl-org/SDL/issues/6731
This commit is contained in:
@@ -32,7 +32,7 @@
|
||||
#endif
|
||||
#include <errno.h>
|
||||
|
||||
int SDL_IOReady(int fd, int flags, int timeoutMS)
|
||||
int SDL_IOReady(int fd, int flags, Sint64 timeoutNS)
|
||||
{
|
||||
int result;
|
||||
|
||||
@@ -42,6 +42,7 @@ int SDL_IOReady(int fd, int flags, int timeoutMS)
|
||||
do {
|
||||
#ifdef HAVE_POLL
|
||||
struct pollfd info;
|
||||
int timeoutMS;
|
||||
|
||||
info.fd = fd;
|
||||
info.events = 0;
|
||||
@@ -51,6 +52,14 @@ int SDL_IOReady(int fd, int flags, int timeoutMS)
|
||||
if (flags & SDL_IOR_WRITE) {
|
||||
info.events |= POLLOUT;
|
||||
}
|
||||
/* FIXME: Add support for ppoll() for nanosecond precision */
|
||||
if (timeoutNS > 0) {
|
||||
timeoutMS = (int)SDL_NS_TO_MS(timeoutNS);
|
||||
} else if (timeoutNS == 0) {
|
||||
timeoutMS = 0;
|
||||
} else {
|
||||
timeoutMS = -1;
|
||||
}
|
||||
result = poll(&info, 1, timeoutMS);
|
||||
#else
|
||||
fd_set rfdset, *rfdp = NULL;
|
||||
@@ -71,9 +80,9 @@ int SDL_IOReady(int fd, int flags, int timeoutMS)
|
||||
wfdp = &wfdset;
|
||||
}
|
||||
|
||||
if (timeoutMS >= 0) {
|
||||
tv.tv_sec = timeoutMS / 1000;
|
||||
tv.tv_usec = (timeoutMS % 1000) * 1000;
|
||||
if (timeoutNS >= 0) {
|
||||
tv.tv_sec = (timeoutNS / SDL_NS_PER_SECOND);
|
||||
tv.tv_usec = SDL_NS_TO_US(timeoutNS % SDL_NS_PER_SECOND);
|
||||
tvp = &tv;
|
||||
}
|
||||
|
||||
|
@@ -28,7 +28,7 @@
|
||||
#define SDL_IOR_WRITE 0x2
|
||||
#define SDL_IOR_NO_RETRY 0x4
|
||||
|
||||
extern int SDL_IOReady(int fd, int flags, int timeoutMS);
|
||||
extern int SDL_IOReady(int fd, int flags, Sint64 timeoutNS);
|
||||
|
||||
#endif /* SDL_poll_h_ */
|
||||
|
||||
|
Reference in New Issue
Block a user