1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-07-01 11:32:48 -05:00

Two related changes to timing code:

First, make absolute times unsigned.  This means that it's safe to 
depend on their overflow behaviour (which is undefined for signed 
integers).  This requires a little extra care in handling comparisons, 
but I think I've correctly adjusted them all.

Second, functions registered with schedule_timer() are guaranteed to be 
called with precisely the time that was returned by schedule_timer().  
Thus, it's only necessary to check these values for equality rather than 
doing risky range checks, so do that.

The timing code still does lots that's undefined, unnecessary, or just
wrong, but this is a good start.

[originally from svn r9667]
This commit is contained in:
Ben Harris
2012-09-18 21:42:48 +00:00
parent 41ad182710
commit d5836982e2
16 changed files with 88 additions and 61 deletions

View File

@ -41,7 +41,7 @@ void notify_remote_exit(void *frontend)
{
}
void timer_change_notify(long next)
void timer_change_notify(unsigned long next)
{
}

View File

@ -2012,10 +2012,14 @@ void notify_remote_exit(void *fe)
}
}
void timer_change_notify(long next)
void timer_change_notify(unsigned long next)
{
long ticks = next - GETTICKCOUNT();
if (ticks <= 0) ticks = 1; /* just in case */
unsigned long now = GETTICKCOUNT();
long ticks;
if (now - next < INT_MAX)
ticks = 0;
else
ticks = next - now;
KillTimer(hwnd, TIMING_TIMER_ID);
SetTimer(hwnd, TIMING_TIMER_ID, ticks, NULL);
timing_next_time = next;
@ -2042,7 +2046,7 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT message,
switch (message) {
case WM_TIMER:
if ((UINT_PTR)wParam == TIMING_TIMER_ID) {
long next;
unsigned long next;
KillTimer(hwnd, TIMING_TIMER_ID);
if (run_timers(timing_next_time, &next)) {
@ -5354,9 +5358,9 @@ static int flashing = 0;
* Timer for platforms where we must maintain window flashing manually
* (e.g., Win95).
*/
static void flash_window_timer(void *ctx, long now)
static void flash_window_timer(void *ctx, unsigned long now)
{
if (flashing && now - next_flash >= 0) {
if (flashing && now == next_flash) {
flash_window(1);
}
}

View File

@ -289,7 +289,7 @@ int main(int argc, char **argv)
int errors;
int got_host = FALSE;
int use_subsystem = 0;
long now, next;
unsigned long now, next, then;
sklist = NULL;
skcount = sksize = 0;
@ -634,8 +634,12 @@ int main(int argc, char **argv)
}
if (run_timers(now, &next)) {
ticks = next - GETTICKCOUNT();
if (ticks < 0) ticks = 0; /* just in case */
then = now;
now = GETTICKCOUNT();
if (now - then > next - then)
ticks = 0;
else
ticks = next - now;
} else {
ticks = INFINITE;
}

View File

@ -331,11 +331,11 @@ static void serial_size(void *handle, int width, int height)
return;
}
static void serbreak_timer(void *ctx, long now)
static void serbreak_timer(void *ctx, unsigned long now)
{
Serial serial = (Serial)ctx;
if (now >= serial->clearbreak_time && serial->port) {
if (now == serial->clearbreak_time && serial->port) {
ClearCommBreak(serial->port);
serial->break_in_progress = FALSE;
logevent(serial->frontend, "Finished serial break");

View File

@ -486,15 +486,20 @@ extern int select_result(WPARAM, LPARAM);
int do_eventsel_loop(HANDLE other_event)
{
int n, nhandles, nallhandles, netindex, otherindex;
long next, ticks;
unsigned long next, then;
long ticks;
HANDLE *handles;
SOCKET *sklist;
int skcount;
long now = GETTICKCOUNT();
unsigned long now = GETTICKCOUNT();
if (run_timers(now, &next)) {
ticks = next - GETTICKCOUNT();
if (ticks < 0) ticks = 0; /* just in case */
then = now;
now = GETTICKCOUNT();
if (now - then > next - then)
ticks = 0;
else
ticks = next - now;
} else {
ticks = INFINITE;
}