allow any function in a task to easily get the reason code
authorChristian Grothoff <christian@grothoff.org>
Tue, 10 Nov 2009 19:45:42 +0000 (19:45 +0000)
committerChristian Grothoff <christian@grothoff.org>
Tue, 10 Nov 2009 19:45:42 +0000 (19:45 +0000)
src/include/gnunet_scheduler_lib.h
src/util/scheduler.c

index 760a674d5b03264af180c5db484e1903406230df..16fd2e807db78ff0ef162f75165918f77fa9baaf 100644 (file)
@@ -241,6 +241,18 @@ unsigned int GNUNET_SCHEDULER_get_load (struct GNUNET_SCHEDULER_Handle *sched,
                                         enum GNUNET_SCHEDULER_Priority p);
 
 
+/**
+ * Obtain the reason code for why the current task was
+ * started.  Will return the same value as 
+ * the GNUNET_SCHEDULER_TaskContext's reason field.
+ *
+ * @param sched scheduler to query
+ * @return reason(s) why the current task is run
+ */
+enum GNUNET_SCHEDULER_Reason
+GNUNET_SCHEDULER_get_reason (struct GNUNET_SCHEDULER_Handle *sched);
+
+
 /**
  * Cancel the task with the specified identifier.
  * The task must not yet have run.
index 85a5cba53a4124710dcc55f98368910610ec1eef..ee4a9a4f3b761875a63b2f2ba90992e04650d28f 100644 (file)
@@ -109,6 +109,11 @@ struct GNUNET_SCHEDULER_Handle
    */
   struct Task *pending;
 
+  /**
+   * ID of the task that is running right now.
+   */
+  struct Task *active_task;
+
   /**
    * List of tasks ready to run right now,
    * grouped by importance.
@@ -456,6 +461,7 @@ run_ready (struct GNUNET_SCHEDULER_Handle *sched)
       sched->ready_count--;
       sched->current_priority = p;
       GNUNET_assert (pos->priority == p);
+      sched->active_task = pos;
       tc.sched = sched;
       tc.reason = pos->reason;
       tc.read_ready = pos->read_set;
@@ -465,6 +471,7 @@ run_ready (struct GNUNET_SCHEDULER_Handle *sched)
       GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                   "Running task: %llu / %p\n", pos->id, pos->callback_cls);
 #endif
+      sched->active_task = NULL;
       destroy_task (pos);
       sched->tasks_run++;
     }
@@ -601,6 +608,20 @@ GNUNET_SCHEDULER_run (GNUNET_SCHEDULER_Task task, void *task_cls)
 }
 
 
+/**
+ * Obtain the reason code for why the current task was
+ * started.  Will return the same value as 
+ * the GNUNET_SCHEDULER_TaskContext's reason field.
+ *
+ * @param sched scheduler to query
+ * @return reason(s) why the current task is run
+ */
+enum GNUNET_SCHEDULER_Reason
+GNUNET_SCHEDULER_get_reason (struct GNUNET_SCHEDULER_Handle *sched)
+{
+  return sched->active_task->reason;
+}
+
 
 /**
  * Get information about the current load of this scheduler.  Use this