/* Delete from fd queue */
silc_hash_table_list(schedule->fd_queue, &htl);
- while (silc_hash_table_get(&htl, (void **)&fd, (void **)&task))
+ while (silc_hash_table_get(&htl, (void *)&fd, (void *)&task))
silc_hash_table_del(schedule->fd_queue, SILC_32_TO_PTR(fd));
silc_hash_table_list_reset(&htl);
schedule->fd_queue =
silc_hash_table_alloc(0, silc_hash_uint, NULL, NULL, NULL,
silc_schedule_fd_destructor, NULL, TRUE);
- if (!schedule->fd_queue)
+ if (!schedule->fd_queue) {
+ silc_free(schedule);
return NULL;
+ }
silc_list_init(schedule->timeout_queue, struct SilcTaskStruct, next);
silc_list_init(schedule->free_tasks, struct SilcTaskStruct, next);
/* Initialize the platform specific scheduler. */
schedule->internal = schedule_ops.init(schedule, app_context);
+ if (!schedule->internal) {
+ silc_hash_table_free(schedule->fd_queue);
+ silc_mutex_free(schedule->lock);
+ silc_free(schedule);
+ return NULL;
+ }
/* Timeout freelist garbage collection */
silc_schedule_task_add_timeout(schedule, silc_schedule_timeout_gc,
/* Check if fd is already added */
if (silc_unlikely(silc_hash_table_find(schedule->fd_queue,
SILC_32_TO_PTR(fd),
- NULL, (void **)&task))) {
+ NULL, (void *)&task))) {
if (task->valid)
goto out;
/* 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;
/* Delete from fd queue */
silc_hash_table_list(schedule->fd_queue, &htl);
- while (silc_hash_table_get(&htl, NULL, (void **)&task))
+ while (silc_hash_table_get(&htl, NULL, (void *)&task))
task->valid = FALSE;
silc_hash_table_list_reset(&htl);
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));
/* fd is unique, so there is only one task with this fd in the table */
if (silc_likely(silc_hash_table_find(schedule->fd_queue,
SILC_32_TO_PTR(fd), NULL,
- (void **)&task))) {
+ (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"));
/* 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)
+ while (silc_hash_table_get(&htl, NULL, (void *)&task)) {
+ if (task->callback == callback) {
task->valid = FALSE;
+ ret = TRUE;
+ }
}
silc_hash_table_list_reset(&htl);
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"));
/* 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)
+ while (silc_hash_table_get(&htl, NULL, (void *)&task)) {
+ if (task->context == context) {
task->valid = FALSE;
+ ret = TRUE;
+ }
}
silc_hash_table_list_reset(&htl);
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);
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
SILC_SCHEDULE_LOCK(schedule);
if (silc_hash_table_find(schedule->fd_queue, SILC_32_TO_PTR(fd),
- NULL, (void **)&task)) {
+ NULL, (void *)&task)) {
if (!schedule_ops.schedule_fd(schedule, schedule->internal, task, mask)) {
SILC_SCHEDULE_UNLOCK(schedule);
return FALSE;
SILC_SCHEDULE_LOCK(schedule);
if (silc_hash_table_find(schedule->fd_queue, SILC_32_TO_PTR(fd),
- NULL, (void **)&task))
+ NULL, (void *)&task))
event = task->events;
SILC_SCHEDULE_UNLOCK(schedule);