Skip to content
This repository has been archived by the owner on Apr 19, 2024. It is now read-only.

Commit

Permalink
Revert r8847, which was bilge; I can't magically change the order of …
Browse files Browse the repository at this point in the history
…a tree

just by giving a different sorting function to find234().


git-svn-id: svn://svn.tartarus.org/sgt/putty@8849 cda61777-01e9-0310-a592-d414129be87e
  • Loading branch information
jacob committed Jan 17, 2010
1 parent 87e14c0 commit 1605c49
Showing 1 changed file with 22 additions and 24 deletions.
46 changes: 22 additions & 24 deletions timing.c
Expand Up @@ -22,6 +22,7 @@ struct timer {
}; };


static tree234 *timers = NULL; static tree234 *timers = NULL;
static tree234 *timer_contexts = NULL;
static long now = 0L; static long now = 0L;


static int compare_timers(void *av, void *bv) static int compare_timers(void *av, void *bv)
Expand Down Expand Up @@ -70,10 +71,8 @@ static int compare_timers(void *av, void *bv)


static int compare_timer_contexts(void *av, void *bv) static int compare_timer_contexts(void *av, void *bv)
{ {
struct timer *at = (struct timer *)av; char *a = (char *)av;
struct timer *bt = (struct timer *)bv; char *b = (char *)bv;
char *a = (char *)at->ctx;
char *b = (char *)bt->ctx;
if (a < b) if (a < b)
return -1; return -1;
else if (a > b) else if (a > b)
Expand All @@ -85,6 +84,7 @@ static void init_timers(void)
{ {
if (!timers) { if (!timers) {
timers = newtree234(compare_timers); timers = newtree234(compare_timers);
timer_contexts = newtree234(compare_timer_contexts);
now = GETTICKCOUNT(); now = GETTICKCOUNT();
} }
} }
Expand Down Expand Up @@ -113,6 +113,8 @@ long schedule_timer(int ticks, timer_fn_t fn, void *ctx)


if (t != add234(timers, t)) { if (t != add234(timers, t)) {
sfree(t); /* identical timer already exists */ sfree(t); /* identical timer already exists */
} else {
add234(timer_contexts, t->ctx);/* don't care if this fails */
} }


first = (struct timer *)index234(timers, 0); first = (struct timer *)index234(timers, 0);
Expand Down Expand Up @@ -198,7 +200,14 @@ int run_timers(long anow, long *next)
if (!first) if (!first)
return FALSE; /* no timers remaining */ return FALSE; /* no timers remaining */


if (first->now - now <= 0) { if (find234(timer_contexts, first->ctx, NULL) == NULL) {
/*
* This timer belongs to a context that has been
* expired. Delete it without running.
*/
delpos234(timers, 0);
sfree(first);
} else if (first->now - now <= 0) {
/* /*
* This timer is active and has reached its running * This timer is active and has reached its running
* time. Run it. * time. Run it.
Expand All @@ -222,24 +231,13 @@ int run_timers(long anow, long *next)
*/ */
void expire_timer_context(void *ctx) void expire_timer_context(void *ctx)
{ {
struct timer *ptr; init_timers();
struct timer exemplar;

if (!timers) return;

exemplar.ctx = ctx;
/* don't care about initialisation of other members */

/* Dispose of all timers with this context */
while ((ptr = (struct timer *)find234(timers, &exemplar,
compare_timer_contexts))) {
del234(timers, ptr);
sfree(ptr);
}


/* Dispose of timer tree itself if none are left */ /*
if (count234(timers) == 0) { * We don't bother to check the return value; if the context
freetree234(timers); * already wasn't in the tree (presumably because no timers
timers = NULL; * ever actually got scheduled for it) then that's fine and we
} * simply don't need to do anything.
*/
del234(timer_contexts, ctx);
} }

0 comments on commit 1605c49

Please sign in to comment.