summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKeith Packard <keithp@keithp.com>2016-05-26 10:30:56 -0700
committerAdam Jackson <ajax@redhat.com>2016-07-18 15:27:51 -0400
commite6636b438322a9a2f2270ad9d60bf3dfc72be0b3 (patch)
tree60de783adf97d0f009a5edc332a833209a78fbe6
parenta414db021575accff64abad6f1047245e81c7476 (diff)
os: Compute timeout in milliseconds instead of struct timeval
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@keithp.com> Reviewed-by: Adam Jackson <ajax@redhat.com>
-rw-r--r--include/os.h3
-rw-r--r--os/WaitFor.c32
-rw-r--r--os/utils.c21
3 files changed, 23 insertions, 33 deletions
diff --git a/include/os.h b/include/os.h
index 5f651418b..9a3d9a9a0 100644
--- a/include/os.h
+++ b/include/os.h
@@ -182,8 +182,7 @@ extern void ForceClockId(clockid_t /* forced_clockid */);
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 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");