diff options
author | Michel Dänzer <michel@tungstengraphics.com> | 2006-12-19 16:29:26 +0100 |
---|---|---|
committer | Michel Dänzer <michel@tungstengraphics.com> | 2006-12-19 16:29:26 +0100 |
commit | 4334860e69e7d5b156082bd05c7a86708e5bad4c (patch) | |
tree | 380e4abcbfc8950b000ff72b0347e78fee3bc74a /os/WaitFor.c | |
parent | 7e4717683d6c08d1e490a60b7493a94bbc57bf8d (diff) | |
parent | fdcc22ca1704d3519156c66804528c21b04fea65 (diff) |
Merge branch 'master' into exa-damagetrack
Conflicts:
exa/exa_accel.c
exa/exa_migration.c
Diffstat (limited to 'os/WaitFor.c')
-rw-r--r-- | os/WaitFor.c | 48 |
1 files changed, 38 insertions, 10 deletions
diff --git a/os/WaitFor.c b/os/WaitFor.c index f7921c3d9..ba227a3b6 100644 --- a/os/WaitFor.c +++ b/os/WaitFor.c @@ -1,4 +1,3 @@ -/* $XFree86: xc/programs/Xserver/os/WaitFor.c,v 3.42 2003/10/16 01:33:35 dawes Exp $ */ /*********************************************************** Copyright 1987, 1998 The Open Group @@ -46,7 +45,6 @@ SOFTWARE. ******************************************************************/ -/* $Xorg: WaitFor.c,v 1.4 2001/02/09 02:05:22 xorgcvs Exp $ */ /***************************************************************** * OS Dependent input routines: @@ -121,11 +119,13 @@ mffs(fd_mask mask) struct _OsTimerRec { OsTimerPtr next; CARD32 expires; + CARD32 delta; OsTimerCallback callback; pointer arg; }; static void DoTimer(OsTimerPtr timer, CARD32 now, OsTimerPtr *prev); +static void CheckAllTimers(CARD32 now); static OsTimerPtr timers = NULL; /***************** @@ -202,12 +202,20 @@ WaitForSomething(int *pClientsReady) { now = GetTimeInMillis(); 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; + if (timeout > 0 && timeout > timers->delta + 250) { + /* time has rewound. reset the timers. */ + CheckAllTimers(now); + } + + if (timers) { + 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); #ifdef SMART_SCHEDULE @@ -428,6 +436,21 @@ ANYSET(FdMask *src) } #endif +/* 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 +CheckAllTimers(CARD32 now) +{ + OsTimerPtr timer; + +start: + for (timer = timers; timer; timer = timer->next) { + if (timer->expires - now > timer->delta + 250) { + TimerForce(timer); + goto start; + } + } +} static void DoTimer(OsTimerPtr timer, CARD32 now, OsTimerPtr *prev) @@ -469,8 +492,13 @@ TimerSet(OsTimerPtr timer, int flags, CARD32 millis, } if (!millis) return timer; - if (!(flags & TimerAbsolute)) + if (flags & TimerAbsolute) { + timer->delta = millis - now; + } + else { + timer->delta = millis; millis += now; + } timer->expires = millis; timer->callback = func; timer->arg = arg; @@ -484,7 +512,7 @@ TimerSet(OsTimerPtr timer, int flags, CARD32 millis, for (prev = &timers; *prev && (int) ((*prev)->expires - millis) <= 0; prev = &(*prev)->next) - ; + ; timer->next = *prev; *prev = timer; return timer; |