[PATCH 2/3] os: refactor timer processing
Daniel Kurtz
djkurtz at chromium.org
Sat Sep 22 06:28:36 PDT 2012
Combine two open coded loops that do the same thing:
Call DoTimer() for all expired timers
Signed-off-by: Daniel Kurtz <djkurtz at chromium.org>
---
os/WaitFor.c | 68 +++++++++++++++++++++++++--------------------------------
1 files changed, 30 insertions(+), 38 deletions(-)
diff --git a/os/WaitFor.c b/os/WaitFor.c
index 8630fc9..2aab6d1 100644
--- a/os/WaitFor.c
+++ b/os/WaitFor.c
@@ -121,6 +121,7 @@ struct _OsTimerRec {
};
static void DoTimer(OsTimerPtr timer, CARD32 now, OsTimerPtr *prev);
+static Bool DoTimers(void);
static void CheckAllTimers(void);
volatile static OsTimerPtr timers = NULL;
@@ -250,49 +251,14 @@ WaitForSomething(int *pClientsReady)
XFD_COPYSET(&ClientsWithInput, &clientsReadable);
break;
}
- if (*checkForInput[0] != *checkForInput[1])
+ if (*checkForInput[0] != *checkForInput[1] || DoTimers())
return 0;
-
- OsBlockSignals();
- if (timers) {
- int expired = 0;
-
- now = GetTimeInMillis();
- if ((int) (timers->expires - now) <= 0)
- expired = 1;
-
- while (timers && (int) (timers->expires - now) <= 0)
- DoTimer(timers, now, &timers);
-
- if (expired) {
- OsReleaseSignals();
- return 0;
- }
- }
- OsReleaseSignals();
}
else {
fd_set tmp_set;
- if (*checkForInput[0] == *checkForInput[1]) {
- OsBlockSignals();
- if (timers) {
- int expired = 0;
-
- now = GetTimeInMillis();
- if ((int) (timers->expires - now) <= 0)
- expired = 1;
-
- while (timers && (int) (timers->expires - now) <= 0)
- DoTimer(timers, now, &timers);
-
- if (expired) {
- OsReleaseSignals();
- return 0;
- }
- }
- OsReleaseSignals();
- }
+ if (*checkForInput[0] == *checkForInput[1] && DoTimers())
+ return 0;
if (someReady)
XFD_ORSET(&LastSelectMask, &ClientsWithInput, &LastSelectMask);
if (AnyClientsWriteBlocked && XFD_ANYSET(&clientsWritable)) {
@@ -415,6 +381,32 @@ DoTimer(OsTimerPtr timer, CARD32 now, OsTimerPtr *prev)
TimerSet(timer, 0, newTime, timer->callback, timer->arg);
}
+/* Call DoTimer() for all expired timers.
+ * Returns TRUE if there were any expired timers
+ */
+static Bool
+DoTimers(void)
+{
+ Bool expired = FALSE;
+ CARD32 now;
+
+ OsBlockSignals();
+ if (!timers)
+ goto out;
+
+ now = GetTimeInMillis();
+ if ((int) (timers->expires - now) > 0)
+ goto out;
+
+ expired = TRUE;
+ while (timers && (int) (timers->expires - now) <= 0)
+ DoTimer(timers, now, &timers);
+
+ out:
+ OsReleaseSignals();
+ return expired;
+}
+
OsTimerPtr
TimerSet(OsTimerPtr timer, int flags, CARD32 millis,
OsTimerCallback func, pointer arg)
--
1.7.7.3
More information about the xorg-devel
mailing list