diff options
author | Christian Grothoff <christian@grothoff.org> | 2009-11-10 19:45:42 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2009-11-10 19:45:42 +0000 |
commit | 02aaa9eeefb8f1c408ccf02cf3a2e7a2a7bed58d (patch) | |
tree | 5521c168af82f8aba1995b87b1ba7fcea7e412f1 /src | |
parent | 1351e32fa8ffcd56fc6329f4a68ccc83d0cf0cc5 (diff) | |
download | gnunet-02aaa9eeefb8f1c408ccf02cf3a2e7a2a7bed58d.tar.gz gnunet-02aaa9eeefb8f1c408ccf02cf3a2e7a2a7bed58d.zip |
allow any function in a task to easily get the reason code
Diffstat (limited to 'src')
-rw-r--r-- | src/include/gnunet_scheduler_lib.h | 12 | ||||
-rw-r--r-- | src/util/scheduler.c | 21 |
2 files changed, 33 insertions, 0 deletions
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 | |||
@@ -242,6 +242,18 @@ unsigned int GNUNET_SCHEDULER_get_load (struct GNUNET_SCHEDULER_Handle *sched, | |||
242 | 242 | ||
243 | 243 | ||
244 | /** | 244 | /** |
245 | * Obtain the reason code for why the current task was | ||
246 | * started. Will return the same value as | ||
247 | * the GNUNET_SCHEDULER_TaskContext's reason field. | ||
248 | * | ||
249 | * @param sched scheduler to query | ||
250 | * @return reason(s) why the current task is run | ||
251 | */ | ||
252 | enum GNUNET_SCHEDULER_Reason | ||
253 | GNUNET_SCHEDULER_get_reason (struct GNUNET_SCHEDULER_Handle *sched); | ||
254 | |||
255 | |||
256 | /** | ||
245 | * Cancel the task with the specified identifier. | 257 | * Cancel the task with the specified identifier. |
246 | * The task must not yet have run. | 258 | * The task must not yet have run. |
247 | * | 259 | * |
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 | |||
@@ -110,6 +110,11 @@ struct GNUNET_SCHEDULER_Handle | |||
110 | struct Task *pending; | 110 | struct Task *pending; |
111 | 111 | ||
112 | /** | 112 | /** |
113 | * ID of the task that is running right now. | ||
114 | */ | ||
115 | struct Task *active_task; | ||
116 | |||
117 | /** | ||
113 | * List of tasks ready to run right now, | 118 | * List of tasks ready to run right now, |
114 | * grouped by importance. | 119 | * grouped by importance. |
115 | */ | 120 | */ |
@@ -456,6 +461,7 @@ run_ready (struct GNUNET_SCHEDULER_Handle *sched) | |||
456 | sched->ready_count--; | 461 | sched->ready_count--; |
457 | sched->current_priority = p; | 462 | sched->current_priority = p; |
458 | GNUNET_assert (pos->priority == p); | 463 | GNUNET_assert (pos->priority == p); |
464 | sched->active_task = pos; | ||
459 | tc.sched = sched; | 465 | tc.sched = sched; |
460 | tc.reason = pos->reason; | 466 | tc.reason = pos->reason; |
461 | tc.read_ready = pos->read_set; | 467 | tc.read_ready = pos->read_set; |
@@ -465,6 +471,7 @@ run_ready (struct GNUNET_SCHEDULER_Handle *sched) | |||
465 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 471 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
466 | "Running task: %llu / %p\n", pos->id, pos->callback_cls); | 472 | "Running task: %llu / %p\n", pos->id, pos->callback_cls); |
467 | #endif | 473 | #endif |
474 | sched->active_task = NULL; | ||
468 | destroy_task (pos); | 475 | destroy_task (pos); |
469 | sched->tasks_run++; | 476 | sched->tasks_run++; |
470 | } | 477 | } |
@@ -601,6 +608,20 @@ GNUNET_SCHEDULER_run (GNUNET_SCHEDULER_Task task, void *task_cls) | |||
601 | } | 608 | } |
602 | 609 | ||
603 | 610 | ||
611 | /** | ||
612 | * Obtain the reason code for why the current task was | ||
613 | * started. Will return the same value as | ||
614 | * the GNUNET_SCHEDULER_TaskContext's reason field. | ||
615 | * | ||
616 | * @param sched scheduler to query | ||
617 | * @return reason(s) why the current task is run | ||
618 | */ | ||
619 | enum GNUNET_SCHEDULER_Reason | ||
620 | GNUNET_SCHEDULER_get_reason (struct GNUNET_SCHEDULER_Handle *sched) | ||
621 | { | ||
622 | return sched->active_task->reason; | ||
623 | } | ||
624 | |||
604 | 625 | ||
605 | /** | 626 | /** |
606 | * Get information about the current load of this scheduler. Use this | 627 | * Get information about the current load of this scheduler. Use this |