silc_task_queue_alloc(&schedule->timeout_queue);
silc_task_queue_alloc(&schedule->generic_queue);
+ if (!max_tasks)
+ max_tasks = 200;
+
/* Initialize the scheduler */
schedule->fd_list = silc_calloc(max_tasks, sizeof(*schedule->fd_list));
schedule->max_fd = max_tasks;
{
SilcTask task;
int i, last_fd = schedule->last_fd;
+ uint32 fd;
for (i = 0; i <= last_fd; i++) {
if (schedule->fd_list[i].events == 0)
continue;
+ fd = schedule->fd_list[i].fd;
+
/* First check whether this fd has task in the fd queue */
silc_mutex_lock(schedule->fd_queue->lock);
- task = silc_task_find(schedule->fd_queue, schedule->fd_list[i].fd);
+ task = silc_task_find(schedule->fd_queue, fd);
/* If the task was found then execute its callbacks. If not then
execute all generic tasks for that fd. */
if (task->valid && schedule->fd_list[i].revents & SILC_TASK_READ) {
silc_mutex_unlock(schedule->generic_queue->lock);
silc_mutex_unlock(schedule->lock);
- task->callback(schedule, SILC_TASK_READ, schedule->fd_list[i].fd,
- task->context);
+ task->callback(schedule, SILC_TASK_READ, fd, task->context);
silc_mutex_lock(schedule->lock);
silc_mutex_lock(schedule->generic_queue->lock);
}
if (task->valid && schedule->fd_list[i].revents & SILC_TASK_WRITE) {
silc_mutex_unlock(schedule->generic_queue->lock);
silc_mutex_unlock(schedule->lock);
- task->callback(schedule, SILC_TASK_WRITE, schedule->fd_list[i].fd,
- task->context);
+ task->callback(schedule, SILC_TASK_WRITE, fd, task->context);
silc_mutex_lock(schedule->lock);
silc_mutex_lock(schedule->generic_queue->lock);
}