From 02aaa9eeefb8f1c408ccf02cf3a2e7a2a7bed58d Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Tue, 10 Nov 2009 19:45:42 +0000 Subject: allow any function in a task to easily get the reason code --- src/include/gnunet_scheduler_lib.h | 12 ++++++++++++ src/util/scheduler.c | 21 +++++++++++++++++++++ 2 files changed, 33 insertions(+) (limited to 'src') diff --git a/src/include/gnunet_scheduler_lib.h b/src/include/gnunet_scheduler_lib.h index 760a674d5..16fd2e807 100644 --- a/src/include/gnunet_scheduler_lib.h +++ b/src/include/gnunet_scheduler_lib.h @@ -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. diff --git a/src/util/scheduler.c b/src/util/scheduler.c index 85a5cba53..ee4a9a4f3 100644 --- a/src/util/scheduler.c +++ b/src/util/scheduler.c @@ -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 -- cgit v1.2.3