mirror of
https://git.tartarus.org/simon/putty.git
synced 2025-03-22 14:39:24 -05:00
Change expiry of timers when their contexts go away from lazy to eager.
Intended to be of benefit to derived code making many connections from a single process. [originally from svn r8847]
This commit is contained in:
parent
5ea11dfb3a
commit
7f7877e9a5
46
timing.c
46
timing.c
@ -22,7 +22,6 @@ 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)
|
||||||
@ -71,8 +70,10 @@ 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)
|
||||||
{
|
{
|
||||||
char *a = (char *)av;
|
struct timer *at = (struct timer *)av;
|
||||||
char *b = (char *)bv;
|
struct timer *bt = (struct timer *)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)
|
||||||
@ -84,7 +85,6 @@ 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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -113,8 +113,6 @@ 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);
|
||||||
@ -200,14 +198,7 @@ int run_timers(long anow, long *next)
|
|||||||
if (!first)
|
if (!first)
|
||||||
return FALSE; /* no timers remaining */
|
return FALSE; /* no timers remaining */
|
||||||
|
|
||||||
if (find234(timer_contexts, first->ctx, NULL) == NULL) {
|
if (first->now - now <= 0) {
|
||||||
/*
|
|
||||||
* 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.
|
||||||
@ -231,13 +222,24 @@ int run_timers(long anow, long *next)
|
|||||||
*/
|
*/
|
||||||
void expire_timer_context(void *ctx)
|
void expire_timer_context(void *ctx)
|
||||||
{
|
{
|
||||||
init_timers();
|
struct timer *ptr;
|
||||||
|
struct timer exemplar;
|
||||||
|
|
||||||
/*
|
if (!timers) return;
|
||||||
* We don't bother to check the return value; if the context
|
|
||||||
* already wasn't in the tree (presumably because no timers
|
exemplar.ctx = ctx;
|
||||||
* ever actually got scheduled for it) then that's fine and we
|
/* don't care about initialisation of other members */
|
||||||
* simply don't need to do anything.
|
|
||||||
*/
|
/* Dispose of all timers with this context */
|
||||||
del234(timer_contexts, ctx);
|
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) {
|
||||||
|
freetree234(timers);
|
||||||
|
timers = NULL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user