make sure we run ALL shutdown tasks before resuming execution of new 'normal' tasks
authorChristian Grothoff <christian@grothoff.org>
Tue, 9 Feb 2010 22:43:36 +0000 (22:43 +0000)
committerChristian Grothoff <christian@grothoff.org>
Tue, 9 Feb 2010 22:43:36 +0000 (22:43 +0000)
src/include/gnunet_scheduler_lib.h
src/util/scheduler.c
src/util/server.c

index 3205729a3ff82ebbdcb9c9bba6aede10988d6334..79739ef16956384256a79b28a04affe6b2f239bf 100644 (file)
@@ -141,11 +141,21 @@ enum GNUNET_SCHEDULER_Priority
    */
   GNUNET_SCHEDULER_PRIORITY_URGENT = 6,
 
+  /**
+   * This is an internal priority level that is only used for tasks
+   * that are being triggered due to shutdown (they have automatically
+   * highest priority).  User code must not use this priority level
+   * directly.  Tasks run with this priority level that internally
+   * schedule other tasks will see their original priority level
+   * be inherited (unless otherwise specified).
+   */
+  GNUNET_SCHEDULER_PRIORITY_SHUTDOWN = 7,
+
   /**
    * Number of priorities (must be the last priority).
    * This priority must not be used by clients.
    */
-  GNUNET_SCHEDULER_PRIORITY_COUNT = 7
+  GNUNET_SCHEDULER_PRIORITY_COUNT = 8
 };
 
 #include "gnunet_time_lib.h"
index 6b12c7d1a2cabc518d4a3787e3a1f445c49576ac..dfc7510481e5368235da1acaf1ca9af61925a670 100644 (file)
@@ -60,10 +60,9 @@ struct Task
   struct GNUNET_NETWORK_FDSet *read_set;
 
   /**
-   * Set of file descriptors this task is waiting
-   * for for writing.  Once ready, this is updated
-   * to reflect the set of file descriptors ready
-   * for operation.
+   * Set of file descriptors this task is waiting for for writing.
+   * Once ready, this is updated to reflect the set of file
+   * descriptors ready for operation.
    */
   struct GNUNET_NETWORK_FDSet *write_set;
 
@@ -334,8 +333,11 @@ is_ready (struct GNUNET_SCHEDULER_Handle *sched,
 static void
 queue_ready_task (struct GNUNET_SCHEDULER_Handle *handle, struct Task *task)
 {
-  task->next = handle->ready[check_priority (task->priority)];
-  handle->ready[check_priority (task->priority)] = task;
+  enum GNUNET_SCHEDULER_Priority p = task->priority;
+  if (0 != (task->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
+    p = GNUNET_SCHEDULER_PRIORITY_SHUTDOWN;
+  task->next = handle->ready[check_priority (p)];
+  handle->ready[check_priority (p)] = task;
   handle->ready_count++;
 }
 
@@ -472,7 +474,7 @@ run_ready (struct GNUNET_SCHEDULER_Handle *sched)
       GNUNET_assert (pos != NULL);      /* ready_count wrong? */
       sched->ready[p] = pos->next;
       sched->ready_count--;
-      sched->current_priority = p;
+      sched->current_priority = pos->priority;
       GNUNET_assert (pos->priority == p);
       sched->active_task = pos;
       tc.sched = sched;
index 62dea6d90a3eac69d268130082ea2ea82bc02c06..32008bce8bef3e12967cf412331d27eb7249c636 100644 (file)
@@ -779,7 +779,7 @@ process_incoming (void *cls,
       (client->shutdown_now == GNUNET_YES) ||
       (GNUNET_YES != client->check (client->client_closure)))
     {
-      /* other side closed connection, error connecting, etc. */
+      /* other side closed connection, error connecting, etc. */      
       shutdown_incoming_processing (client);
       return;
     }