From 0941b4e809d1b29da14ff11ee210f10040b765ae Mon Sep 17 00:00:00 2001 From: Bob Halley Date: Sat, 12 Jun 1999 01:10:32 +0000 Subject: [PATCH] add isc_task_purgeevent --- lib/isc/include/isc/task.h | 49 +++++++++++++++++++++++++++++++------- lib/isc/task.c | 41 +++++++++++++++++++++++++++++++ 2 files changed, 82 insertions(+), 8 deletions(-) diff --git a/lib/isc/include/isc/task.h b/lib/isc/include/isc/task.h index 2cf4e151b3..fac00f8c0b 100644 --- a/lib/isc/include/isc/task.h +++ b/lib/isc/include/isc/task.h @@ -184,17 +184,18 @@ isc_task_purgerange(isc_task_t *task, void *sender, isc_eventtype_t first, /* * Purge events from a task's event queue. * - * Notes: - * Events whose sender is 'sender', and whose type is >= first and - * <= last will be purged, unless they are marked as unpurgable. - * A sender of NULL will match any sender. - * * Requires: * * 'task' is a valid task. * * last >= first * + * Ensures: + * + * Events whose sender is 'sender', and whose type is >= first and + * <= last will be purged, unless they are marked as unpurgable. + * A sender of NULL will match any sender. + * * Returns: * * The number of events purged. @@ -206,9 +207,6 @@ isc_task_purge(isc_task_t *task, void *sender, isc_eventtype_t type); * Purge events from a task's event queue. * * Notes: - * Events whose sender is 'sender', and whose type is 'type' - * will be purged, unless they are marked as unpurgable. - * A sender of NULL will match any sender. * * This function is equivalent to * @@ -220,11 +218,46 @@ isc_task_purge(isc_task_t *task, void *sender, isc_eventtype_t type); * * last >= first * + * Ensures: + * + * Events whose sender is 'sender', and whose type is 'type' + * will be purged, unless they are marked as unpurgable. + * A sender of NULL will match any sender. + * * Returns: * * The number of events purged. */ +isc_boolean_t +isc_task_purgeevent(isc_task_t *task, isc_event_t *event); +/* + * Purge 'event' from a task's event queue. + * + * Notes: + * + * If 'event' is on the task's event queue, it will be purged, + * unless it is marked as unpurgeable. 'event' does not have to be + * on the task's event queue; in fact, it can even be an invalid + * pointer. Purging only occurs if the event is actually on the task's + * event queue. + * + * Purging never changes the state of the task. + * + * Requires: + * + * 'task' is a valid task. + * + * Ensures: + * + * 'event' is not in the event queue for 'task'. + * + * Returns: + * + * ISC_TRUE The event was purged. + * ISC_FALSE The event was not in the event queue, + * or was marked unpurgeable. + */ isc_result_t isc_task_allowsend(isc_task_t *task, isc_boolean_t allow); diff --git a/lib/isc/task.c b/lib/isc/task.c index 179938fd3b..1b89223c4a 100644 --- a/lib/isc/task.c +++ b/lib/isc/task.c @@ -391,6 +391,47 @@ isc_task_purge(isc_task_t *task, void *sender, isc_eventtype_t type) { return (isc_task_purgerange(task, sender, type, type)); } +isc_boolean_t +isc_task_purgeevent(isc_task_t *task, isc_event_t *event) { + isc_event_t *curr_event, *next_event; + + /* + * Purge 'event' from a task's event queue. + */ + + REQUIRE(VALID_TASK(task)); + + /* + * If 'event' is on the task's event queue, it will be purged, + * unless it is marked as unpurgeable. 'event' does not have to be + * on the task's event queue; in fact, it can even be an invalid + * pointer. Purging only occurs if the event is actually on the task's + * event queue. + * + * Purging never changes the state of the task. + */ + + LOCK(&task->lock); + for (curr_event = HEAD(task->events); + curr_event != NULL; + curr_event = next_event) { + next_event = NEXT(curr_event, link); + if (curr_event == event && + (event->attributes & ISC_EVENTATTR_NOPURGE) == 0) { + DEQUEUE(task->events, curr_event, link); + break; + } + } + UNLOCK(&task->lock); + + if (curr_event == NULL) + return (ISC_FALSE); + + isc_event_free(&curr_event); + + return (ISC_TRUE); +} + isc_result_t isc_task_allowsend(isc_task_t *task, isc_boolean_t allowed) { isc_result_t result = ISC_R_SUCCESS;