From 05e0ca51673774842b7156cfa6bbbcbb591fcdcb Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Tue, 9 Feb 2010 22:43:36 +0000 Subject: make sure we run ALL shutdown tasks before resuming execution of new 'normal' tasks --- src/include/gnunet_scheduler_lib.h | 12 +++++++++++- src/util/scheduler.c | 16 +++++++++------- src/util/server.c | 2 +- 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/src/include/gnunet_scheduler_lib.h b/src/include/gnunet_scheduler_lib.h index 3205729a3..79739ef16 100644 --- a/src/include/gnunet_scheduler_lib.h +++ b/src/include/gnunet_scheduler_lib.h @@ -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" diff --git a/src/util/scheduler.c b/src/util/scheduler.c index 6b12c7d1a..dfc751048 100644 --- a/src/util/scheduler.c +++ b/src/util/scheduler.c @@ -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; diff --git a/src/util/server.c b/src/util/server.c index 62dea6d90..32008bce8 100644 --- a/src/util/server.c +++ b/src/util/server.c @@ -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; } -- cgit v1.2.3