summaryrefslogtreecommitdiff
path: root/os
diff options
context:
space:
mode:
Diffstat (limited to 'os')
-rw-r--r--os/WaitFor.c32
-rw-r--r--os/utils.c21
2 files changed, 22 insertions, 31 deletions
diff --git a/os/WaitFor.c b/os/WaitFor.c
index b6801fea9..7bdd39987 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 a58603dfe..868a2d6de 100644
--- a/os/utils.c
+++ b/os/utils.c
@@ -513,27 +513,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");