updates.
[silc.git] / lib / silcutil / silcschedule.c
index 1d727c6b900605ef9a8276fa27bd3e832c1605aa..bd046a8f4e84044c0b2243f9c767c0a44dcf27bb 100644 (file)
@@ -200,6 +200,9 @@ SilcSchedule silc_schedule_init(int max_tasks)
   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;
@@ -269,14 +272,17 @@ static void silc_schedule_dispatch_nontimeout(SilcSchedule schedule)
 {
   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. */
@@ -328,8 +334,7 @@ static void silc_schedule_dispatch_nontimeout(SilcSchedule schedule)
        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);
        }
@@ -338,8 +343,7 @@ static void silc_schedule_dispatch_nontimeout(SilcSchedule schedule)
        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);
        }