mirror of
https://git.tartarus.org/simon/putty.git
synced 2026-10-23 03:45:29 +03:00
More general function to delete toplevel callbacks.
For cases where you want a more subtle criterion than "cites this particular context structure". I'm going to introduce one in the next commit.
This commit is contained in:
21
callback.c
21
callback.c
@@ -41,7 +41,9 @@ void queue_idempotent_callback(struct IdempotentCallback *ic)
|
||||
queue_toplevel_callback(run_idempotent_callback, ic);
|
||||
}
|
||||
|
||||
void delete_callbacks_for_context(void *ctx)
|
||||
void delete_callbacks(
|
||||
bool (*delete_this_one)(void *predicate_ctx, toplevel_callback_fn_t fn,
|
||||
void *callback_ctx), void *predicate_ctx)
|
||||
{
|
||||
struct callback *newhead, *newtail;
|
||||
|
||||
@@ -49,9 +51,7 @@ void delete_callbacks_for_context(void *ctx)
|
||||
while (cbhead) {
|
||||
struct callback *cb = cbhead;
|
||||
cbhead = cbhead->next;
|
||||
if (cb->ctx == ctx ||
|
||||
(cb->fn == run_idempotent_callback &&
|
||||
((struct IdempotentCallback *)cb->ctx)->ctx == ctx)) {
|
||||
if (delete_this_one(predicate_ctx, cb->fn, cb->ctx)) {
|
||||
sfree(cb);
|
||||
} else {
|
||||
if (!newhead)
|
||||
@@ -69,6 +69,19 @@ void delete_callbacks_for_context(void *ctx)
|
||||
newtail->next = NULL;
|
||||
}
|
||||
|
||||
static bool callback_is_for_context(
|
||||
void *predicate_ctx, toplevel_callback_fn_t fn, void *callback_ctx)
|
||||
{
|
||||
return callback_ctx == predicate_ctx ||
|
||||
(fn == run_idempotent_callback &&
|
||||
((struct IdempotentCallback *)callback_ctx)->ctx == predicate_ctx);
|
||||
}
|
||||
|
||||
void delete_callbacks_for_context(void *ctx)
|
||||
{
|
||||
delete_callbacks(callback_is_for_context, ctx);
|
||||
}
|
||||
|
||||
void queue_toplevel_callback(toplevel_callback_fn_t fn, void *ctx)
|
||||
{
|
||||
struct callback *cb;
|
||||
|
||||
3
putty.h
3
putty.h
@@ -2703,6 +2703,9 @@ unsigned long timing_last_clock(void);
|
||||
void queue_toplevel_callback(toplevel_callback_fn_t fn, void *ctx);
|
||||
bool run_toplevel_callbacks(void);
|
||||
bool toplevel_callback_pending(void);
|
||||
void delete_callbacks(
|
||||
bool (*delete_this_one)(void *predicate_ctx, toplevel_callback_fn_t fn,
|
||||
void *callback_ctx), void *predicate_ctx);
|
||||
void delete_callbacks_for_context(void *ctx);
|
||||
|
||||
/*
|
||||
|
||||
Reference in New Issue
Block a user