[PATCH xserver 16/23] os: Compute timeout in milliseconds instead of struct timeval
Keith Packard
keithp at keithp.com
Thu May 26 23:59:51 UTC 2016
The timeout resolution offered in the AdjustWaitForDelay call is
only milliseconds, so passing around the timeout as a pointer to a
struct timeval is not helpful. Doing everything in milliseconds up to
the point of the select call simplifies the code without affecting
functionality at all.
Signed-off-by: Keith Packard <keithp at keithp.com>
---
include/os.h | 3 +--
os/WaitFor.c | 32 ++++++++++++++++++++++----------
os/utils.c | 21 ---------------------
3 files changed, 23 insertions(+), 33 deletions(-)
diff --git a/include/os.h b/include/os.h
index 51400a9..25e02bf 100644
--- a/include/os.h
+++ b/include/os.h
@@ -175,8 +175,7 @@ extern _X_EXPORT Bool AddClientOnOpenFD(int /* fd */ );
extern _X_EXPORT CARD32 GetTimeInMillis(void);
extern _X_EXPORT CARD64 GetTimeInMicros(void);
-extern _X_EXPORT void AdjustWaitForDelay(void *waitTime,
- unsigned long newdelay);
+extern _X_EXPORT void AdjustWaitForDelay(void *waitTime, int newdelay);
typedef struct _OsTimerRec *OsTimerPtr;
diff --git a/os/WaitFor.c b/os/WaitFor.c
index 26673e4..0ba1d6b 100644
--- a/os/WaitFor.c
+++ b/os/WaitFor.c
@@ -147,7 +147,7 @@ WaitForSomething(int *pClientsReady)
{
int i;
struct timeval waittime, *wt;
- INT32 timeout = 0;
+ int timeout;
fd_set clientsReadable;
fd_set clientsWritable;
int curclient;
@@ -175,17 +175,15 @@ WaitForSomething(int *pClientsReady)
if (workQueue)
ProcessWorkQueue();
if (XFD_ANYSET(&ClientsWithInput)) {
+ timeout = 0;
someReady = TRUE;
- waittime.tv_sec = 0;
- waittime.tv_usec = 0;
- wt = &waittime;
}
if (someReady) {
XFD_COPYSET(&AllSockets, &LastSelectMask);
XFD_UNSET(&LastSelectMask, &ClientsWithInput);
}
else {
- wt = NULL;
+ timeout = -1;
if (timers) {
now = GetTimeInMillis();
timeout = timers->expires - now;
@@ -198,16 +196,20 @@ WaitForSomething(int *pClientsReady)
timeout = timers->expires - now;
if (timeout < 0)
timeout = 0;
- waittime.tv_sec = timeout / MILLI_PER_SECOND;
- waittime.tv_usec = (timeout % MILLI_PER_SECOND) *
- (1000000 / MILLI_PER_SECOND);
- wt = &waittime;
}
}
XFD_COPYSET(&AllSockets, &LastSelectMask);
}
- BlockHandler(&wt);
+ BlockHandler(&timeout);
+ if (timeout < 0)
+ wt = NULL;
+ else {
+ waittime.tv_sec = timeout / MILLI_PER_SECOND;
+ waittime.tv_usec = (timeout % MILLI_PER_SECOND) *
+ (1000000 / MILLI_PER_SECOND);
+ wt = &waittime;
+ }
if (NewOutputPending)
FlushAllOutput();
/* keep this check close to select() call to minimize race */
@@ -359,6 +361,16 @@ WaitForSomething(int *pClientsReady)
return nready;
}
+void
+AdjustWaitForDelay(void *waitTime, int newdelay)
+{
+ int *timeoutp = waitTime;
+ int timeout = *timeoutp;
+
+ if (timeout < 0 || newdelay < timeout)
+ *timeoutp = newdelay;
+}
+
/* If time has rewound, re-run every affected timer.
* Timers might drop out of the list, so we have to restart every time. */
static void
diff --git a/os/utils.c b/os/utils.c
index 87417e2..4507c9e 100644
--- a/os/utils.c
+++ b/os/utils.c
@@ -493,27 +493,6 @@ GetTimeInMicros(void)
#endif
void
-AdjustWaitForDelay(void *waitTime, unsigned long newdelay)
-{
- static struct timeval delay_val;
- struct timeval **wt = (struct timeval **) waitTime;
- unsigned long olddelay;
-
- if (*wt == NULL) {
- delay_val.tv_sec = newdelay / 1000;
- delay_val.tv_usec = 1000 * (newdelay % 1000);
- *wt = &delay_val;
- }
- else {
- olddelay = (*wt)->tv_sec * 1000 + (*wt)->tv_usec / 1000;
- if (newdelay < olddelay) {
- (*wt)->tv_sec = newdelay / 1000;
- (*wt)->tv_usec = 1000 * (newdelay % 1000);
- }
- }
-}
-
-void
UseMsg(void)
{
ErrorF("use: X [:<display>] [option]\n");
--
2.8.0.rc3
More information about the xorg-devel
mailing list