From 60c165f23f8d5553bd8b4fd43366fbf5f24c2832 Mon Sep 17 00:00:00 2001 From: Pekka Riikonen Date: Tue, 23 Jan 2007 16:52:33 +0000 Subject: [PATCH] Task deletion functions now return boolean value. --- lib/silcutil/silcschedule.c | 59 +++++++++++++++++++++++++++---------- lib/silcutil/silcschedule.h | 48 +++++++++++++++++------------- 2 files changed, 71 insertions(+), 36 deletions(-) diff --git a/lib/silcutil/silcschedule.c b/lib/silcutil/silcschedule.c index aa0e9eb5..790b242f 100644 --- a/lib/silcutil/silcschedule.c +++ b/lib/silcutil/silcschedule.c @@ -661,7 +661,7 @@ SilcTask silc_schedule_task_add(SilcSchedule schedule, SilcUInt32 fd, /* Invalidates task */ -void silc_schedule_task_del(SilcSchedule schedule, SilcTask task) +SilcBool silc_schedule_task_del(SilcSchedule schedule, SilcTask task) { if (silc_unlikely(task == SILC_ALL_TASKS)) { SilcHashTableList htl; @@ -683,20 +683,23 @@ void silc_schedule_task_del(SilcSchedule schedule, SilcTask task) task->valid = FALSE; SILC_SCHEDULE_UNLOCK(schedule); - return; + return TRUE; } SILC_LOG_DEBUG(("Unregistering task %p", task)); SILC_SCHEDULE_LOCK(schedule); task->valid = FALSE; SILC_SCHEDULE_UNLOCK(schedule); + + return TRUE; } /* Invalidate task by fd */ -void silc_schedule_task_del_by_fd(SilcSchedule schedule, SilcUInt32 fd) +SilcBool silc_schedule_task_del_by_fd(SilcSchedule schedule, SilcUInt32 fd) { SilcTask task = NULL; + SilcBool ret = FALSE; SILC_LOG_DEBUG(("Unregister task by fd %d", fd)); @@ -708,23 +711,29 @@ void silc_schedule_task_del_by_fd(SilcSchedule schedule, SilcUInt32 fd) (void **)&task))) { SILC_LOG_DEBUG(("Deleting task %p", task)); task->valid = FALSE; + ret = TRUE; } SILC_SCHEDULE_UNLOCK(schedule); /* If it is signal, remove it */ - if (silc_unlikely(!task)) + if (silc_unlikely(!task)) { schedule_ops.signal_unregister(schedule, schedule->internal, fd); + ret = TRUE; + } + + return ret; } /* Invalidate task by task callback. */ -void silc_schedule_task_del_by_callback(SilcSchedule schedule, - SilcTaskCallback callback) +SilcBool silc_schedule_task_del_by_callback(SilcSchedule schedule, + SilcTaskCallback callback) { SilcTask task; SilcHashTableList htl; SilcList list; + SilcBool ret = FALSE; SILC_LOG_DEBUG(("Unregister task by callback")); @@ -733,8 +742,10 @@ void silc_schedule_task_del_by_callback(SilcSchedule schedule, /* Delete from fd queue */ silc_hash_table_list(schedule->fd_queue, &htl); while (silc_hash_table_get(&htl, NULL, (void **)&task)) { - if (task->callback == callback) + if (task->callback == callback) { task->valid = FALSE; + ret = TRUE; + } } silc_hash_table_list_reset(&htl); @@ -742,20 +753,26 @@ void silc_schedule_task_del_by_callback(SilcSchedule schedule, list = schedule->timeout_queue; silc_list_start(list); while ((task = (SilcTask)silc_list_get(list))) { - if (task->callback == callback) + if (task->callback == callback) { task->valid = FALSE; + ret = TRUE; + } } SILC_SCHEDULE_UNLOCK(schedule); + + return ret; } /* Invalidate task by context. */ -void silc_schedule_task_del_by_context(SilcSchedule schedule, void *context) +SilcBool silc_schedule_task_del_by_context(SilcSchedule schedule, + void *context) { SilcTask task; SilcHashTableList htl; SilcList list; + SilcBool ret = FALSE; SILC_LOG_DEBUG(("Unregister task by context")); @@ -764,8 +781,10 @@ void silc_schedule_task_del_by_context(SilcSchedule schedule, void *context) /* Delete from fd queue */ silc_hash_table_list(schedule->fd_queue, &htl); while (silc_hash_table_get(&htl, NULL, (void **)&task)) { - if (task->context == context) + if (task->context == context) { task->valid = FALSE; + ret = TRUE; + } } silc_hash_table_list_reset(&htl); @@ -773,26 +792,32 @@ void silc_schedule_task_del_by_context(SilcSchedule schedule, void *context) list = schedule->timeout_queue; silc_list_start(list); while ((task = (SilcTask)silc_list_get(list))) { - if (task->context == context) + if (task->context == context) { + ret = TRUE; task->valid = FALSE; + } } SILC_SCHEDULE_UNLOCK(schedule); + + return ret; } /* Invalidate task by all */ -void silc_schedule_task_del_by_all(SilcSchedule schedule, int fd, - SilcTaskCallback callback, void *context) +SilcBool silc_schedule_task_del_by_all(SilcSchedule schedule, int fd, + SilcTaskCallback callback, + void *context) { SilcTask task; SilcList list; + SilcBool ret = FALSE; SILC_LOG_DEBUG(("Unregister task by fd, callback and context")); /* For fd task, callback and context is irrelevant as fd is unique */ if (fd) - silc_schedule_task_del_by_fd(schedule, fd); + return silc_schedule_task_del_by_fd(schedule, fd); SILC_SCHEDULE_LOCK(schedule); @@ -800,11 +825,15 @@ void silc_schedule_task_del_by_all(SilcSchedule schedule, int fd, list = schedule->timeout_queue; silc_list_start(list); while ((task = (SilcTask)silc_list_get(list))) { - if (task->callback == callback && task->context == context) + if (task->callback == callback && task->context == context) { task->valid = FALSE; + ret = TRUE; + } } SILC_SCHEDULE_UNLOCK(schedule); + + return TRUE; } /* Sets a file descriptor to be listened by scheduler. One can call this diff --git a/lib/silcutil/silcschedule.h b/lib/silcutil/silcschedule.h index dff50dfc..2151e72c 100644 --- a/lib/silcutil/silcschedule.h +++ b/lib/silcutil/silcschedule.h @@ -440,97 +440,103 @@ void *silc_schedule_get_context(SilcSchedule schedule); * * SYNOPSIS * - * void silc_schedule_task_del(SilcSchedule schedule, SilcTask task); + * SilcBool silc_schedule_task_del(SilcSchedule schedule, SilcTask task); * * DESCRIPTION * * Deletes the `task' from the scheduler indicated by the `schedule'. * After deleting the task it is guaranteed that the task callback * will not be called. If the `task' is SILC_ALL_TASKS then all - * tasks is removed from the scheduler. + * tasks is removed from the scheduler. Returns always TRUE. * * It is safe to call this function in any place. Tasks may be removed * in task callbacks (including in the task's own task callback) and * in multi-threaded environment in other threads as well. * ***/ -void silc_schedule_task_del(SilcSchedule schedule, SilcTask task); +SilcBool silc_schedule_task_del(SilcSchedule schedule, SilcTask task); /****f* silcutil/SilcScheduleAPI/silc_schedule_task_del_by_fd * * SYNOPSIS * - * void silc_schedule_task_del_by_fd(SilcSchedule schedule, SilcUInt32 fd); + * SilcBool silc_schedule_task_del_by_fd(SilcSchedule schedule, + * SilcUInt32 fd); * * DESCRIPTION * - * Deletes a task from the scheduler by the specified `fd'. + * Deletes a task from the scheduler by the specified `fd'. Returns + * FALSE if such fd task does not exist. * * It is safe to call this function in any place. Tasks may be removed * in task callbacks (including in the task's own task callback) and * in multi-threaded environment in other threads as well. * ***/ -void silc_schedule_task_del_by_fd(SilcSchedule schedule, SilcUInt32 fd); +SilcBool silc_schedule_task_del_by_fd(SilcSchedule schedule, SilcUInt32 fd); /****f* silcutil/SilcScheduleAPI/silc_schedule_task_del_by_callback * * SYNOPSIS * - * void silc_schedule_task_del_by_callback(SilcSchedule schedule, - * SilcTaskCallback callback); + * SilcBool silc_schedule_task_del_by_callback(SilcSchedule schedule, + * SilcTaskCallback callback); * * DESCRIPTION * * Deletes a task from the scheduler by the specified `callback' task - * callback function. + * callback function. Returns FALSE if such task with such callback + * does not exist. * * It is safe to call this function in any place. Tasks may be removed * in task callbacks (including in the task's own task callback) and * in multi-threaded environment in other threads as well. * ***/ -void silc_schedule_task_del_by_callback(SilcSchedule schedule, - SilcTaskCallback callback); +SilcBool silc_schedule_task_del_by_callback(SilcSchedule schedule, + SilcTaskCallback callback); /****f* silcutil/SilcScheduleAPI/silc_schedule_task_del_by_context * * SYNOPSIS * - * void silc_schedule_task_del_by_context(SilcSchedule schedule, - * void *context); + * SilcBool silc_schedule_task_del_by_context(SilcSchedule schedule, + * void *context); * * DESCRIPTION * - * Deletes a task from the scheduler by the specified `context'. + * Deletes a task from the scheduler by the specified `context'. Returns + * FALSE if such task with such context does not exist. * * It is safe to call this function in any place. Tasks may be removed * in task callbacks (including in the task's own task callback) and * in multi-threaded environment in other threads as well. * ***/ -void silc_schedule_task_del_by_context(SilcSchedule schedule, void *context); +SilcBool silc_schedule_task_del_by_context(SilcSchedule schedule, + void *context); /****f* silcutil/SilcScheduleAPI/silc_schedule_task_del_by_all * * SYNOPSIS * - * void silc_schedule_task_del_by_all(SilcSchedule schedule, int fd, - * SilcTaskCallback callback, - * void *context); + * SilcBool silc_schedule_task_del_by_all(SilcSchedule schedule, int fd, + * SilcTaskCallback callback, + * void *context); * * DESCRIPTION * * Deletes a task from the scheduler by the specified `fd', `callback' - * and `context'. + * and `context'. Returns FALSE if such task does not exist. * * It is safe to call this function in any place. Tasks may be removed * in task callbacks (including in the task's own task callback) and * in multi-threaded environment in other threads as well. * ***/ -void silc_schedule_task_del_by_all(SilcSchedule schedule, int fd, - SilcTaskCallback callback, void *context); +SilcBool silc_schedule_task_del_by_all(SilcSchedule schedule, int fd, + SilcTaskCallback callback, + void *context); /****f* silcutil/SilcScheduleAPI/silc_schedule_set_listen_fd * -- 2.24.0