From: Christian Grothoff Date: Wed, 4 Nov 2009 14:10:32 +0000 (+0000) Subject: bugfixes and redesigning scheduler API X-Git-Tag: initial-import-from-subversion-38251~23168 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=cf45b8dff29c366d51aa2e6ea6a64b99b514b9c9;p=oweals%2Fgnunet.git bugfixes and redesigning scheduler API --- diff --git a/BUGS b/BUGS index f2af53241..504ff2c21 100644 --- a/BUGS +++ b/BUGS @@ -2,6 +2,10 @@ This file lists minor work items (also possibly called "known bugs"). We are not tracking them in Mantis yet since there are too many and no sane end-user should care about this codebase yet anyway. +* TESTING: + - connection.c:553 fails when "make check" is run! + (check if this could be memory corruption). + * UTIL: - container_bloomfilter: improve efficiency (see FIXME) diff --git a/src/arm/gnunet-arm.c b/src/arm/gnunet-arm.c index 09a1305a5..d0748f173 100644 --- a/src/arm/gnunet-arm.c +++ b/src/arm/gnunet-arm.c @@ -123,7 +123,6 @@ confirm_cb (void *cls, int success) break; } GNUNET_SCHEDULER_add_continuation (sched, - GNUNET_NO, &cps_loop, NULL, GNUNET_SCHEDULER_REASON_PREREQ_DONE); @@ -147,7 +146,6 @@ confirm_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) else fprintf (stdout, _("Service `%s' is not running.\n"), service); GNUNET_SCHEDULER_add_continuation (sched, - GNUNET_NO, &cps_loop, NULL, GNUNET_SCHEDULER_REASON_PREREQ_DONE); @@ -181,7 +179,6 @@ run (void *cls, return; } GNUNET_SCHEDULER_add_continuation (sched, - GNUNET_NO, &cps_loop, NULL, GNUNET_SCHEDULER_REASON_PREREQ_DONE); diff --git a/src/arm/gnunet-service-arm.c b/src/arm/gnunet-service-arm.c index ebb9c337e..bfb3896bf 100644 --- a/src/arm/gnunet-service-arm.c +++ b/src/arm/gnunet-service-arm.c @@ -516,9 +516,6 @@ stop_service (struct GNUNET_SERVER_Client *client, pos->kill_continuation_cls = client; GNUNET_SERVER_client_keep (client); GNUNET_SCHEDULER_add_delayed (sched, - GNUNET_YES, - GNUNET_SCHEDULER_PRIORITY_IDLE, - GNUNET_SCHEDULER_NO_TASK, MAINT_FAST_FREQUENCY, &maint, NULL); } else @@ -641,9 +638,6 @@ maint (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) } if (cls == NULL) GNUNET_SCHEDULER_add_delayed (tc->sched, - GNUNET_YES, - GNUNET_SCHEDULER_PRIORITY_IDLE, - GNUNET_SCHEDULER_NO_TASK, MAINT_FREQUENCY, &maint, NULL); /* check for services that died (WAITPID) */ @@ -800,11 +794,9 @@ run (void *cls, GNUNET_SERVER_add_handlers (server, handlers); /* manage services */ - GNUNET_SCHEDULER_add_delayed (sched, - GNUNET_YES, - GNUNET_SCHEDULER_PRIORITY_IDLE, - GNUNET_SCHEDULER_NO_TASK, - MAINT_FREQUENCY, &maint, NULL); + GNUNET_SCHEDULER_add_with_priority (sched, + GNUNET_SCHEDULER_PRIORITY_IDLE, + &maint, NULL); } @@ -820,7 +812,7 @@ main (int argc, char *const *argv) { return (GNUNET_OK == GNUNET_SERVICE_run (argc, - argv, "arm", &run, NULL, NULL, NULL)) ? 0 : 1; + argv, "arm", &run, NULL)) ? 0 : 1; } /* end of gnunet-service-arm.c */ diff --git a/src/core/core_api.c b/src/core/core_api.c index 1a74eb7d0..91055dd03 100644 --- a/src/core/core_api.c +++ b/src/core/core_api.c @@ -320,9 +320,6 @@ request_start (void *cls, size_t size, void *buf) } /* create new timeout task (in case core takes too long to respond!) */ th->timeout_task = GNUNET_SCHEDULER_add_delayed (h->sched, - GNUNET_NO, - GNUNET_SCHEDULER_PRIORITY_KEEP, - GNUNET_SCHEDULER_NO_TASK, GNUNET_TIME_absolute_get_remaining (th->timeout), &timeout_request, th); @@ -748,9 +745,7 @@ transmit_start (void *cls, size_t size, void *buf) h->startup_timeout = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_MINUTES); h->reconnect_task = - GNUNET_SCHEDULER_add_delayed (h->sched, GNUNET_NO, - GNUNET_SCHEDULER_PRIORITY_IDLE, - GNUNET_SCHEDULER_NO_TASK, + GNUNET_SCHEDULER_add_delayed (h->sched, delay, &reconnect_task, h); return 0; } @@ -990,9 +985,6 @@ GNUNET_CORE_peer_configure (struct GNUNET_CORE_Handle *handle, th->info_cls = info_cls; th->timeout = GNUNET_TIME_relative_to_absolute (timeout); th->timeout_task = GNUNET_SCHEDULER_add_delayed (handle->sched, - GNUNET_NO, - GNUNET_SCHEDULER_PRIORITY_KEEP, - GNUNET_SCHEDULER_NO_TASK, timeout, &timeout_request, th); th->msize = sizeof (struct RequestConfigureMessage); @@ -1112,9 +1104,6 @@ GNUNET_CORE_notify_transmit_ready (struct GNUNET_CORE_Handle *handle, th->peer = *target; th->timeout = GNUNET_TIME_relative_to_absolute (maxdelay); th->timeout_task = GNUNET_SCHEDULER_add_delayed (handle->sched, - GNUNET_NO, - GNUNET_SCHEDULER_PRIORITY_KEEP, - GNUNET_SCHEDULER_NO_TASK, maxdelay, &timeout_request, th); th->priority = priority; diff --git a/src/core/gnunet-service-core.c b/src/core/gnunet-service-core.c index 1d272b873..839eb2727 100644 --- a/src/core/gnunet-service-core.c +++ b/src/core/gnunet-service-core.c @@ -1703,9 +1703,6 @@ process_plaintext_neighbour_queue (struct Neighbour *n) /* no messages selected for sending, try again later... */ n->retry_plaintext_task = GNUNET_SCHEDULER_add_delayed (sched, - GNUNET_NO, - GNUNET_SCHEDULER_PRIORITY_IDLE, - GNUNET_SCHEDULER_NO_TASK, retry_time, &retry_plaintext_processing, n); return; @@ -2154,9 +2151,6 @@ send_key (struct Neighbour *n) if (n->status != PEER_STATE_KEY_CONFIRMED) n->retry_set_key_task = GNUNET_SCHEDULER_add_delayed (sched, - GNUNET_NO, - GNUNET_SCHEDULER_PRIORITY_KEEP, - GNUNET_SCHEDULER_NO_TASK, n->set_key_retry_frequency, &set_key_retry_task, n); } @@ -2894,9 +2888,6 @@ schedule_quota_update (struct Neighbour *n) GNUNET_SCHEDULER_NO_TASK); n->quota_update_task = GNUNET_SCHEDULER_add_delayed (sched, - GNUNET_NO, - GNUNET_SCHEDULER_PRIORITY_IDLE, - GNUNET_SCHEDULER_NO_TASK, QUOTA_UPDATE_FREQUENCY, &neighbour_quota_update, n); @@ -3114,6 +3105,8 @@ cleaning_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) } while (NULL != (c = clients)) handle_client_disconnect (NULL, c->client_handle); + if (my_private_key != NULL) + GNUNET_CRYPTO_rsa_key_free (my_private_key); } @@ -3198,9 +3191,6 @@ run (void *cls, &handle_transport_notify_disconnect); GNUNET_assert (NULL != transport); GNUNET_SCHEDULER_add_delayed (sched, - GNUNET_YES, - GNUNET_SCHEDULER_PRIORITY_IDLE, - GNUNET_SCHEDULER_NO_TASK, GNUNET_TIME_UNIT_FOREVER_REL, &cleaning_task, NULL); /* process client requests */ @@ -3210,17 +3200,6 @@ run (void *cls, } -/** - * Function called during shutdown. Clean up our state. - */ -static void -cleanup (void *cls, - const struct GNUNET_CONFIGURATION_Handle *cfg) -{ - if (my_private_key != NULL) - GNUNET_CRYPTO_rsa_key_free (my_private_key); -} - /** * The main function for the transport service. @@ -3235,7 +3214,7 @@ main (int argc, char *const *argv) return (GNUNET_OK == GNUNET_SERVICE_run (argc, argv, - "core", &run, NULL, &cleanup, NULL)) ? 0 : 1; + "core", &run, NULL)) ? 0 : 1; } /* end of gnunet-service-core.c */ diff --git a/src/core/test_core_api.c b/src/core/test_core_api.c index 89aa34f5b..ebd4e8e99 100644 --- a/src/core/test_core_api.c +++ b/src/core/test_core_api.c @@ -172,9 +172,6 @@ process_mtype (void *cls, OKPP; GNUNET_SCHEDULER_cancel (sched, err_task); GNUNET_SCHEDULER_add_delayed (sched, - GNUNET_NO, - GNUNET_SCHEDULER_PRIORITY_KEEP, - GNUNET_SCHEDULER_NO_TASK, GNUNET_TIME_UNIT_ZERO, &terminate_task, NULL); return GNUNET_OK; } @@ -201,9 +198,6 @@ transmit_ready (void *cls, size_t size, void *buf) m->size = htons (sizeof (struct GNUNET_MessageHeader)); err_task = GNUNET_SCHEDULER_add_delayed (sched, - GNUNET_NO, - GNUNET_SCHEDULER_PRIORITY_KEEP, - GNUNET_SCHEDULER_NO_TASK, GNUNET_TIME_UNIT_MINUTES, &terminate_task_error, NULL); return sizeof (struct GNUNET_MessageHeader); @@ -300,7 +294,6 @@ setup_peer (struct PeerContext *p, const char *cfgname) "-L", "DEBUG", #endif "-c", cfgname, NULL); - sleep (1); /* allow ARM to start */ #endif GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); GNUNET_ARM_start_services (p->cfg, sched, "core", NULL); diff --git a/src/core/test_core_api_start_only.c b/src/core/test_core_api_start_only.c index ce2668b89..5ca750664 100644 --- a/src/core/test_core_api_start_only.c +++ b/src/core/test_core_api_start_only.c @@ -166,7 +166,6 @@ setup_peer (struct PeerContext *p, const char *cfgname) "-L", "DEBUG", #endif "-c", cfgname, NULL); - sleep (1); /* allow ARM to start */ #endif GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); GNUNET_ARM_start_services (p->cfg, sched, "core", NULL); diff --git a/src/datastore/gnunet-service-datastore.c b/src/datastore/gnunet-service-datastore.c index 3a22f9bda..27b1cd58e 100644 --- a/src/datastore/gnunet-service-datastore.c +++ b/src/datastore/gnunet-service-datastore.c @@ -260,9 +260,6 @@ expired_processor (void *cls, { expired_kill_task = GNUNET_SCHEDULER_add_delayed (sched, - GNUNET_NO, - GNUNET_SCHEDULER_PRIORITY_IDLE, - GNUNET_SCHEDULER_NO_TASK, MAX_EXPIRE_DELAY, &delete_expired, NULL); @@ -1209,7 +1206,7 @@ cleaning_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) GNUNET_CONTAINER_bloomfilter_free (filter); filter = NULL; } - // GNUNET_ARM_stop_services (cfg, tc->sched, "statistics", NULL); + GNUNET_ARM_stop_services (cfg, tc->sched, "statistics", NULL); } @@ -1307,28 +1304,22 @@ run (void *cls, _("Failed to initialize bloomfilter.\n")); return; } -// GNUNET_ARM_start_services (cfg, sched, "statistics", NULL); + GNUNET_ARM_start_services (cfg, sched, "statistics", NULL); plugin = load_plugin (); if (NULL == plugin) { GNUNET_CONTAINER_bloomfilter_free (filter); filter = NULL; -// GNUNET_ARM_stop_services (cfg, sched, "statistics", NULL); + GNUNET_ARM_stop_services (cfg, sched, "statistics", NULL); return; } GNUNET_SERVER_disconnect_notify (server, &cleanup_reservations, NULL); GNUNET_SERVER_add_handlers (server, handlers); expired_kill_task - = GNUNET_SCHEDULER_add_delayed (sched, - GNUNET_NO, - GNUNET_SCHEDULER_PRIORITY_IDLE, - GNUNET_SCHEDULER_NO_TASK, - GNUNET_TIME_UNIT_ZERO, - &delete_expired, NULL); + = GNUNET_SCHEDULER_add_with_priority (sched, + GNUNET_SCHEDULER_PRIORITY_IDLE, + &delete_expired, NULL); GNUNET_SCHEDULER_add_delayed (sched, - GNUNET_YES, - GNUNET_SCHEDULER_PRIORITY_IDLE, - GNUNET_SCHEDULER_NO_TASK, GNUNET_TIME_UNIT_FOREVER_REL, &cleaning_task, NULL); @@ -1350,7 +1341,7 @@ main (int argc, char *const *argv) ret = (GNUNET_OK == GNUNET_SERVICE_run (argc, argv, - "datastore", &run, NULL, NULL, NULL)) ? 0 : 1; + "datastore", &run, NULL)) ? 0 : 1; return ret; } diff --git a/src/datastore/perf_datastore_api.c b/src/datastore/perf_datastore_api.c index 2344dafe8..34adf0c7d 100644 --- a/src/datastore/perf_datastore_api.c +++ b/src/datastore/perf_datastore_api.c @@ -140,7 +140,6 @@ check_success (void *cls, crc->phase = RP_CUT; } GNUNET_SCHEDULER_add_continuation (crc->sched, - GNUNET_NO, &run_continuation, crc, GNUNET_SCHEDULER_REASON_PREREQ_DONE); @@ -167,7 +166,6 @@ remove_next(void *cls, #endif GNUNET_assert (GNUNET_OK == success); GNUNET_SCHEDULER_add_continuation (crc->sched, - GNUNET_NO, &run_continuation, crc, GNUNET_SCHEDULER_REASON_PREREQ_DONE); @@ -214,18 +212,15 @@ delete_value (void *cls, { crc->phase = RP_REPORT; GNUNET_SCHEDULER_add_continuation (crc->sched, - GNUNET_NO, &run_continuation, crc, GNUNET_SCHEDULER_REASON_PREREQ_DONE); return; } - GNUNET_SCHEDULER_add_after (crc->sched, - GNUNET_NO, - GNUNET_SCHEDULER_PRIORITY_HIGH, - GNUNET_SCHEDULER_NO_TASK, - &do_delete, - crc); + GNUNET_SCHEDULER_add_with_priority (crc->sched, + GNUNET_SCHEDULER_PRIORITY_HIGH, + &do_delete, + crc); return; } stored_ops++; @@ -303,7 +298,6 @@ run_continuation (void *cls, crc->phase = RP_PUT; crc->j = 0; GNUNET_SCHEDULER_add_continuation (crc->sched, - GNUNET_NO, &run_continuation, crc, GNUNET_SCHEDULER_REASON_PREREQ_DONE); @@ -335,7 +329,6 @@ run (void *cls, crc->cfg = cfg; crc->phase = RP_PUT; GNUNET_SCHEDULER_add_continuation (crc->sched, - GNUNET_NO, &run_continuation, crc, GNUNET_SCHEDULER_REASON_PREREQ_DONE); @@ -364,7 +357,6 @@ check () "-L", "DEBUG", #endif "-c", "test_datastore_api_data.conf", NULL); - sleep (1); GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, argv, "perf-datastore-api", "nohelp", options, &run, NULL); diff --git a/src/datastore/perf_plugin_datastore.c b/src/datastore/perf_plugin_datastore.c index b7bc9db31..a23569875 100644 --- a/src/datastore/perf_plugin_datastore.c +++ b/src/datastore/perf_plugin_datastore.c @@ -168,8 +168,6 @@ iterateDummy (void *cls, crc->phase = RP_PUT; } GNUNET_SCHEDULER_add_after (crc->sched, - GNUNET_NO, - GNUNET_SCHEDULER_PRIORITY_KEEP, GNUNET_SCHEDULER_NO_TASK, &test, crc); return GNUNET_OK; @@ -254,8 +252,6 @@ test (void *cls, crc->i++; crc->phase = RP_LP_GET; GNUNET_SCHEDULER_add_after (crc->sched, - GNUNET_NO, - GNUNET_SCHEDULER_PRIORITY_KEEP, GNUNET_SCHEDULER_NO_TASK, &test, crc); break; @@ -301,11 +297,8 @@ test (void *cls, break; case RP_DONE: crc->api->drop (crc->api->cls); - GNUNET_SCHEDULER_add_delayed (crc->sched, - GNUNET_YES, + GNUNET_SCHEDULER_add_with_priority (crc->sched, GNUNET_SCHEDULER_PRIORITY_IDLE, - GNUNET_SCHEDULER_NO_TASK, - GNUNET_TIME_UNIT_ZERO, &cleaning_task, crc); break; } @@ -364,8 +357,6 @@ run (void *cls, crc->cfg = c; crc->phase = RP_PUT; GNUNET_SCHEDULER_add_after (s, - GNUNET_YES, - GNUNET_SCHEDULER_PRIORITY_KEEP, GNUNET_SCHEDULER_NO_TASK, &test, crc); } diff --git a/src/datastore/plugin_datastore_sqlite.c b/src/datastore/plugin_datastore_sqlite.c index e673bafa4..1607ba5e0 100644 --- a/src/datastore/plugin_datastore_sqlite.c +++ b/src/datastore/plugin_datastore_sqlite.c @@ -663,7 +663,6 @@ sqlite_next_request (void *next_cls, if (GNUNET_YES == end_it) nc->end_it = GNUNET_YES; GNUNET_SCHEDULER_add_continuation (nc->plugin->env->sched, - GNUNET_NO, &sqlite_next_request_cont, nc, GNUNET_SCHEDULER_REASON_PREREQ_DONE); diff --git a/src/datastore/test_datastore_api.c b/src/datastore/test_datastore_api.c index 605cb042d..5d4443cbe 100644 --- a/src/datastore/test_datastore_api.c +++ b/src/datastore/test_datastore_api.c @@ -145,7 +145,6 @@ check_success (void *cls, GNUNET_free_non_null (crc->data); crc->data = NULL; GNUNET_SCHEDULER_add_continuation (crc->sched, - GNUNET_NO, &run_continuation, crc, GNUNET_SCHEDULER_REASON_PREREQ_DONE); @@ -164,7 +163,6 @@ get_reserved (void *cls, GNUNET_assert (0 < success); crc->rid = success; GNUNET_SCHEDULER_add_continuation (crc->sched, - GNUNET_NO, &run_continuation, crc, GNUNET_SCHEDULER_REASON_PREREQ_DONE); @@ -193,7 +191,6 @@ check_value (void *cls, crc->i = ITERATIONS; } GNUNET_SCHEDULER_add_continuation (crc->sched, - GNUNET_NO, &run_continuation, crc, GNUNET_SCHEDULER_REASON_PREREQ_DONE); @@ -226,7 +223,6 @@ delete_value (void *cls, { crc->phase = RP_DO_DEL; GNUNET_SCHEDULER_add_continuation (crc->sched, - GNUNET_NO, &run_continuation, crc, GNUNET_SCHEDULER_REASON_PREREQ_DONE); @@ -259,7 +255,6 @@ check_nothing (void *cls, crc->phase = RP_RESERVE; } GNUNET_SCHEDULER_add_continuation (crc->sched, - GNUNET_NO, &run_continuation, crc, GNUNET_SCHEDULER_REASON_PREREQ_DONE); @@ -284,7 +279,6 @@ check_multiple (void *cls, GNUNET_assert (crc->phase == RP_GET_MULTIPLE_DONE); crc->phase = RP_UPDATE; GNUNET_SCHEDULER_add_continuation (crc->sched, - GNUNET_NO, &run_continuation, crc, GNUNET_SCHEDULER_REASON_PREREQ_DONE); @@ -315,7 +309,6 @@ check_update (void *cls, GNUNET_assert (crc->phase == RP_UPDATE_DONE); crc->phase = RP_DONE; GNUNET_SCHEDULER_add_continuation (crc->sched, - GNUNET_NO, &run_continuation, crc, GNUNET_SCHEDULER_REASON_PREREQ_DONE); @@ -542,7 +535,6 @@ run (void *cls, now = GNUNET_TIME_absolute_get (); datastore = GNUNET_DATASTORE_connect (cfg, sched); GNUNET_SCHEDULER_add_continuation (crc->sched, - GNUNET_NO, &run_continuation, crc, GNUNET_SCHEDULER_REASON_PREREQ_DONE); @@ -572,7 +564,6 @@ check () "-L", "DEBUG", #endif "-c", "test_datastore_api_data.conf", NULL); - sleep (1); GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, argv, "test-datastore-api", "nohelp", options, &run, NULL); diff --git a/src/datastore/test_datastore_api_management.c b/src/datastore/test_datastore_api_management.c index 48daebb1d..cad789a6f 100644 --- a/src/datastore/test_datastore_api_management.c +++ b/src/datastore/test_datastore_api_management.c @@ -133,7 +133,6 @@ check_success (void *cls, GNUNET_free_non_null (crc->data); crc->data = NULL; GNUNET_SCHEDULER_add_continuation (crc->sched, - GNUNET_NO, &run_continuation, crc, GNUNET_SCHEDULER_REASON_PREREQ_DONE); @@ -171,7 +170,6 @@ check_value (void *cls, if (0 == crc->i) crc->phase = RP_DONE; GNUNET_SCHEDULER_add_continuation (crc->sched, - GNUNET_NO, &run_continuation, crc, GNUNET_SCHEDULER_REASON_PREREQ_DONE); @@ -206,7 +204,6 @@ check_nothing (void *cls, if (0 == --crc->i) crc->phase = RP_DONE; GNUNET_SCHEDULER_add_continuation (crc->sched, - GNUNET_NO, &run_continuation, crc, GNUNET_SCHEDULER_REASON_PREREQ_DONE); @@ -310,7 +307,6 @@ run (void *cls, now = GNUNET_TIME_absolute_get (); datastore = GNUNET_DATASTORE_connect (cfg, sched); GNUNET_SCHEDULER_add_continuation (crc->sched, - GNUNET_NO, &run_continuation, crc, GNUNET_SCHEDULER_REASON_PREREQ_DONE); @@ -340,7 +336,6 @@ check () "-L", "DEBUG", #endif "-c", "test_datastore_api_data.conf", NULL); - sleep (1); GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, argv, "test-datastore-api", "nohelp", options, &run, NULL); diff --git a/src/fs/fs_download.c b/src/fs/fs_download.c index e92eb85c1..4b3d96082 100644 --- a/src/fs/fs_download.c +++ b/src/fs/fs_download.c @@ -718,9 +718,6 @@ try_reconnect (struct GNUNET_FS_DownloadContext *dc) } dc->task = GNUNET_SCHEDULER_add_delayed (dc->h->sched, - GNUNET_NO, - GNUNET_SCHEDULER_PRIORITY_IDLE, - GNUNET_SCHEDULER_NO_TASK, GNUNET_TIME_UNIT_SECONDS, &do_reconnect, dc); diff --git a/src/fs/fs_list_indexed.c b/src/fs/fs_list_indexed.c index 9ef205ca0..d182f9aa4 100644 --- a/src/fs/fs_list_indexed.c +++ b/src/fs/fs_list_indexed.c @@ -91,7 +91,6 @@ handle_index_info (void *cls, "GET_INDEXED", "fs"); GNUNET_SCHEDULER_add_continuation (gic->h->sched, - GNUNET_NO, gic->cont, gic->cont_cls, GNUNET_SCHEDULER_REASON_TIMEOUT); @@ -103,7 +102,6 @@ handle_index_info (void *cls, { /* normal end-of-list */ GNUNET_SCHEDULER_add_continuation (gic->h->sched, - GNUNET_NO, gic->cont, gic->cont_cls, GNUNET_SCHEDULER_REASON_PREREQ_DONE); @@ -124,7 +122,6 @@ handle_index_info (void *cls, "GET_INDEXED", "fs"); GNUNET_SCHEDULER_add_continuation (gic->h->sched, - GNUNET_NO, gic->cont, gic->cont_cls, GNUNET_SCHEDULER_REASON_TIMEOUT); @@ -138,7 +135,6 @@ handle_index_info (void *cls, &iim->file_id)) { GNUNET_SCHEDULER_add_continuation (gic->h->sched, - GNUNET_NO, gic->cont, gic->cont_cls, GNUNET_SCHEDULER_REASON_PREREQ_DONE); @@ -185,7 +181,6 @@ GNUNET_FS_get_indexed_files (struct GNUNET_FS_Handle *h, _("Failed to not connect to `%s' service.\n"), "fs"); GNUNET_SCHEDULER_add_continuation (h->sched, - GNUNET_NO, cont, cont_cls, GNUNET_SCHEDULER_REASON_TIMEOUT); diff --git a/src/fs/fs_publish.c b/src/fs/fs_publish.c index 721951970..bef03a45e 100644 --- a/src/fs/fs_publish.c +++ b/src/fs/fs_publish.c @@ -185,13 +185,10 @@ ds_put_cont (void *cls, GNUNET_FS_file_information_sync (pcc->p); if (NULL != pcc->cont) pcc->sc->upload_task - = GNUNET_SCHEDULER_add_delayed (pcc->sc->h->sched, - GNUNET_NO, - GNUNET_SCHEDULER_PRIORITY_BACKGROUND, - GNUNET_SCHEDULER_NO_TASK, - GNUNET_TIME_UNIT_ZERO, - pcc->cont, - pcc->cont_cls); + = GNUNET_SCHEDULER_add_with_priority (pcc->sc->h->sched, + GNUNET_SCHEDULER_PRIORITY_BACKGROUND, + pcc->cont, + pcc->cont_cls); GNUNET_free (pcc); } @@ -325,13 +322,10 @@ publish_kblocks_cont (void *cls, { signal_publish_error (p, sc, emsg); sc->upload_task - = GNUNET_SCHEDULER_add_delayed (sc->h->sched, - GNUNET_NO, - GNUNET_SCHEDULER_PRIORITY_BACKGROUND, - GNUNET_SCHEDULER_NO_TASK, - GNUNET_TIME_UNIT_ZERO, - &do_upload, - sc); + = GNUNET_SCHEDULER_add_with_priority (sc->h->sched, + GNUNET_SCHEDULER_PRIORITY_BACKGROUND, + &do_upload, + sc); return; } GNUNET_FS_file_information_sync (p); @@ -343,13 +337,10 @@ publish_kblocks_cont (void *cls, else sc->fi_pos = p->dir; sc->upload_task - = GNUNET_SCHEDULER_add_delayed (sc->h->sched, - GNUNET_NO, - GNUNET_SCHEDULER_PRIORITY_BACKGROUND, - GNUNET_SCHEDULER_NO_TASK, - GNUNET_TIME_UNIT_ZERO, - &do_upload, - sc); + = GNUNET_SCHEDULER_add_with_priority (sc->h->sched, + GNUNET_SCHEDULER_PRIORITY_BACKGROUND, + &do_upload, + sc); } @@ -446,11 +437,8 @@ encode_cont (void *cls, } /* continue with main */ sc->upload_task - = GNUNET_SCHEDULER_add_delayed (sc->h->sched, - GNUNET_NO, - GNUNET_SCHEDULER_PRIORITY_BACKGROUND, - GNUNET_SCHEDULER_NO_TASK, - GNUNET_TIME_UNIT_ZERO, + = GNUNET_SCHEDULER_add_with_priority (sc->h->sched, + GNUNET_SCHEDULER_PRIORITY_BACKGROUND, &do_upload, sc); } @@ -486,11 +474,8 @@ block_proc (void *cls, if (NULL == sc->dsh) { sc->upload_task - = GNUNET_SCHEDULER_add_delayed (sc->h->sched, - GNUNET_NO, + = GNUNET_SCHEDULER_add_with_priority (sc->h->sched, GNUNET_SCHEDULER_PRIORITY_BACKGROUND, - GNUNET_SCHEDULER_NO_TASK, - GNUNET_TIME_UNIT_ZERO, &do_upload, sc); return; @@ -910,7 +895,6 @@ do_upload (void *cls, else GNUNET_CRYPTO_hash_file (sc->h->sched, GNUNET_SCHEDULER_PRIORITY_IDLE, - GNUNET_NO, p->data.file.filename, HASHING_BLOCKSIZE, &hash_for_index_cb, @@ -1018,11 +1002,8 @@ GNUNET_FS_publish_start (struct GNUNET_FS_Handle *h, // and reserve as first task (then trigger // "do_upload" from that continuation)! ret->upload_task - = GNUNET_SCHEDULER_add_delayed (h->sched, - GNUNET_NO, + = GNUNET_SCHEDULER_add_with_priority (h->sched, GNUNET_SCHEDULER_PRIORITY_BACKGROUND, - GNUNET_SCHEDULER_NO_TASK, - GNUNET_TIME_UNIT_ZERO, &do_upload, ret); return ret; @@ -1217,7 +1198,6 @@ kb_put_cont (void *cls, return; } GNUNET_SCHEDULER_add_continuation (pkc->h->sched, - GNUNET_NO, &publish_ksk_cont, pkc, GNUNET_SCHEDULER_REASON_PREREQ_DONE); @@ -1383,7 +1363,6 @@ GNUNET_FS_publish_ksk (struct GNUNET_FS_Handle *h, pkc->cpy->purpose.purpose = htonl(GNUNET_SIGNATURE_PURPOSE_FS_KBLOCK); pkc->ksk_uri = GNUNET_FS_uri_dup (ksk_uri); GNUNET_SCHEDULER_add_continuation (h->sched, - GNUNET_NO, &publish_ksk_cont, pkc, GNUNET_SCHEDULER_REASON_PREREQ_DONE); diff --git a/src/fs/fs_search.c b/src/fs/fs_search.c index 8b986ec7c..5d03046e2 100644 --- a/src/fs/fs_search.c +++ b/src/fs/fs_search.c @@ -720,9 +720,6 @@ try_reconnect (struct GNUNET_FS_SearchContext *sc) } sc->task = GNUNET_SCHEDULER_add_delayed (sc->h->sched, - GNUNET_NO, - GNUNET_SCHEDULER_PRIORITY_IDLE, - GNUNET_SCHEDULER_NO_TASK, GNUNET_TIME_UNIT_SECONDS, &do_reconnect, sc); diff --git a/src/fs/fs_tree.c b/src/fs/fs_tree.c index 83da423f3..4d15d78f3 100644 --- a/src/fs/fs_tree.c +++ b/src/fs/fs_tree.c @@ -287,7 +287,6 @@ void GNUNET_FS_tree_encoder_next (struct GNUNET_FS_TreeEncoder * te) &te->emsg)) { GNUNET_SCHEDULER_add_continuation (te->h->sched, - GNUNET_NO, te->cont, te->cls, GNUNET_SCHEDULER_REASON_TIMEOUT); @@ -309,7 +308,6 @@ void GNUNET_FS_tree_encoder_next (struct GNUNET_FS_TreeEncoder * te) te->uri->data.chk.chk = te->chk_tree[0]; te->uri->data.chk.file_length = GNUNET_htonll (te->size); GNUNET_SCHEDULER_add_continuation (te->h->sched, - GNUNET_NO, te->cont, te->cls, GNUNET_SCHEDULER_REASON_PREREQ_DONE); diff --git a/src/fs/fs_unindex.c b/src/fs/fs_unindex.c index 0c3738753..243209b0e 100644 --- a/src/fs/fs_unindex.c +++ b/src/fs/fs_unindex.c @@ -420,7 +420,6 @@ GNUNET_FS_unindex_start (struct GNUNET_FS_Handle *h, &pi); GNUNET_CRYPTO_hash_file (h->sched, GNUNET_SCHEDULER_PRIORITY_IDLE, - GNUNET_NO, filename, HASHING_BLOCKSIZE, &process_hash, diff --git a/src/fs/gnunet-service-fs.c b/src/fs/gnunet-service-fs.c index 5148c4675..ca6b9b426 100644 --- a/src/fs/gnunet-service-fs.c +++ b/src/fs/gnunet-service-fs.c @@ -1075,7 +1075,6 @@ handle_index_start (void *cls, /* slow validation, need to hash full file (again) */ GNUNET_CRYPTO_hash_file (sched, GNUNET_SCHEDULER_PRIORITY_IDLE, - GNUNET_NO, fn, HASHING_BLOCKSIZE, &hash_for_index_val, @@ -1287,9 +1286,6 @@ queue_ds_request (struct GNUNET_TIME_Relative deadline, if (deadline.value == GNUNET_TIME_UNIT_FOREVER_REL.value) return e; e->task = GNUNET_SCHEDULER_add_delayed (sched, - GNUNET_NO, - GNUNET_SCHEDULER_PRIORITY_BACKGROUND, - GNUNET_SCHEDULER_NO_TASK, deadline, &timeout_ds_request, e); @@ -1718,13 +1714,10 @@ transmit_request_cb (void *cls, if (NULL == buf) { /* timeout, try another peer immediately again */ - pr->task = GNUNET_SCHEDULER_add_delayed (sched, - GNUNET_NO, - GNUNET_SCHEDULER_PRIORITY_IDLE, - GNUNET_SCHEDULER_NO_TASK, - GNUNET_TIME_UNIT_ZERO, - &forward_request_task, - pr); + pr->task = GNUNET_SCHEDULER_add_with_priority (sched, + GNUNET_SCHEDULER_PRIORITY_IDLE, + &forward_request_task, + pr); return 0; } /* (2) build query message */ @@ -1751,9 +1744,6 @@ transmit_request_cb (void *cls, /* (3) schedule job to do it again (or another peer, etc.) */ pr->task = GNUNET_SCHEDULER_add_delayed (sched, - GNUNET_NO, - GNUNET_SCHEDULER_PRIORITY_IDLE, - GNUNET_SCHEDULER_NO_TASK, get_processing_delay (), // FIXME! &forward_request_task, pr); @@ -1797,9 +1787,6 @@ target_reservation_cb (void *cls, { /* try again later; FIXME: we may need to un-reserve "amount"? */ pr->task = GNUNET_SCHEDULER_add_delayed (sched, - GNUNET_NO, - GNUNET_SCHEDULER_PRIORITY_IDLE, - GNUNET_SCHEDULER_NO_TASK, get_processing_delay (), // FIXME: longer? &forward_request_task, pr); @@ -1821,9 +1808,6 @@ target_reservation_cb (void *cls, { /* try again later */ pr->task = GNUNET_SCHEDULER_add_delayed (sched, - GNUNET_NO, - GNUNET_SCHEDULER_PRIORITY_IDLE, - GNUNET_SCHEDULER_NO_TASK, get_processing_delay (), // FIXME: longer? &forward_request_task, pr); @@ -1854,9 +1838,6 @@ forward_request_task (void *cls, { /* we're busy transmitting a result, wait a bit */ pr->task = GNUNET_SCHEDULER_add_delayed (sched, - GNUNET_NO, - GNUNET_SCHEDULER_PRIORITY_IDLE, - GNUNET_SCHEDULER_NO_TASK, get_processing_delay (), &forward_request_task, pr); @@ -1872,9 +1853,6 @@ forward_request_task (void *cls, { /* no possible target found, wait some time */ pr->task = GNUNET_SCHEDULER_add_delayed (sched, - GNUNET_NO, - GNUNET_SCHEDULER_PRIORITY_IDLE, - GNUNET_SCHEDULER_NO_TASK, get_processing_delay (), // FIXME: exponential back-off? or at least wait longer... &forward_request_task, pr); @@ -1998,9 +1976,6 @@ process_local_get_result (void *cls, pr, GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); pr->task = GNUNET_SCHEDULER_add_delayed (sched, - GNUNET_NO, - GNUNET_SCHEDULER_PRIORITY_IDLE, - GNUNET_SCHEDULER_NO_TASK, get_processing_delay (), &forward_request_task, pr); @@ -2132,7 +2107,6 @@ transmit_local_get_ready (void *cls, GNUNET_assert (GNUNET_OK == ok); GNUNET_SCHEDULER_add_continuation (sched, - GNUNET_NO, &transmit_local_get, lgc, GNUNET_SCHEDULER_REASON_PREREQ_DONE); @@ -2514,9 +2488,6 @@ forward_get_request (void *cls, destroy_pending_request (eer); } pr->task = GNUNET_SCHEDULER_add_delayed (sched, - GNUNET_NO, - GNUNET_SCHEDULER_PRIORITY_IDLE, - GNUNET_SCHEDULER_NO_TASK, get_processing_delay (), &forward_request_task, pr); @@ -2617,7 +2588,6 @@ process_p2p_get_result (void *cls, (pgc->type == GNUNET_DATASTORE_BLOCKTYPE_SKBLOCK) ) ) { GNUNET_SCHEDULER_add_continuation (sched, - GNUNET_NO, &forward_get_request, pgc, GNUNET_SCHEDULER_REASON_PREREQ_DONE); @@ -2942,7 +2912,6 @@ handle_p2p_get (void *cls, pgc); else GNUNET_SCHEDULER_add_continuation (sched, - GNUNET_NO, &forward_get_request, pgc, GNUNET_SCHEDULER_REASON_PREREQ_DONE); @@ -3338,9 +3307,6 @@ core_start_cb (void *cls, if (server == NULL) { GNUNET_SCHEDULER_add_delayed (sched, - GNUNET_NO, - GNUNET_SCHEDULER_PRIORITY_HIGH, - GNUNET_SCHEDULER_NO_TASK, GNUNET_TIME_UNIT_SECONDS, &core_connect_task, NULL); @@ -3412,9 +3378,6 @@ run (void *cls, GNUNET_SERVER_add_handlers (server, handlers); core_connect_task (NULL, NULL); GNUNET_SCHEDULER_add_delayed (sched, - GNUNET_YES, - GNUNET_SCHEDULER_PRIORITY_IDLE, - GNUNET_SCHEDULER_NO_TASK, GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task, NULL); @@ -3434,7 +3397,7 @@ main (int argc, char *const *argv) return (GNUNET_OK == GNUNET_SERVICE_run (argc, argv, - "fs", &run, NULL, NULL, NULL)) ? 0 : 1; + "fs", &run, NULL)) ? 0 : 1; } /* end of gnunet-service-fs.c */ diff --git a/src/fs/test_fs_download.c b/src/fs/test_fs_download.c index 04cd3e5d8..4e73ef182 100644 --- a/src/fs/test_fs_download.c +++ b/src/fs/test_fs_download.c @@ -29,7 +29,7 @@ #include "gnunet_arm_service.h" #include "gnunet_fs_service.h" -#define VERBOSE GNUNET_NO +#define VERBOSE GNUNET_YES #define START_ARM GNUNET_YES @@ -133,7 +133,6 @@ progress_cb (void *cls, printf ("Download complete, %llu kbps.\n", (unsigned long long) (FILESIZE * 1000 / (1+GNUNET_TIME_absolute_get_duration (start).value) / 1024)); GNUNET_SCHEDULER_add_continuation (sched, - GNUNET_NO, &abort_download_task, NULL, GNUNET_SCHEDULER_REASON_PREREQ_DONE); @@ -154,7 +153,6 @@ progress_cb (void *cls, event->value.publish.specifics.error.message); GNUNET_break (0); GNUNET_SCHEDULER_add_continuation (sched, - GNUNET_NO, &abort_publish_task, NULL, GNUNET_SCHEDULER_REASON_PREREQ_DONE); @@ -164,7 +162,6 @@ progress_cb (void *cls, "Error downloading file: %s\n", event->value.download.specifics.error.message); GNUNET_SCHEDULER_add_continuation (sched, - GNUNET_NO, &abort_download_task, NULL, GNUNET_SCHEDULER_REASON_PREREQ_DONE); @@ -196,7 +193,6 @@ progress_cb (void *cls, case GNUNET_FS_STATUS_DOWNLOAD_STOPPED: GNUNET_assert (download == event->value.download.dc); GNUNET_SCHEDULER_add_continuation (sched, - GNUNET_NO, &abort_publish_task, NULL, GNUNET_SCHEDULER_REASON_PREREQ_DONE); diff --git a/src/fs/test_fs_list_indexed.c b/src/fs/test_fs_list_indexed.c index 868c9d71a..f9225e3ce 100644 --- a/src/fs/test_fs_list_indexed.c +++ b/src/fs/test_fs_list_indexed.c @@ -97,7 +97,6 @@ list_indexed_task (void *cls, { GNUNET_SCHEDULER_add_continuation (sched, - GNUNET_NO, &abort_publish_task, NULL, GNUNET_SCHEDULER_REASON_PREREQ_DONE); @@ -120,7 +119,6 @@ progress_cb (void *cls, if (0 == strcmp ("list_indexed-context-dir", event->value.publish.cctx)) GNUNET_SCHEDULER_add_continuation (sched, - GNUNET_NO, &list_indexed_task, NULL, GNUNET_SCHEDULER_REASON_PREREQ_DONE); @@ -146,7 +144,6 @@ progress_cb (void *cls, if (0 == strcmp ("list_indexed-context-dir", event->value.publish.cctx)) GNUNET_SCHEDULER_add_continuation (sched, - GNUNET_NO, &abort_publish_task, NULL, GNUNET_SCHEDULER_REASON_PREREQ_DONE); diff --git a/src/fs/test_fs_publish.c b/src/fs/test_fs_publish.c index 1b79b941d..a7bcd48d9 100644 --- a/src/fs/test_fs_publish.c +++ b/src/fs/test_fs_publish.c @@ -106,7 +106,6 @@ progress_cb (void *cls, if (0 == strcmp ("list_indexed-context-dir", event->value.publish.cctx)) GNUNET_SCHEDULER_add_continuation (sched, - GNUNET_NO, &abort_publish_task, NULL, GNUNET_SCHEDULER_REASON_PREREQ_DONE); @@ -131,7 +130,6 @@ progress_cb (void *cls, if (0 == strcmp ("list_indexed-context-dir", event->value.publish.cctx)) GNUNET_SCHEDULER_add_continuation (sched, - GNUNET_NO, &abort_publish_task, NULL, GNUNET_SCHEDULER_REASON_PREREQ_DONE); @@ -171,7 +169,6 @@ progress_cb (void *cls, { GNUNET_assert (publish == event->value.publish.sc); GNUNET_SCHEDULER_add_continuation (sched, - GNUNET_NO, &abort_publish_task, NULL, GNUNET_SCHEDULER_REASON_PREREQ_DONE); diff --git a/src/fs/test_fs_search.c b/src/fs/test_fs_search.c index d1b5f77aa..e0961c4a7 100644 --- a/src/fs/test_fs_search.c +++ b/src/fs/test_fs_search.c @@ -124,7 +124,6 @@ progress_cb (void *cls, printf ("Search complete.\n"); #endif GNUNET_SCHEDULER_add_continuation (sched, - GNUNET_NO, &abort_search_task, NULL, GNUNET_SCHEDULER_REASON_PREREQ_DONE); @@ -135,7 +134,6 @@ progress_cb (void *cls, event->value.publish.specifics.error.message); GNUNET_break (0); GNUNET_SCHEDULER_add_continuation (sched, - GNUNET_NO, &abort_publish_task, NULL, GNUNET_SCHEDULER_REASON_PREREQ_DONE); @@ -145,7 +143,6 @@ progress_cb (void *cls, "Error searching file: %s\n", event->value.search.specifics.error.message); GNUNET_SCHEDULER_add_continuation (sched, - GNUNET_NO, &abort_search_task, NULL, GNUNET_SCHEDULER_REASON_PREREQ_DONE); @@ -174,7 +171,6 @@ progress_cb (void *cls, case GNUNET_FS_STATUS_SEARCH_STOPPED: GNUNET_assert (search == event->value.search.sc); GNUNET_SCHEDULER_add_continuation (sched, - GNUNET_NO, &abort_publish_task, NULL, GNUNET_SCHEDULER_REASON_PREREQ_DONE); diff --git a/src/fs/test_fs_unindex.c b/src/fs/test_fs_unindex.c index eb10c1db9..af9db7400 100644 --- a/src/fs/test_fs_unindex.c +++ b/src/fs/test_fs_unindex.c @@ -121,7 +121,6 @@ progress_cb (void *cls, printf ("Unindex complete, %llu kbps.\n", (unsigned long long) (FILESIZE * 1000 / (1+GNUNET_TIME_absolute_get_duration (start).value) / 1024)); GNUNET_SCHEDULER_add_continuation (sched, - GNUNET_NO, &abort_unindex_task, NULL, GNUNET_SCHEDULER_REASON_PREREQ_DONE); @@ -142,7 +141,6 @@ progress_cb (void *cls, event->value.publish.specifics.error.message); GNUNET_break (0); GNUNET_SCHEDULER_add_continuation (sched, - GNUNET_NO, &abort_publish_task, NULL, GNUNET_SCHEDULER_REASON_PREREQ_DONE); @@ -152,7 +150,6 @@ progress_cb (void *cls, "Error unindexing file: %s\n", event->value.unindex.specifics.error.message); GNUNET_SCHEDULER_add_continuation (sched, - GNUNET_NO, &abort_unindex_task, NULL, GNUNET_SCHEDULER_REASON_PREREQ_DONE); @@ -181,7 +178,6 @@ progress_cb (void *cls, case GNUNET_FS_STATUS_UNINDEX_STOPPED: GNUNET_assert (unindex == event->value.unindex.uc); GNUNET_SCHEDULER_add_continuation (sched, - GNUNET_NO, &abort_publish_task, NULL, GNUNET_SCHEDULER_REASON_PREREQ_DONE); diff --git a/src/hostlist/gnunet-daemon-hostlist.c b/src/hostlist/gnunet-daemon-hostlist.c index 5aa4e70ea..78584cac9 100644 --- a/src/hostlist/gnunet-daemon-hostlist.c +++ b/src/hostlist/gnunet-daemon-hostlist.c @@ -177,9 +177,6 @@ run (void *cls, NULL, GNUNET_NO, handlers); GNUNET_SCHEDULER_add_delayed (sched, - GNUNET_YES, - GNUNET_SCHEDULER_PRIORITY_IDLE, - GNUNET_SCHEDULER_NO_TASK, GNUNET_TIME_UNIT_FOREVER_REL, &cleaning_task, NULL); } diff --git a/src/hostlist/hostlist-client.c b/src/hostlist/hostlist-client.c index e0ff1f5a2..8ef5c9895 100644 --- a/src/hostlist/hostlist-client.c +++ b/src/hostlist/hostlist-client.c @@ -404,7 +404,6 @@ run_multi () GNUNET_NETWORK_fdset_copy_native (gws, &ws, max); current_task = GNUNET_SCHEDULER_add_select (sched, - GNUNET_NO, GNUNET_SCHEDULER_PRIORITY_DEFAULT, GNUNET_SCHEDULER_NO_TASK, GNUNET_TIME_UNIT_MINUTES, @@ -549,9 +548,6 @@ schedule_hostlist_task () hostlist_delay.value, GNUNET_YES); current_task = GNUNET_SCHEDULER_add_delayed (sched, - GNUNET_NO, - GNUNET_SCHEDULER_PRIORITY_IDLE, - GNUNET_SCHEDULER_NO_TASK, delay, &check_task, NULL); diff --git a/src/hostlist/hostlist-server.c b/src/hostlist/hostlist-server.c index 03e3c5d69..38e144a9d 100644 --- a/src/hostlist/hostlist-server.c +++ b/src/hostlist/hostlist-server.c @@ -92,9 +92,6 @@ finish_response (struct HostSet *results) GNUNET_free (results); /* schedule next update of the response */ GNUNET_SCHEDULER_add_delayed (sched, - GNUNET_NO, - GNUNET_SCHEDULER_PRIORITY_IDLE, - GNUNET_SCHEDULER_NO_TASK, RESPONSE_UPDATE_FREQUENCY, &update_response, NULL); @@ -252,7 +249,6 @@ prepare_daemon () GNUNET_NETWORK_fdset_copy_native (wes, &es, max); hostlist_task = GNUNET_SCHEDULER_add_select (sched, - GNUNET_NO, GNUNET_SCHEDULER_PRIORITY_HIGH, GNUNET_SCHEDULER_NO_TASK, tv, diff --git a/src/hostlist/test_gnunet_daemon_hostlist.c b/src/hostlist/test_gnunet_daemon_hostlist.c index d71340377..ca7a2369a 100644 --- a/src/hostlist/test_gnunet_daemon_hostlist.c +++ b/src/hostlist/test_gnunet_daemon_hostlist.c @@ -95,7 +95,6 @@ setup_peer (struct PeerContext *p, const char *cfgname) "-L", "DEBUG", #endif "-c", cfgname, NULL); - sleep (1); /* allow ARM to start */ #endif GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); GNUNET_ARM_start_services (p->cfg, sched, "core", NULL); diff --git a/src/include/gnunet_crypto_lib.h b/src/include/gnunet_crypto_lib.h index 76d28ad57..1dc9cb1aa 100644 --- a/src/include/gnunet_crypto_lib.h +++ b/src/include/gnunet_crypto_lib.h @@ -370,7 +370,6 @@ typedef void (*GNUNET_CRYPTO_HashCompletedCallback) (void *cls, * * @param sched scheduler to use * @param priority scheduling priority to use - * @param run_on_shutdown should we complete even on shutdown? * @param filename name of file to hash * @param blocksize number of bytes to process in one task * @param callback function to call upon completion @@ -378,7 +377,6 @@ typedef void (*GNUNET_CRYPTO_HashCompletedCallback) (void *cls, */ void GNUNET_CRYPTO_hash_file (struct GNUNET_SCHEDULER_Handle *sched, enum GNUNET_SCHEDULER_Priority priority, - int run_on_shutdown, const char *filename, size_t blocksize, GNUNET_CRYPTO_HashCompletedCallback callback, diff --git a/src/include/gnunet_scheduler_lib.h b/src/include/gnunet_scheduler_lib.h index 621e57fcf..760a674d5 100644 --- a/src/include/gnunet_scheduler_lib.h +++ b/src/include/gnunet_scheduler_lib.h @@ -197,21 +197,30 @@ typedef void (*GNUNET_SCHEDULER_Task) (void *cls, /** - * Initialize and run scheduler. This function will return when - * either a shutdown was initiated (via signal) and all tasks marked - * to "run_on_shutdown" have been completed or when all tasks in - * general have been completed. + * Initialize and run scheduler. This function will return when all + * tasks have completed. On systems with signals, receiving a SIGTERM + * (and other similar signals) will cause "GNUNET_SCHEDULER_shutdown" + * to be run after the active task is complete. As a result, SIGTERM + * causes all active tasks to be scheduled with reason + * "GNUNET_SCHEDULER_REASON_SHUTDOWN". (However, tasks added + * afterwards will execute normally!). Note that any particular + * signal will only shut down one scheduler; applications should + * always only create a single scheduler. * - * @param task task to run immediately - * @param cls closure of task + * @param task task to run first (and immediately) + * @param task_cls closure of task */ -void GNUNET_SCHEDULER_run (GNUNET_SCHEDULER_Task task, void *cls); +void GNUNET_SCHEDULER_run (GNUNET_SCHEDULER_Task task, void *task_cls); /** - * Request the shutdown of a scheduler. This function can be used to - * stop a scheduler, for example from within the signal - * handler for signals causing shutdowns. + * Request the shutdown of a scheduler. Marks all currently + * pending tasks as ready because of shutdown. This will + * cause all tasks to run (as soon as possible, respecting + * priorities and prerequisite tasks). Note that tasks + * scheduled AFTER this call may still be delayed arbitrarily. + * + * @param sched the scheduler */ void GNUNET_SCHEDULER_shutdown (struct GNUNET_SCHEDULER_Handle *sched); @@ -256,68 +265,70 @@ void *GNUNET_SCHEDULER_cancel (struct GNUNET_SCHEDULER_Handle *sched, */ void GNUNET_SCHEDULER_add_continuation (struct GNUNET_SCHEDULER_Handle *sched, - int run_on_shutdown, GNUNET_SCHEDULER_Task main, void *cls, enum GNUNET_SCHEDULER_Reason reason); /** - * Schedule a new task to be run after the specified - * prerequisite task has completed. + * Schedule a new task to be run after the specified prerequisite task + * has completed. It will be run with the priority of the calling + * task. * * @param sched scheduler to use - * @param run_on_shutdown run on shutdown? - * @param prio how important is this task? * @param prerequisite_task run this task after the task with the given * task identifier completes (and any of our other * conditions, such as delay, read or write-readyness * are satisfied). Use GNUNET_SCHEDULER_NO_TASK to not have any dependency - * on completion of other tasks. - * @param main main function of the task - * @param cls closure of task + * on completion of other tasks (this will cause the task to run as + * soon as possible). + * @param task main function of the task + * @param task_cls closure of task * @return unique task identifier for the job - * only valid until "main" is started! + * only valid until "task" is started! */ GNUNET_SCHEDULER_TaskIdentifier GNUNET_SCHEDULER_add_after (struct GNUNET_SCHEDULER_Handle *sched, - int run_on_shutdown, - enum GNUNET_SCHEDULER_Priority prio, GNUNET_SCHEDULER_TaskIdentifier prerequisite_task, - GNUNET_SCHEDULER_Task main, void *cls); + GNUNET_SCHEDULER_Task task, + void *task_cls); + + +/** + * Schedule a new task to be run with a specified priority. + * + * @param sched scheduler to use + * @param prio how important is the new task? + * @param task main function of the task + * @param task_cls closure of task + * @return unique task identifier for the job + * only valid until "task" is started! + */ +GNUNET_SCHEDULER_TaskIdentifier +GNUNET_SCHEDULER_add_with_priority (struct GNUNET_SCHEDULER_Handle *sched, + enum GNUNET_SCHEDULER_Priority prio, + GNUNET_SCHEDULER_Task task, + void *task_cls); /** * Schedule a new task to be run with a specified delay. The task - * will be scheduled for execution once the delay has expired and the - * prerequisite task has completed. + * will be scheduled for execution once the delay has expired. It + * will be run with the priority of the calling task. * * @param sched scheduler to use - * @param run_on_shutdown run on shutdown? You can use this - * argument to run a function only during shutdown - * by setting delay to -1. Set this - * argument to GNUNET_NO to skip this task if - * the user requested process termination. - * @param prio how important is this task? - * @param prerequisite_task run this task after the task with the given - * task identifier completes (and any of our other - * conditions, such as delay, read or write-readyness - * are satisfied). Use GNUNET_SCHEDULER_NO_TASK to not have any dependency - * on completion of other tasks. - * @param delay how long should we wait? Use GNUNET_TIME_UNIT_FOREVER_REL for "forever" - * @param main main function of the task - * @param cls closure of task + * @param delay when should this operation time out? Use + * GNUNET_TIME_UNIT_FOREVER_REL for "on shutdown" + * @param task main function of the task + * @param task_cls closure of task * @return unique task identifier for the job - * only valid until "main" is started! + * only valid until "task" is started! */ GNUNET_SCHEDULER_TaskIdentifier GNUNET_SCHEDULER_add_delayed (struct GNUNET_SCHEDULER_Handle *sched, - int run_on_shutdown, - enum GNUNET_SCHEDULER_Priority prio, - GNUNET_SCHEDULER_TaskIdentifier - prerequisite_task, struct GNUNET_TIME_Relative delay, - GNUNET_SCHEDULER_Task main, void *cls); + GNUNET_SCHEDULER_Task task, + void *task_cls); /** @@ -325,32 +336,24 @@ GNUNET_SCHEDULER_add_delayed (struct GNUNET_SCHEDULER_Handle *sched, * specified file descriptor is ready for reading. The delay can be * used as a timeout on the socket being ready. The task will be * scheduled for execution once either the delay has expired or the - * socket operation is ready. + * socket operation is ready. It will be run with the priority of + * the calling task. * * @param sched scheduler to use - * @param run_on_shutdown run on shutdown? Set this - * argument to GNUNET_NO to skip this task if - * the user requested process termination. - * @param prio how important is this task? - * @param prerequisite_task run this task after the task with the given - * task identifier completes (and any of our other - * conditions, such as delay, read or write-readyness - * are satisfied). Use GNUNET_SCHEDULER_NO_TASK to not have any dependency - * on completion of other tasks. - * @param delay how long should we wait? Use GNUNET_TIME_UNIT_FOREVER_REL for "forever" + * @param delay when should this operation time out? Use + * GNUNET_TIME_UNIT_FOREVER_REL for "on shutdown" * @param rfd read file-descriptor - * @param main main function of the task - * @param cls closure of task + * @param task main function of the task + * @param task_cls closure of task * @return unique task identifier for the job - * only valid until "main" is started! + * only valid until "task" is started! */ GNUNET_SCHEDULER_TaskIdentifier GNUNET_SCHEDULER_add_read_net (struct GNUNET_SCHEDULER_Handle *sched, - int run_on_shutdown, - enum GNUNET_SCHEDULER_Priority prio, - GNUNET_SCHEDULER_TaskIdentifier prerequisite_task, - struct GNUNET_TIME_Relative delay, - struct GNUNET_NETWORK_Handle *rfd, GNUNET_SCHEDULER_Task main, void *cls); + struct GNUNET_TIME_Relative delay, + struct GNUNET_NETWORK_Handle *rfd, + GNUNET_SCHEDULER_Task task, + void *task_cls); /** @@ -358,32 +361,24 @@ GNUNET_SCHEDULER_add_read_net (struct GNUNET_SCHEDULER_Handle *sched, * specified file descriptor is ready for writing. The delay can be * used as a timeout on the socket being ready. The task will be * scheduled for execution once either the delay has expired or the - * socket operation is ready. + * socket operation is ready. It will be run with the priority of + * the calling task. * * @param sched scheduler to use - * @param run_on_shutdown run on shutdown? Set this - * argument to GNUNET_NO to skip this task if - * the user requested process termination. - * @param prio how important is this task? - * @param prerequisite_task run this task after the task with the given - * task identifier completes (and any of our other - * conditions, such as delay, read or write-readyness - * are satisfied). Use GNUNET_SCHEDULER_NO_TASK to not have any dependency - * on completion of other tasks. - * @param delay how long should we wait? Use GNUNET_TIME_UNIT_FOREVER_REL for "forever" + * @param delay when should this operation time out? Use + * GNUNET_TIME_UNIT_FOREVER_REL for "on shutdown" * @param wfd write file-descriptor - * @param main main function of the task - * @param cls closure of task + * @param task main function of the task + * @param task_cls closure of task * @return unique task identifier for the job - * only valid until "main" is started! + * only valid until "task" is started! */ GNUNET_SCHEDULER_TaskIdentifier GNUNET_SCHEDULER_add_write_net (struct GNUNET_SCHEDULER_Handle *sched, - int run_on_shutdown, - enum GNUNET_SCHEDULER_Priority prio, - GNUNET_SCHEDULER_TaskIdentifier prerequisite_task, - struct GNUNET_TIME_Relative delay, - struct GNUNET_NETWORK_Handle *wfd, GNUNET_SCHEDULER_Task main, void *cls); + struct GNUNET_TIME_Relative delay, + struct GNUNET_NETWORK_Handle *wfd, + GNUNET_SCHEDULER_Task task, + void *task_cls); /** @@ -391,33 +386,24 @@ GNUNET_SCHEDULER_add_write_net (struct GNUNET_SCHEDULER_Handle *sched, * specified file descriptor is ready for reading. The delay can be * used as a timeout on the socket being ready. The task will be * scheduled for execution once either the delay has expired or the - * socket operation is ready. + * socket operation is ready. It will be run with the priority of + * the calling task. * * @param sched scheduler to use - * @param run_on_shutdown run on shutdown? Set this - * argument to GNUNET_NO to skip this task if - * the user requested process termination. - * @param prio how important is this task? - * @param prerequisite_task run this task after the task with the given - * task identifier completes (and any of our other - * conditions, such as delay, read or write-readyness - * are satisfied). Use GNUNET_SCHEDULER_NO_TASK to not have any dependency - * on completion of other tasks. - * @param delay how long should we wait? Use GNUNET_TIME_UNIT_FOREVER_REL for "forever" + * @param delay when should this operation time out? Use + * GNUNET_TIME_UNIT_FOREVER_REL for "on shutdown" * @param rfd read file-descriptor - * @param main main function of the task - * @param cls closure of task + * @param task main function of the task + * @param task_cls closure of task * @return unique task identifier for the job - * only valid until "main" is started! + * only valid until "task" is started! */ GNUNET_SCHEDULER_TaskIdentifier GNUNET_SCHEDULER_add_read_file (struct GNUNET_SCHEDULER_Handle *sched, - int run_on_shutdown, - enum GNUNET_SCHEDULER_Priority prio, - GNUNET_SCHEDULER_TaskIdentifier prerequisite_task, struct GNUNET_TIME_Relative delay, const struct GNUNET_DISK_FileHandle *rfd, - GNUNET_SCHEDULER_Task main, void *cls); + GNUNET_SCHEDULER_Task task, + void *task_cls); /** @@ -425,33 +411,24 @@ GNUNET_SCHEDULER_add_read_file (struct GNUNET_SCHEDULER_Handle *sched, * specified file descriptor is ready for writing. The delay can be * used as a timeout on the socket being ready. The task will be * scheduled for execution once either the delay has expired or the - * socket operation is ready. + * socket operation is ready. It will be run with the priority of + * the calling task. * * @param sched scheduler to use - * @param run_on_shutdown run on shutdown? Set this - * argument to GNUNET_NO to skip this task if - * the user requested process termination. - * @param prio how important is this task? - * @param prerequisite_task run this task after the task with the given - * task identifier completes (and any of our other - * conditions, such as delay, read or write-readyness - * are satisfied). Use GNUNET_SCHEDULER_NO_TASK to not have any dependency - * on completion of other tasks. - * @param delay how long should we wait? Use GNUNET_TIME_UNIT_FOREVER_REL for "forever" + * @param delay when should this operation time out? Use + * GNUNET_TIME_UNIT_FOREVER_REL for "on shutdown" * @param wfd write file-descriptor - * @param main main function of the task - * @param cls closure of task + * @param task main function of the task + * @param task_cls closure of task * @return unique task identifier for the job - * only valid until "main" is started! + * only valid until "task" is started! */ GNUNET_SCHEDULER_TaskIdentifier GNUNET_SCHEDULER_add_write_file (struct GNUNET_SCHEDULER_Handle *sched, - int run_on_shutdown, - enum GNUNET_SCHEDULER_Priority prio, - GNUNET_SCHEDULER_TaskIdentifier prerequisite_task, struct GNUNET_TIME_Relative delay, const struct GNUNET_DISK_FileHandle *wfd, - GNUNET_SCHEDULER_Task main, void *cls); + GNUNET_SCHEDULER_Task task, + void *task_cls); /** @@ -472,33 +449,31 @@ GNUNET_SCHEDULER_add_write_file (struct GNUNET_SCHEDULER_Handle *sched, * * * @param sched scheduler to use - * @param run_on_shutdown run on shutdown? Set this - * argument to GNUNET_NO to skip this task if - * the user requested process termination. * @param prio how important is this task? * @param prerequisite_task run this task after the task with the given * task identifier completes (and any of our other * conditions, such as delay, read or write-readyness * are satisfied). Use GNUNET_SCHEDULER_NO_TASK to not have any dependency * on completion of other tasks. - * @param delay how long should we wait? Use GNUNET_TIME_UNIT_FOREVER_REL for "forever" + * @param delay how long should we wait? Use GNUNET_TIME_UNIT_FOREVER_REL for "forever", + * which means that the task will only be run after we receive SIGTERM * @param rs set of file descriptors we want to read (can be NULL) * @param ws set of file descriptors we want to write (can be NULL) - * @param main main function of the task - * @param cls closure of task + * @param task main function of the task + * @param task_cls closure of task * @return unique task identifier for the job - * only valid until "main" is started! + * only valid until "task" is started! */ GNUNET_SCHEDULER_TaskIdentifier GNUNET_SCHEDULER_add_select (struct GNUNET_SCHEDULER_Handle *sched, - int run_on_shutdown, enum GNUNET_SCHEDULER_Priority prio, GNUNET_SCHEDULER_TaskIdentifier prerequisite_task, struct GNUNET_TIME_Relative delay, const struct GNUNET_NETWORK_FDSet * rs, const struct GNUNET_NETWORK_FDSet * ws, - GNUNET_SCHEDULER_Task main, void *cls); + GNUNET_SCHEDULER_Task task, + void *task_cls); #if 0 /* keep Emacsens' auto-indent happy */ { diff --git a/src/include/gnunet_service_lib.h b/src/include/gnunet_service_lib.h index 0c69d297c..82089954e 100644 --- a/src/include/gnunet_service_lib.h +++ b/src/include/gnunet_service_lib.h @@ -54,18 +54,6 @@ typedef void (*GNUNET_SERVICE_Main) (void *cls, cfg); -/** - * Function called when the service shuts - * down to run service-specific teardown code. - * - * @param cls closure - * @param cfg configuration to use - */ -typedef void (*GNUNET_SERVICE_Term) (void *cls, - const struct GNUNET_CONFIGURATION_Handle * - cfg); - - /** * Run a standard GNUnet service startup sequence (initialize loggers * and configuration, parse options). @@ -75,8 +63,6 @@ typedef void (*GNUNET_SERVICE_Term) (void *cls, * @param serviceName our service name * @param task main task of the service * @param task_cls closure for task - * @param term termination task of the service - * @param term_cls closure for term * @return GNUNET_SYSERR on error, GNUNET_OK * if we shutdown nicely */ @@ -84,8 +70,7 @@ int GNUNET_SERVICE_run (int argc, char *const *argv, const char *serviceName, GNUNET_SERVICE_Main task, - void *task_cls, - GNUNET_SERVICE_Term term, void *term_cls); + void *task_cls); struct GNUNET_SERVICE_Context; diff --git a/src/nat/nat.c b/src/nat/nat.c index 2a93d31a7..151c526d4 100644 --- a/src/nat/nat.c +++ b/src/nat/nat.c @@ -285,9 +285,7 @@ nat_pulse (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) notify_change (nat, ext_addr_natpmp, port_mapped); } - nat->pulse_timer = GNUNET_SCHEDULER_add_delayed (nat->sched, GNUNET_NO, - GNUNET_SCHEDULER_PRIORITY_DEFAULT, - GNUNET_SCHEDULER_NO_TASK, + nat->pulse_timer = GNUNET_SCHEDULER_add_delayed (nat->sched, GNUNET_TIME_UNIT_SECONDS, &nat_pulse, nat); } @@ -335,9 +333,7 @@ GNUNET_NAT_register (struct GNUNET_SCHEDULER_Handle *sched, nat->natpmp = GNUNET_NAT_NATPMP_init (nat->local_addr, addrlen, nat->public_port); nat->upnp = GNUNET_NAT_UPNP_init (nat->local_addr, addrlen, nat->public_port); - nat->pulse_timer = GNUNET_SCHEDULER_add_delayed (sched, GNUNET_NO, - GNUNET_SCHEDULER_PRIORITY_DEFAULT, - GNUNET_SCHEDULER_NO_TASK, + nat->pulse_timer = GNUNET_SCHEDULER_add_delayed (sched, GNUNET_TIME_UNIT_SECONDS, &nat_pulse, nat); diff --git a/src/nat/test_nat.c b/src/nat/test_nat.c index 2ff168c56..dc5112c36 100644 --- a/src/nat/test_nat.c +++ b/src/nat/test_nat.c @@ -125,9 +125,7 @@ run (void *cls, nat = GNUNET_NAT_register (sched, addr, data.addrlen, addr_callback, NULL); GNUNET_free (addr); - GNUNET_SCHEDULER_add_delayed (sched, GNUNET_NO, - GNUNET_SCHEDULER_PRIORITY_DEFAULT, - GNUNET_SCHEDULER_NO_TASK, + GNUNET_SCHEDULER_add_delayed (sched, GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, TIMEOUT), stop, nat); } diff --git a/src/peerinfo/gnunet-service-peerinfo.c b/src/peerinfo/gnunet-service-peerinfo.c index 11e311c22..f5a60470e 100644 --- a/src/peerinfo/gnunet-service-peerinfo.c +++ b/src/peerinfo/gnunet-service-peerinfo.c @@ -342,6 +342,8 @@ cron_scan_directory_data_hosts (void *cls, static unsigned int retries; unsigned int count; + if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) + return; count = 0; GNUNET_DISK_directory_create (networkIdDirectory); GNUNET_DISK_directory_scan (networkIdDirectory, @@ -351,9 +353,6 @@ cron_scan_directory_data_hosts (void *cls, GNUNET_ERROR_TYPE_BULK, _("Still no peers found in `%s'!\n"), networkIdDirectory); GNUNET_SCHEDULER_add_delayed (tc->sched, - GNUNET_NO, - GNUNET_SCHEDULER_PRIORITY_KEEP, - GNUNET_SCHEDULER_NO_TASK, DATA_HOST_FREQ, &cron_scan_directory_data_hosts, NULL); } @@ -501,12 +500,10 @@ cron_flush_trust (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) flush_trust (pos); pos = pos->next; } - if (0 == (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) - GNUNET_SCHEDULER_add_delayed (tc->sched, - GNUNET_YES, - GNUNET_SCHEDULER_PRIORITY_KEEP, - GNUNET_SCHEDULER_NO_TASK, - TRUST_FLUSH_FREQ, &cron_flush_trust, NULL); + if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) + return; + GNUNET_SCHEDULER_add_delayed (tc->sched, + TRUST_FLUSH_FREQ, &cron_flush_trust, NULL); } @@ -558,14 +555,13 @@ cron_clean_data_hosts (void *cls, { struct GNUNET_TIME_Absolute now; + if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) + return; now = GNUNET_TIME_absolute_get (); GNUNET_DISK_directory_scan (networkIdDirectory, &discard_hosts_helper, &now); GNUNET_SCHEDULER_add_delayed (tc->sched, - GNUNET_NO, - GNUNET_SCHEDULER_PRIORITY_KEEP, - GNUNET_SCHEDULER_NO_TASK, DATA_HOST_CLEAN_FREQ, &cron_clean_data_hosts, NULL); } @@ -660,6 +656,7 @@ static struct GNUNET_SERVER_MessageHandler handlers[] = { }; + /** * Process statistics requests. * @@ -686,23 +683,15 @@ run (void *cls, &trustDirectory)); GNUNET_DISK_directory_create (networkIdDirectory); GNUNET_DISK_directory_create (trustDirectory); - GNUNET_SCHEDULER_add_delayed (sched, - GNUNET_NO, - GNUNET_SCHEDULER_PRIORITY_IDLE, - GNUNET_SCHEDULER_NO_TASK, - GNUNET_TIME_UNIT_MILLISECONDS, - &cron_scan_directory_data_hosts, NULL); - GNUNET_SCHEDULER_add_delayed (sched, - GNUNET_YES, - GNUNET_SCHEDULER_PRIORITY_HIGH, - GNUNET_SCHEDULER_NO_TASK, - TRUST_FLUSH_FREQ, &cron_flush_trust, NULL); - GNUNET_SCHEDULER_add_delayed (sched, - GNUNET_NO, - GNUNET_SCHEDULER_PRIORITY_IDLE, - GNUNET_SCHEDULER_NO_TASK, - DATA_HOST_CLEAN_FREQ, - &cron_clean_data_hosts, NULL); + GNUNET_SCHEDULER_add_with_priority (sched, + GNUNET_SCHEDULER_PRIORITY_IDLE, + &cron_scan_directory_data_hosts, NULL); + GNUNET_SCHEDULER_add_with_priority (sched, + GNUNET_SCHEDULER_PRIORITY_HIGH, + &cron_flush_trust, NULL); + GNUNET_SCHEDULER_add_with_priority (sched, + GNUNET_SCHEDULER_PRIORITY_IDLE, + &cron_clean_data_hosts, NULL); GNUNET_SERVER_add_handlers (server, handlers); } @@ -722,7 +711,7 @@ main (int argc, char *const *argv) ret = (GNUNET_OK == GNUNET_SERVICE_run (argc, argv, - "peerinfo", &run, NULL, NULL, NULL)) ? 0 : 1; + "peerinfo", &run, NULL)) ? 0 : 1; GNUNET_free_non_null (networkIdDirectory); GNUNET_free_non_null (trustDirectory); return ret; diff --git a/src/peerinfo/test_peerinfo_api.c b/src/peerinfo/test_peerinfo_api.c index 2bae851bc..a375ca40e 100644 --- a/src/peerinfo/test_peerinfo_api.c +++ b/src/peerinfo/test_peerinfo_api.c @@ -149,7 +149,6 @@ check () "-L", "DEBUG", #endif "-c", "test_peerinfo_api_data.conf", NULL); - sleep (1); GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, argv, "test-peerinfo-api", "nohelp", options, &run, &ok); diff --git a/src/statistics/gnunet-service-statistics.c b/src/statistics/gnunet-service-statistics.c index 3221fe2ae..8de9a8047 100644 --- a/src/statistics/gnunet-service-statistics.c +++ b/src/statistics/gnunet-service-statistics.c @@ -82,6 +82,11 @@ struct StatsEntry }; +/** + * Our configuration. + */ +static const struct GNUNET_CONFIGURATION_Handle *cfg; + /** * Linked list of our active statistics. */ @@ -96,10 +101,11 @@ static uint32_t uidgen; * Load persistent values from disk. Disk format is * exactly the same format that we also use for * setting the values over the network. + * + * @param server handle to the server context */ static void -load (struct GNUNET_SERVER_Handle *server, - const struct GNUNET_CONFIGURATION_Handle *cfg) +load (struct GNUNET_SERVER_Handle *server) { char *fn; struct GNUNET_DISK_FileHandle *fh; @@ -153,16 +159,11 @@ load (struct GNUNET_SERVER_Handle *server, GNUNET_free (fn); } - /** * Write persistent statistics to disk. - * - * @param cls closure - * @param cfg configuration to use */ static void -save (void *cls, - const struct GNUNET_CONFIGURATION_Handle *cfg) +save () { struct StatsEntry *pos; char *fn; @@ -434,22 +435,41 @@ static struct GNUNET_SERVER_MessageHandler handlers[] = { }; +/** + * Task run during shutdown. + * + * @param cls unused + * @param tc unused + */ +static void +shutdown_task (void *cls, + const struct GNUNET_SCHEDULER_TaskContext *tc) +{ + save (); +} + + /** * Process statistics requests. * * @param cls closure * @param sched scheduler to use * @param server the initialized server - * @param cfg configuration to use + * @param c configuration to use */ static void run (void *cls, struct GNUNET_SCHEDULER_Handle *sched, struct GNUNET_SERVER_Handle *server, - const struct GNUNET_CONFIGURATION_Handle *cfg) + const struct GNUNET_CONFIGURATION_Handle *c) { + cfg = c; GNUNET_SERVER_add_handlers (server, handlers); - load (server, cfg); + load (server); + GNUNET_SCHEDULER_add_delayed (sched, + GNUNET_TIME_UNIT_FOREVER_REL, + &shutdown_task, + NULL); } @@ -466,7 +486,7 @@ main (int argc, char *const *argv) return (GNUNET_OK == GNUNET_SERVICE_run (argc, argv, - "statistics", &run, NULL, &save, NULL)) ? 0 : 1; + "statistics", &run, NULL)) ? 0 : 1; } /* end of gnunet-service-statistics.c */ diff --git a/src/template/gnunet-service-template.c b/src/template/gnunet-service-template.c index 3ab7d3dcc..15ba94b7d 100644 --- a/src/template/gnunet-service-template.c +++ b/src/template/gnunet-service-template.c @@ -27,19 +27,6 @@ #include "gnunet_getopt_lib.h" #include "gnunet_service_lib.h" -/** - * Do cleanup here. - * - * @param cls closure - * @param cfg configuration to use - */ -static void -finish (void *cls, - const struct GNUNET_CONFIGURATION_Handle *cfg) -{ - /* FIXME */ -} - /** * List of handlers for the messages understood by this @@ -50,6 +37,21 @@ static struct GNUNET_SERVER_MessageHandler handlers[] = { {NULL, NULL, 0, 0} }; + +/** + * Task run during shutdown. + * + * @param cls unused + * @param tc unused + */ +static void +cleanup_task (void *cls, + const struct GNUNET_SCHEDULER_TaskContext *tc) +{ + /* FIXME: do clean up here */ +} + + /** * Process template requests. * @@ -66,6 +68,10 @@ run (void *cls, { /* FIXME: do setup here */ GNUNET_SERVER_add_handlers (server, handlers); + GNUNET_SCHEDULER_add_delayed (sched, + GNUNET_TIME_UNIT_FOREVER_REL, + &cleanup_task, + NULL); } @@ -82,7 +88,7 @@ main (int argc, char *const *argv) return (GNUNET_OK == GNUNET_SERVICE_run (argc, argv, - "template", &run, NULL, &finish, NULL)) ? 0 : 1; + "template", &run, NULL)) ? 0 : 1; } /* end of gnunet-service-template.c */ diff --git a/src/testing/testing.c b/src/testing/testing.c index 2bd14095f..e34e7a9ac 100644 --- a/src/testing/testing.c +++ b/src/testing/testing.c @@ -306,9 +306,6 @@ start_fsm (void *cls, /* wait some more */ d->task = GNUNET_SCHEDULER_add_delayed (d->sched, - GNUNET_NO, - GNUNET_SCHEDULER_PRIORITY_KEEP, - GNUNET_SCHEDULER_NO_TASK, GNUNET_CONSTANTS_EXEC_WAIT, &start_fsm, d); @@ -392,9 +389,6 @@ start_fsm (void *cls, d->wait_runs = 0; d->task = GNUNET_SCHEDULER_add_delayed (d->sched, - GNUNET_NO, - GNUNET_SCHEDULER_PRIORITY_KEEP, - GNUNET_SCHEDULER_NO_TASK, GNUNET_CONSTANTS_EXEC_WAIT, &start_fsm, d); @@ -423,9 +417,6 @@ start_fsm (void *cls, /* wait some more */ d->task = GNUNET_SCHEDULER_add_delayed (d->sched, - GNUNET_NO, - GNUNET_SCHEDULER_PRIORITY_KEEP, - GNUNET_SCHEDULER_NO_TASK, GNUNET_CONSTANTS_EXEC_WAIT, &start_fsm, d); @@ -474,9 +465,6 @@ start_fsm (void *cls, /* wait some more */ d->task = GNUNET_SCHEDULER_add_delayed (d->sched, - GNUNET_NO, - GNUNET_SCHEDULER_PRIORITY_KEEP, - GNUNET_SCHEDULER_NO_TASK, GNUNET_CONSTANTS_EXEC_WAIT, &start_fsm, d); @@ -528,9 +516,6 @@ start_fsm (void *cls, /* wait some more */ d->task = GNUNET_SCHEDULER_add_delayed (d->sched, - GNUNET_NO, - GNUNET_SCHEDULER_PRIORITY_KEEP, - GNUNET_SCHEDULER_NO_TASK, GNUNET_CONSTANTS_EXEC_WAIT, &start_fsm, d); @@ -675,9 +660,6 @@ GNUNET_TESTING_daemon_start (struct GNUNET_SCHEDULER_Handle *sched, } ret->task = GNUNET_SCHEDULER_add_delayed (sched, - GNUNET_YES, - GNUNET_SCHEDULER_PRIORITY_KEEP, - GNUNET_SCHEDULER_NO_TASK, GNUNET_CONSTANTS_EXEC_WAIT, &start_fsm, ret); @@ -689,7 +671,6 @@ GNUNET_TESTING_daemon_start (struct GNUNET_SCHEDULER_Handle *sched, #endif ret->phase = SP_COPIED; GNUNET_SCHEDULER_add_continuation (sched, - GNUNET_NO, &start_fsm, ret, GNUNET_SCHEDULER_REASON_PREREQ_DONE); @@ -781,9 +762,6 @@ void GNUNET_TESTING_daemon_stop (struct GNUNET_TESTING_Daemon *d, d->dead_cb_cls = cb_cls; d->task = GNUNET_SCHEDULER_add_delayed (d->sched, - GNUNET_YES, - GNUNET_SCHEDULER_PRIORITY_KEEP, - GNUNET_SCHEDULER_NO_TASK, GNUNET_CONSTANTS_EXEC_WAIT, &start_fsm, d); @@ -879,9 +857,6 @@ void GNUNET_TESTING_daemon_reconfigure (struct GNUNET_TESTING_Daemon *d, d->update_cb_cls = cb_cls; d->task = GNUNET_SCHEDULER_add_delayed (d->sched, - GNUNET_NO, - GNUNET_SCHEDULER_PRIORITY_KEEP, - GNUNET_SCHEDULER_NO_TASK, GNUNET_CONSTANTS_EXEC_WAIT, &start_fsm, d); @@ -986,7 +961,6 @@ transmit_ready (void *cls, size_t size, void *buf) GNUNET_TRANSPORT_disconnect (ctx->d2th); ctx->d2th = NULL; GNUNET_SCHEDULER_add_continuation (ctx->d1->sched, - GNUNET_NO, ¬ify_connect_result, ctx, (buf == NULL) ? diff --git a/src/topology/gnunet-daemon-topology.c b/src/topology/gnunet-daemon-topology.c index b156ddfaf..cdf3da809 100644 --- a/src/topology/gnunet-daemon-topology.c +++ b/src/topology/gnunet-daemon-topology.c @@ -523,9 +523,6 @@ schedule_peer_search () (unsigned long long) delay.value); #endif GNUNET_SCHEDULER_add_delayed (sched, - GNUNET_NO, - GNUNET_SCHEDULER_PRIORITY_DEFAULT, - GNUNET_SCHEDULER_NO_TASK, delay, &find_more_peers, NULL); @@ -823,9 +820,6 @@ core_init (void *cls, #endif if (autoconnect) GNUNET_SCHEDULER_add_delayed (sched, - GNUNET_NO, - GNUNET_SCHEDULER_PRIORITY_DEFAULT, - GNUNET_SCHEDULER_NO_TASK, GNUNET_TIME_UNIT_SECONDS /* give core time to tell us about existing connections */, &find_more_peers, NULL); @@ -1227,9 +1221,6 @@ run (void *cls, handlers); GNUNET_SCHEDULER_add_delayed (sched, - GNUNET_YES, - GNUNET_SCHEDULER_PRIORITY_IDLE, - GNUNET_SCHEDULER_NO_TASK, GNUNET_TIME_UNIT_FOREVER_REL, &cleaning_task, NULL); } diff --git a/src/topology/test_gnunet_service_topology.c b/src/topology/test_gnunet_service_topology.c index b2790c0c9..2536f5454 100644 --- a/src/topology/test_gnunet_service_topology.c +++ b/src/topology/test_gnunet_service_topology.c @@ -26,7 +26,7 @@ #define VERBOSE GNUNET_YES -#define NUM_PEERS 10 +#define NUM_PEERS 4 /** * How long until we give up on connecting the peers? diff --git a/src/transport/gnunet-service-transport.c b/src/transport/gnunet-service-transport.c index 0dc3f859d..efe53e021 100644 --- a/src/transport/gnunet-service-transport.c +++ b/src/transport/gnunet-service-transport.c @@ -710,9 +710,9 @@ transmit_to_client_callback (void *cls, size_t size, void *buf) GNUNET_free (q); client->message_count--; } - GNUNET_assert (tsize > 0); if (NULL != q) { + GNUNET_assert (msize >= sizeof (struct GNUNET_MessageHeader)); th = GNUNET_SERVER_notify_transmit_ready (client->client, msize, GNUNET_TIME_UNIT_FOREVER_REL, @@ -753,6 +753,7 @@ transmit_to_client (struct TransportClient *client, } client->message_count++; msize = ntohs (msg->size); + GNUNET_assert (msize >= sizeof (struct GNUNET_MessageHeader)); q = GNUNET_malloc (sizeof (struct ClientMessageQueueEntry) + msize); memcpy (&q[1], msg, msize); /* append to message queue */ @@ -1217,9 +1218,6 @@ update_addresses (struct TransportPlugin *plugin, int fresh) if (min_remaining.value < GNUNET_TIME_UNIT_FOREVER_REL.value) plugin->address_update_task = GNUNET_SCHEDULER_add_delayed (plugin->env.sched, - GNUNET_NO, - GNUNET_SCHEDULER_PRIORITY_IDLE, - GNUNET_SCHEDULER_NO_TASK, min_remaining, &expire_address_task, plugin); @@ -1527,9 +1525,6 @@ cleanup_validation (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) pos = pos->next; } GNUNET_SCHEDULER_add_delayed (sched, - GNUNET_NO, - GNUNET_SCHEDULER_PRIORITY_IDLE, - GNUNET_SCHEDULER_NO_TASK, GNUNET_TIME_absolute_get_remaining (first), &cleanup_validation, NULL); } @@ -1631,12 +1626,9 @@ plugin_env_notify_validation (void *cls, GNUNET_i2s (peer)); #endif pos->timeout.value = 0; - GNUNET_SCHEDULER_add_delayed (sched, - GNUNET_NO, - GNUNET_SCHEDULER_PRIORITY_IDLE, - GNUNET_SCHEDULER_NO_TASK, - GNUNET_TIME_UNIT_ZERO, - &cleanup_validation, NULL); + GNUNET_SCHEDULER_add_with_priority (sched, + GNUNET_SCHEDULER_PRIORITY_IDLE, + &cleanup_validation, NULL); } else { @@ -1798,9 +1790,6 @@ check_hello_validated (void *cls, va = va->next; } GNUNET_SCHEDULER_add_delayed (sched, - GNUNET_NO, - GNUNET_SCHEDULER_PRIORITY_IDLE, - GNUNET_SCHEDULER_NO_TASK, GNUNET_TIME_absolute_get_remaining (chvc->e->timeout), &cleanup_validation, NULL); GNUNET_free (chvc); @@ -2047,9 +2036,6 @@ setup_new_neighbour (const struct GNUNET_PeerIdentity *peer) n->quota_in = (GNUNET_CONSTANTS_DEFAULT_BPM_IN_OUT + 59999) / (60 * 1000); add_plugins (n); n->timeout_task = GNUNET_SCHEDULER_add_delayed (sched, - GNUNET_NO, - GNUNET_SCHEDULER_PRIORITY_IDLE, - GNUNET_SCHEDULER_NO_TASK, GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, &neighbour_timeout_task, n); transmit_to_peer (NULL, 0, @@ -2161,9 +2147,7 @@ plugin_env_receive (void *cls, n->peer_timeout = GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); n->timeout_task = - GNUNET_SCHEDULER_add_delayed (sched, GNUNET_NO, - GNUNET_SCHEDULER_PRIORITY_IDLE, - GNUNET_SCHEDULER_NO_TASK, + GNUNET_SCHEDULER_add_delayed (sched, GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, &neighbour_timeout_task, n); update_quota (n); @@ -2698,9 +2682,6 @@ run (void *cls, GNUNET_free (plugs); } GNUNET_SCHEDULER_add_delayed (sched, - GNUNET_YES, - GNUNET_SCHEDULER_PRIORITY_IDLE, - GNUNET_SCHEDULER_NO_TASK, GNUNET_TIME_UNIT_FOREVER_REL, &unload_plugins, NULL); if (no_transports) @@ -2728,7 +2709,7 @@ main (int argc, char *const *argv) GNUNET_SERVICE_run (argc, argv, "transport", - &run, NULL, NULL, NULL)) ? 0 : 1; + &run, NULL)) ? 0 : 1; } /* end of gnunet-service-transport.c */ diff --git a/src/transport/plugin_transport_tcp.c b/src/transport/plugin_transport_tcp.c index eeb333a53..a391b1b42 100644 --- a/src/transport/plugin_transport_tcp.c +++ b/src/transport/plugin_transport_tcp.c @@ -1898,9 +1898,6 @@ handle_tcp_data (void *cls, GNUNET_SERVER_receive_done (client, GNUNET_OK); else GNUNET_SCHEDULER_add_delayed (session->plugin->env->sched, - GNUNET_NO, - GNUNET_SCHEDULER_PRIORITY_HIGH, - GNUNET_SCHEDULER_NO_TASK, delay, &delayed_done, session); } diff --git a/src/transport/test_plugin_transport.c b/src/transport/test_plugin_transport.c index ec1b6b76c..856cadeaf 100644 --- a/src/transport/test_plugin_transport.c +++ b/src/transport/test_plugin_transport.c @@ -179,7 +179,6 @@ validation_notification (void *cls, here will end the process. */ ok = 0; /* if the last test succeeded, report success */ GNUNET_SCHEDULER_add_continuation (sched, - GNUNET_NO, &unload_task, (void*) cfg, GNUNET_SCHEDULER_REASON_PREREQ_DONE); @@ -236,9 +235,6 @@ test_validation () /* add job to catch failure (timeout) */ validation_timeout_task = GNUNET_SCHEDULER_add_delayed (sched, - GNUNET_NO, - GNUNET_SCHEDULER_PRIORITY_KEEP, - GNUNET_SCHEDULER_NO_TASK, TIMEOUT, &validation_failed, NULL); diff --git a/src/transport/transport_api.c b/src/transport/transport_api.c index 122950a74..c98194da0 100644 --- a/src/transport/transport_api.c +++ b/src/transport/transport_api.c @@ -625,9 +625,6 @@ schedule_control_transmit (struct GNUNET_TRANSPORT_Handle *h, th->notify_size = size; th->notify_delay_task = GNUNET_SCHEDULER_add_delayed (h->sched, - GNUNET_NO, - GNUNET_SCHEDULER_PRIORITY_KEEP, - GNUNET_SCHEDULER_NO_TASK, timeout, &peer_transmit_timeout, th); if (at_head) @@ -704,7 +701,6 @@ send_set_quota (void *cls, size_t size, void *buf) if (buf == NULL) { GNUNET_SCHEDULER_add_continuation (sqc->handle->sched, - GNUNET_NO, sqc->cont, sqc->cont_cls, GNUNET_SCHEDULER_REASON_TIMEOUT); @@ -724,7 +720,6 @@ send_set_quota (void *cls, size_t size, void *buf) memcpy (&msg->peer, &sqc->target, sizeof (struct GNUNET_PeerIdentity)); if (sqc->cont != NULL) GNUNET_SCHEDULER_add_continuation (sqc->handle->sched, - GNUNET_NO, sqc->cont, sqc->cont_cls, GNUNET_SCHEDULER_REASON_PREREQ_DONE); @@ -802,9 +797,6 @@ hello_wait_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) GNUNET_TIME_absolute_get_remaining (hwl->timeout).value); #endif hwl->task = GNUNET_SCHEDULER_add_delayed (hwl->handle->sched, - GNUNET_YES, - GNUNET_SCHEDULER_PRIORITY_KEEP, - GNUNET_SCHEDULER_NO_TASK, GNUNET_TIME_absolute_get_remaining (hwl->timeout), &hello_wait_timeout, hwl); return; @@ -862,9 +854,6 @@ GNUNET_TRANSPORT_get_hello (struct GNUNET_TRANSPORT_Handle *handle, hwl->rec_cls = rec_cls; hwl->timeout = GNUNET_TIME_relative_to_absolute (timeout); hwl->task = GNUNET_SCHEDULER_add_delayed (handle->sched, - GNUNET_YES, - GNUNET_SCHEDULER_PRIORITY_KEEP, - GNUNET_SCHEDULER_NO_TASK, timeout, &hello_wait_timeout, hwl); return; @@ -1018,9 +1007,6 @@ request_connect (void *cls, size_t size, void *buf) memcpy (&tcm->peer, &th->target, sizeof (struct GNUNET_PeerIdentity)); th->notify_delay_task = GNUNET_SCHEDULER_add_delayed (h->sched, - GNUNET_NO, - GNUNET_SCHEDULER_PRIORITY_KEEP, - GNUNET_SCHEDULER_NO_TASK, GNUNET_TIME_absolute_get_remaining (th->timeout), &peer_transmit_timeout, th); @@ -1128,9 +1114,6 @@ remove_neighbour (struct GNUNET_TRANSPORT_Handle *h, GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == th->notify_delay_task); th->notify_delay_task = GNUNET_SCHEDULER_add_delayed (h->sched, - GNUNET_NO, - GNUNET_SCHEDULER_PRIORITY_KEEP, - GNUNET_SCHEDULER_NO_TASK, CONNECT_RETRY_TIMEOUT, &try_connect_task, th); @@ -1214,9 +1197,6 @@ schedule_reconnect (struct GNUNET_TRANSPORT_Handle *h) GNUNET_assert (h->reconnect_task == GNUNET_SCHEDULER_NO_TASK); h->reconnect_task = GNUNET_SCHEDULER_add_delayed (h->sched, - GNUNET_NO, - GNUNET_SCHEDULER_PRIORITY_DEFAULT, - GNUNET_SCHEDULER_NO_TASK, h->reconnect_delay, &reconnect, h); h->reconnect_delay = GNUNET_TIME_UNIT_SECONDS; } @@ -1318,9 +1298,6 @@ schedule_request (struct GNUNET_TRANSPORT_TransmitHandle *th) #endif th->notify_delay_task = GNUNET_SCHEDULER_add_delayed (h->sched, - GNUNET_NO, - GNUNET_SCHEDULER_PRIORITY_KEEP, - GNUNET_SCHEDULER_NO_TASK, duration, &transmit_ready, th); return; } @@ -1340,9 +1317,6 @@ schedule_request (struct GNUNET_TRANSPORT_TransmitHandle *th) #endif th->notify_delay_task = GNUNET_SCHEDULER_add_delayed (h->sched, - GNUNET_NO, - GNUNET_SCHEDULER_PRIORITY_KEEP, - GNUNET_SCHEDULER_NO_TASK, GNUNET_TIME_absolute_get_remaining (th->timeout), &peer_transmit_timeout, th); return; @@ -1593,9 +1567,6 @@ demultiplexer (void *cls, const struct GNUNET_MessageHeader *msg) GNUNET_assert (th->notify_delay_task == GNUNET_SCHEDULER_NO_TASK); th->notify_delay_task = GNUNET_SCHEDULER_add_delayed (h->sched, - GNUNET_NO, - GNUNET_SCHEDULER_PRIORITY_KEEP, - GNUNET_SCHEDULER_NO_TASK, GNUNET_TIME_absolute_get_remaining(th->timeout), &peer_transmit_timeout, th); @@ -1937,9 +1908,6 @@ GNUNET_TRANSPORT_notify_transmit_ready (struct GNUNET_TRANSPORT_Handle #endif th->notify_delay_task = GNUNET_SCHEDULER_add_delayed (handle->sched, - GNUNET_NO, - GNUNET_SCHEDULER_PRIORITY_KEEP, - GNUNET_SCHEDULER_NO_TASK, timeout, &peer_transmit_timeout, th); return th; } diff --git a/src/util/client.c b/src/util/client.c index 60aa6f101..05f579b9f 100644 --- a/src/util/client.c +++ b/src/util/client.c @@ -308,8 +308,6 @@ GNUNET_CLIENT_disconnect (struct GNUNET_CLIENT_Connection *sock) sock->in_receive = GNUNET_SYSERR; else GNUNET_SCHEDULER_add_after (sock->sched, - GNUNET_YES, - GNUNET_SCHEDULER_PRIORITY_KEEP, GNUNET_SCHEDULER_NO_TASK, &finish_cleanup, sock); } @@ -353,8 +351,6 @@ receive_helper (void *cls, GNUNET_assert (conn->msg_complete == GNUNET_NO); if (GNUNET_SYSERR == conn->in_receive) GNUNET_SCHEDULER_add_after (conn->sched, - GNUNET_YES, - GNUNET_SCHEDULER_PRIORITY_KEEP, GNUNET_SCHEDULER_NO_TASK, &finish_cleanup, conn); conn->in_receive = GNUNET_NO; @@ -412,8 +408,6 @@ receive_task (void *scls, const struct GNUNET_SCHEDULER_TaskContext *tc) if (GNUNET_SYSERR == sock->in_receive) GNUNET_SCHEDULER_add_after (sock->sched, - GNUNET_YES, - GNUNET_SCHEDULER_PRIORITY_KEEP, GNUNET_SCHEDULER_NO_TASK, &finish_cleanup, sock); sock->in_receive = GNUNET_NO; @@ -457,8 +451,6 @@ GNUNET_CLIENT_receive (struct GNUNET_CLIENT_Connection *sock, sock->in_receive = GNUNET_YES; if (GNUNET_YES == sock->msg_complete) GNUNET_SCHEDULER_add_after (sock->sched, - GNUNET_YES, - GNUNET_SCHEDULER_PRIORITY_KEEP, GNUNET_SCHEDULER_NO_TASK, &receive_task, sock); else @@ -522,7 +514,6 @@ service_test_error (struct GNUNET_SCHEDULER_Handle *s, GNUNET_SCHEDULER_Task task, void *task_cls) { GNUNET_SCHEDULER_add_continuation (s, - GNUNET_YES, task, task_cls, GNUNET_SCHEDULER_REASON_TIMEOUT); @@ -549,7 +540,6 @@ confirm_handler (void *cls, const struct GNUNET_MessageHeader *msg) "Received confirmation that service is running.\n"); #endif GNUNET_SCHEDULER_add_continuation (conn->sched, - GNUNET_YES, conn->test_cb, conn->test_cb_cls, GNUNET_SCHEDULER_REASON_PREREQ_DONE); @@ -719,9 +709,6 @@ client_notify (void *cls, size_t size, void *buf) GNUNET_assert (NULL != th->sock->sock); delay = GNUNET_TIME_relative_min (delay, GNUNET_TIME_UNIT_SECONDS); th->task = GNUNET_SCHEDULER_add_delayed (th->sock->sched, - GNUNET_NO, - GNUNET_SCHEDULER_PRIORITY_KEEP, - GNUNET_SCHEDULER_NO_TASK, delay, &client_delayed_retry, th); th->sock->th = th; diff --git a/src/util/connection.c b/src/util/connection.c index 066b81bbe..9bf2aa975 100644 --- a/src/util/connection.c +++ b/src/util/connection.c @@ -476,8 +476,6 @@ destroy_continuation (void *cls, "Destroy waits for write_task to be done (%p)\n", sock); #endif GNUNET_SCHEDULER_add_after (sock->sched, - GNUNET_YES, - GNUNET_SCHEDULER_PRIORITY_KEEP, sock->write_task, &destroy_continuation, sock); return; @@ -498,8 +496,6 @@ destroy_continuation (void *cls, if (sock->read_task != GNUNET_SCHEDULER_NO_TASK) { GNUNET_SCHEDULER_add_after (sock->sched, - GNUNET_YES, - GNUNET_SCHEDULER_PRIORITY_KEEP, sock->read_task, &destroy_continuation, sock); return; @@ -569,8 +565,6 @@ connect_fail_continuation (struct GNUNET_CONNECTION_Handle *h) #endif h->ccs -= COCO_RECEIVE_AGAIN; h->read_task = GNUNET_SCHEDULER_add_after (h->sched, - GNUNET_NO, - GNUNET_SCHEDULER_PRIORITY_KEEP, GNUNET_SCHEDULER_NO_TASK, &receive_again, h); } @@ -586,8 +580,6 @@ connect_fail_continuation (struct GNUNET_CONNECTION_Handle *h) h->nth.timeout_task = GNUNET_SCHEDULER_NO_TASK; h->ccs -= COCO_TRANSMIT_READY; h->write_task = GNUNET_SCHEDULER_add_after (h->sched, - GNUNET_NO, - GNUNET_SCHEDULER_PRIORITY_KEEP, GNUNET_SCHEDULER_NO_TASK, &transmit_ready, h); } @@ -600,7 +592,6 @@ connect_fail_continuation (struct GNUNET_CONNECTION_Handle *h) #endif h->ccs -= COCO_DESTROY_CONTINUATION; GNUNET_SCHEDULER_add_continuation (h->sched, - GNUNET_NO, &destroy_continuation, h, GNUNET_SCHEDULER_REASON_TIMEOUT); } @@ -630,8 +621,6 @@ connect_success_continuation (struct GNUNET_CONNECTION_Handle *h) #endif h->ccs -= COCO_RECEIVE_AGAIN; h->read_task = GNUNET_SCHEDULER_add_after (h->sched, - GNUNET_NO, - GNUNET_SCHEDULER_PRIORITY_KEEP, GNUNET_SCHEDULER_NO_TASK, &receive_again, h); } @@ -648,9 +637,6 @@ connect_success_continuation (struct GNUNET_CONNECTION_Handle *h) h->ccs -= COCO_TRANSMIT_READY; h->write_task = GNUNET_SCHEDULER_add_write_net (h->sched, - GNUNET_NO, - GNUNET_SCHEDULER_PRIORITY_KEEP, - GNUNET_SCHEDULER_NO_TASK, GNUNET_TIME_absolute_get_remaining (h->nth.transmit_timeout), h->sock, &transmit_ready, h); @@ -664,7 +650,6 @@ connect_success_continuation (struct GNUNET_CONNECTION_Handle *h) #endif h->ccs -= COCO_DESTROY_CONTINUATION; GNUNET_SCHEDULER_add_continuation (h->sched, - GNUNET_NO, &destroy_continuation, h, GNUNET_SCHEDULER_REASON_PREREQ_DONE); @@ -808,9 +793,8 @@ try_connect_using_address (void *cls, GNUNET_TIME_absolute_get_remaining (h-> receive_timeout)); ap->task = - GNUNET_SCHEDULER_add_write_net (h->sched, GNUNET_NO, - GNUNET_SCHEDULER_PRIORITY_KEEP, - GNUNET_SCHEDULER_NO_TASK, delay, ap->sock, + GNUNET_SCHEDULER_add_write_net (h->sched, + delay, ap->sock, &connect_probe_continuation, ap); } @@ -956,8 +940,6 @@ GNUNET_CONNECTION_destroy (struct GNUNET_CONNECTION_Handle *sock) } GNUNET_assert (sock->sched != NULL); GNUNET_SCHEDULER_add_after (sock->sched, - GNUNET_YES, - GNUNET_SCHEDULER_PRIORITY_KEEP, GNUNET_SCHEDULER_NO_TASK, &destroy_continuation, sock); } @@ -1101,9 +1083,6 @@ receive_again (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) GNUNET_assert (sh->sock != NULL); /* connect succeeded, wait for data! */ sh->read_task = GNUNET_SCHEDULER_add_read_net (tc->sched, - GNUNET_YES, - GNUNET_SCHEDULER_PRIORITY_KEEP, - GNUNET_SCHEDULER_NO_TASK, GNUNET_TIME_absolute_get_remaining (sh->receive_timeout), sh->sock, @@ -1406,9 +1385,6 @@ SCHEDULE_WRITE: if (sock->write_task == GNUNET_SCHEDULER_NO_TASK) sock->write_task = GNUNET_SCHEDULER_add_write_net (tc->sched, - GNUNET_NO, - GNUNET_SCHEDULER_PRIORITY_KEEP, - GNUNET_SCHEDULER_NO_TASK, GNUNET_TIME_absolute_get_remaining (sock->nth.transmit_timeout), sock->sock, &transmit_ready, sock); @@ -1453,9 +1429,6 @@ GNUNET_CONNECTION_notify_transmit_ready (struct GNUNET_CONNECTION_Handle (sock->ap_head == NULL) && (sock->dns_active == NULL)) { sock->write_task = GNUNET_SCHEDULER_add_delayed (sock->sched, - GNUNET_NO, - GNUNET_SCHEDULER_PRIORITY_KEEP, - GNUNET_SCHEDULER_NO_TASK, GNUNET_TIME_UNIT_ZERO, &connect_error, sock); return &sock->nth; @@ -1469,9 +1442,6 @@ GNUNET_CONNECTION_notify_transmit_ready (struct GNUNET_CONNECTION_Handle "Scheduling transmit_ready (%p).\n", sock); #endif sock->write_task = GNUNET_SCHEDULER_add_write_net (sock->sched, - GNUNET_NO, - GNUNET_SCHEDULER_PRIORITY_KEEP, - GNUNET_SCHEDULER_NO_TASK, GNUNET_TIME_absolute_get_remaining (sock->nth. transmit_timeout), @@ -1488,9 +1458,6 @@ GNUNET_CONNECTION_notify_transmit_ready (struct GNUNET_CONNECTION_Handle #endif sock->ccs |= COCO_TRANSMIT_READY; sock->nth.timeout_task = GNUNET_SCHEDULER_add_delayed (sock->sched, - GNUNET_NO, - GNUNET_SCHEDULER_PRIORITY_KEEP, - GNUNET_SCHEDULER_NO_TASK, timeout, &transmit_timeout, sock); diff --git a/src/util/crypto_hash.c b/src/util/crypto_hash.c index 3f5869489..dcee545f7 100644 --- a/src/util/crypto_hash.c +++ b/src/util/crypto_hash.c @@ -415,11 +415,6 @@ struct FileHashContext */ uint64_t offset; - /** - * Run on shutdown? - */ - int run_on_shutdown; - /** * File descriptor. */ @@ -476,8 +471,6 @@ file_hash_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) return; } GNUNET_SCHEDULER_add_after (tc->sched, - fhc->run_on_shutdown, - GNUNET_SCHEDULER_PRIORITY_KEEP, GNUNET_SCHEDULER_NO_TASK, &file_hash_task, fhc); } @@ -487,7 +480,6 @@ file_hash_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) * * @param sched scheduler to use * @param priority scheduling priority to use - * @param run_on_shutdown should we complete even on shutdown? * @param filename name of file to hash * @param blocksize number of bytes to process in one task * @param callback function to call upon completion @@ -496,7 +488,6 @@ file_hash_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) void GNUNET_CRYPTO_hash_file (struct GNUNET_SCHEDULER_Handle *sched, enum GNUNET_SCHEDULER_Priority priority, - int run_on_shutdown, const char *filename, size_t blocksize, GNUNET_CRYPTO_HashCompletedCallback callback, @@ -518,7 +509,6 @@ GNUNET_CRYPTO_hash_file (struct GNUNET_SCHEDULER_Handle *sched, file_hash_finish (fhc, NULL); return; } - fhc->run_on_shutdown = run_on_shutdown; fhc->fh = GNUNET_DISK_file_open (filename, GNUNET_DISK_OPEN_READ, GNUNET_DISK_PERM_NONE); @@ -527,10 +517,7 @@ GNUNET_CRYPTO_hash_file (struct GNUNET_SCHEDULER_Handle *sched, file_hash_finish (fhc, NULL); return; } - GNUNET_SCHEDULER_add_after (sched, - run_on_shutdown, - priority, - GNUNET_SCHEDULER_NO_TASK, &file_hash_task, fhc); + GNUNET_SCHEDULER_add_with_priority (sched, priority, &file_hash_task, fhc); } diff --git a/src/util/disk.c b/src/util/disk.c index 9f93a1ee2..3b3cb9e65 100644 --- a/src/util/disk.c +++ b/src/util/disk.c @@ -856,11 +856,9 @@ GNUNET_DISK_directory_iterator_next (struct GNUNET_DISK_DirectoryIterator GNUNET_DISK_directory_iterator_next (iter, GNUNET_YES); return GNUNET_NO; } - GNUNET_SCHEDULER_add_after (iter->sched, - GNUNET_YES, - iter->priority, - GNUNET_SCHEDULER_NO_TASK, - &directory_iterator_task, iter); + GNUNET_SCHEDULER_add_with_priority (iter->sched, + iter->priority, + &directory_iterator_task, iter); return GNUNET_YES; } diff --git a/src/util/gnunet-service-resolver.c b/src/util/gnunet-service-resolver.c index f8dd2e166..4dcabface 100644 --- a/src/util/gnunet-service-resolver.c +++ b/src/util/gnunet-service-resolver.c @@ -516,7 +516,7 @@ main (int argc, char *const *argv) ret = (GNUNET_OK == GNUNET_SERVICE_run (argc, argv, - "resolver", &run, NULL, NULL, NULL)) ? 0 : 1; + "resolver", &run, NULL)) ? 0 : 1; while (head != NULL) { diff --git a/src/util/resolver_api.c b/src/util/resolver_api.c index 69d143bc1..812cdc84e 100644 --- a/src/util/resolver_api.c +++ b/src/util/resolver_api.c @@ -442,9 +442,6 @@ GNUNET_RESOLVER_ip_get (struct GNUNET_SCHEDULER_Handle *sched, ((domain == AF_INET6) || (domain == AF_UNSPEC)))) { rh->task = GNUNET_SCHEDULER_add_delayed (sched, - GNUNET_NO, - GNUNET_SCHEDULER_PRIORITY_KEEP, - GNUNET_SCHEDULER_NO_TASK, GNUNET_TIME_UNIT_ZERO, &numeric_resolution, rh); return rh; @@ -455,9 +452,6 @@ GNUNET_RESOLVER_ip_get (struct GNUNET_SCHEDULER_Handle *sched, if (0 == strcasecmp (loopback[i++], hostname)) { rh->task = GNUNET_SCHEDULER_add_delayed (sched, - GNUNET_NO, - GNUNET_SCHEDULER_PRIORITY_KEEP, - GNUNET_SCHEDULER_NO_TASK, GNUNET_TIME_UNIT_ZERO, &loopback_resolution, rh); return rh; @@ -623,9 +617,6 @@ GNUNET_RESOLVER_hostname_get (struct GNUNET_SCHEDULER_Handle *sched, if (GNUNET_NO == do_resolve) { rh->task = GNUNET_SCHEDULER_add_delayed (sched, - GNUNET_NO, - GNUNET_SCHEDULER_PRIORITY_KEEP, - GNUNET_SCHEDULER_NO_TASK, GNUNET_TIME_UNIT_ZERO, &numeric_reverse, rh); return rh; diff --git a/src/util/scheduler.c b/src/util/scheduler.c index 2bb356eb6..16f65b457 100644 --- a/src/util/scheduler.c +++ b/src/util/scheduler.c @@ -95,11 +95,6 @@ struct Task */ enum GNUNET_SCHEDULER_Priority priority; - /** - * Should this task be run on shutdown? - */ - int run_on_shutdown; - }; @@ -134,12 +129,6 @@ struct GNUNET_SCHEDULER_Handle */ GNUNET_SCHEDULER_TaskIdentifier lowest_pending_id; - /** - * GNUNET_NO if we are running normally, - * GNUNET_YES if we are in shutdown mode. - */ - int shutdown; - /** * Number of tasks on the ready list. */ @@ -260,6 +249,8 @@ update_sets (struct GNUNET_SCHEDULER_Handle *sched, GNUNET_NETWORK_fdset_add (rs, pos->read_set); if (pos->write_set != NULL) GNUNET_NETWORK_fdset_add (ws, pos->write_set); + if (pos->reason != 0) + *timeout = GNUNET_TIME_UNIT_ZERO; pos = pos->next; } } @@ -309,12 +300,7 @@ is_ready (struct GNUNET_SCHEDULER_Handle *sched, const struct GNUNET_NETWORK_FDSet *rs, const struct GNUNET_NETWORK_FDSet *ws) { - if ((GNUNET_NO == task->run_on_shutdown) && (GNUNET_YES == sched->shutdown)) - return GNUNET_NO; - if ((GNUNET_YES == task->run_on_shutdown) && - (GNUNET_YES == sched->shutdown)) - task->reason |= GNUNET_SCHEDULER_REASON_SHUTDOWN; - if (now.value >= task->timeout.value) + if (now.value >= task->timeout.value) task->reason |= GNUNET_SCHEDULER_REASON_TIMEOUT; if ((0 == (task->reason & GNUNET_SCHEDULER_REASON_READ_READY)) && (rs != NULL) && (set_overlaps (rs, task->read_set))) @@ -394,6 +380,32 @@ check_ready (struct GNUNET_SCHEDULER_Handle *handle, } +/** + * Request the shutdown of a scheduler. Marks all currently + * pending tasks as ready because of shutdown. This will + * cause all tasks to run (as soon as possible, respecting + * priorities and prerequisite tasks). Note that tasks + * scheduled AFTER this call may still be delayed arbitrarily. + * + * @param sched the scheduler + */ +void +GNUNET_SCHEDULER_shutdown (struct GNUNET_SCHEDULER_Handle *sched) +{ + struct Task *pos; + + pos = sched->pending; + while (pos != NULL) + { + pos->reason |= GNUNET_SCHEDULER_REASON_SHUTDOWN; + /* we don't move the task into the ready queue yet; check_ready + will do that later, possibly adding additional + readyness-factors */ + pos = pos->next; + } +} + + /** * Destroy a task (release associated resources) * @@ -415,7 +427,7 @@ destroy_task (struct Task *t) * empty. Keep running tasks until we are either no longer running * "URGENT" tasks or until we have at least one "pending" task (which * may become ready, hence we should select on it). Naturally, if - * there are no more ready tasks, we also return. + * there are no more ready tasks, we also return. * * @param sched the scheduler */ @@ -459,7 +471,7 @@ run_ready (struct GNUNET_SCHEDULER_Handle *sched) while ((sched->pending == NULL) || (p == GNUNET_SCHEDULER_PRIORITY_URGENT)); } - +#ifndef MINGW /** * Pipe used to communicate shutdown via signal. */ @@ -478,19 +490,25 @@ sighandler_shutdown () (sigpipe, GNUNET_DISK_PIPE_END_WRITE), &c, sizeof (c)); } +#endif /** - * Initialize a scheduler using this thread. This function will - * return when either a shutdown was initiated (via signal) and all - * tasks marked to "run_on_shutdown" have been completed or when all - * tasks in general have been completed. + * Initialize and run scheduler. This function will return when all + * tasks have completed. On systems with signals, receiving a SIGTERM + * (and other similar signals) will cause "GNUNET_SCHEDULER_shutdown" + * to be run after the active task is complete. As a result, SIGTERM + * causes all active tasks to be scheduled with reason + * "GNUNET_SCHEDULER_REASON_SHUTDOWN". (However, tasks added + * afterwards will execute normally!). Note that any particular signal + * will only shut down one scheduler; applications should always only + * create a single scheduler. * * @param task task to run immediately - * @param cls closure of task + * @param task_cls closure of task */ void -GNUNET_SCHEDULER_run (GNUNET_SCHEDULER_Task task, void *cls) +GNUNET_SCHEDULER_run (GNUNET_SCHEDULER_Task task, void *task_cls) { struct GNUNET_SCHEDULER_Handle sched; struct GNUNET_NETWORK_FDSet *rs; @@ -501,12 +519,12 @@ GNUNET_SCHEDULER_run (GNUNET_SCHEDULER_Task task, void *cls) struct GNUNET_SIGNAL_Context *shc_term; struct GNUNET_SIGNAL_Context *shc_quit; struct GNUNET_SIGNAL_Context *shc_hup; - struct Task *tpos; unsigned long long last_tr; unsigned int busy_wait_warning; #ifndef MINGW const struct GNUNET_DISK_FileHandle *pr; #endif + char c; rs = GNUNET_NETWORK_fdset_create (); ws = GNUNET_NETWORK_fdset_create (); @@ -516,38 +534,40 @@ GNUNET_SCHEDULER_run (GNUNET_SCHEDULER_Task task, void *cls) GNUNET_assert (sigpipe != NULL); pr = GNUNET_DISK_pipe_handle (sigpipe, GNUNET_DISK_PIPE_END_READ); GNUNET_assert (pr != NULL); - shc_int = GNUNET_SIGNAL_handler_install (SIGINT, &sighandler_shutdown); + shc_int = GNUNET_SIGNAL_handler_install (SIGINT, &sighandler_shutdown); shc_term = GNUNET_SIGNAL_handler_install (SIGTERM, &sighandler_shutdown); shc_quit = GNUNET_SIGNAL_handler_install (SIGQUIT, &sighandler_shutdown); - shc_hup = GNUNET_SIGNAL_handler_install (SIGHUP, &sighandler_shutdown); + shc_hup = GNUNET_SIGNAL_handler_install (SIGHUP, &sighandler_shutdown); #endif memset (&sched, 0, sizeof (sched)); sched.current_priority = GNUNET_SCHEDULER_PRIORITY_DEFAULT; GNUNET_SCHEDULER_add_continuation (&sched, - GNUNET_YES, task, - cls, GNUNET_SCHEDULER_REASON_STARTUP); + task_cls, + GNUNET_SCHEDULER_REASON_STARTUP); last_tr = 0; busy_wait_warning = 0; - while ((GNUNET_NO == sched.shutdown) && - ((sched.pending != NULL) || (sched.ready_count > 0))) + while ( (sched.pending != NULL) || (sched.ready_count > 0) ) { GNUNET_NETWORK_fdset_zero (rs); GNUNET_NETWORK_fdset_zero (ws); - timeout = GNUNET_TIME_relative_get_forever (); + timeout = GNUNET_TIME_UNIT_FOREVER_REL; update_sets (&sched, rs, ws, &timeout); -#ifndef MINGW GNUNET_NETWORK_fdset_handle_set (rs, pr); -#endif if (sched.ready_count > 0) { /* no blocking, more work already ready! */ - timeout = GNUNET_TIME_relative_get_zero (); + timeout = GNUNET_TIME_UNIT_ZERO; } ret = GNUNET_NETWORK_socket_select (rs, ws, NULL, timeout); #ifndef MINGW if (GNUNET_NETWORK_fdset_handle_isset (rs, pr)) - break; + { + /* consume the signal */ + GNUNET_DISK_file_read (pr, &c, sizeof(c)); + /* mark all active tasks as ready due to shutdown */ + GNUNET_SCHEDULER_shutdown (&sched); + } #endif if (last_tr == sched.tasks_run) { @@ -574,7 +594,6 @@ GNUNET_SCHEDULER_run (GNUNET_SCHEDULER_Task task, void *cls) check_ready (&sched, rs, ws); run_ready (&sched); } - sched.shutdown = GNUNET_YES; #ifndef MINGW GNUNET_SIGNAL_handler_uninstall (shc_int); GNUNET_SIGNAL_handler_uninstall (shc_term); @@ -583,36 +602,11 @@ GNUNET_SCHEDULER_run (GNUNET_SCHEDULER_Task task, void *cls) GNUNET_DISK_pipe_close (sigpipe); sigpipe = NULL; #endif - do - { - run_ready (&sched); - check_ready (&sched, NULL, NULL); - } - while (sched.ready_count > 0); - while (NULL != (tpos = sched.pending)) - { - sched.pending = tpos->next; - GNUNET_free (tpos); - } GNUNET_NETWORK_fdset_destroy (rs); GNUNET_NETWORK_fdset_destroy (ws); } -/** - * Request the shutdown of a scheduler. This function can be used to - * stop a scheduling thread when created with the - * "GNUNET_SCHEDULER_init_thread" function or from within the signal - * handler for signals causing shutdowns. - * - * @param sched the scheduler - */ -void -GNUNET_SCHEDULER_shutdown (struct GNUNET_SCHEDULER_Handle *sched) -{ - sched->shutdown = GNUNET_YES; -} - /** * Get information about the current load of this scheduler. Use this @@ -715,102 +709,113 @@ GNUNET_SCHEDULER_cancel (struct GNUNET_SCHEDULER_Handle *sched, * and the reason code can be specified. * * @param sched scheduler to use - * @param run_on_shutdown should this task be run if we are shutting down? - * @param main main function of the task - * @param cls closure for 'main' + * @param task main function of the task + * @param task_cls closure for 'main' * @param reason reason for task invocation */ void GNUNET_SCHEDULER_add_continuation (struct GNUNET_SCHEDULER_Handle *sched, - int run_on_shutdown, - GNUNET_SCHEDULER_Task main, - void *cls, + GNUNET_SCHEDULER_Task task, + void *task_cls, enum GNUNET_SCHEDULER_Reason reason) { - struct Task *task; - - task = GNUNET_malloc (sizeof (struct Task)); - task->callback = main; - task->callback_cls = cls; - task->id = ++sched->last_id; - task->reason = reason; - task->priority = sched->current_priority; - task->run_on_shutdown = run_on_shutdown; + struct Task *t; + + t = GNUNET_malloc (sizeof (struct Task)); + t->callback = task; + t->callback_cls = task_cls; + t->id = ++sched->last_id; + t->reason = reason; + t->priority = sched->current_priority; #if DEBUG_TASKS GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Adding continuation task: %llu / %p\n", - task->id, task->callback_cls); + t->id, t->callback_cls); #endif - queue_ready_task (sched, task); + queue_ready_task (sched, t); } + /** - * Schedule a new task to be run after the specified - * prerequisite task has completed. + * Schedule a new task to be run after the specified prerequisite task + * has completed. It will be run with the priority of the calling + * task. * * @param sched scheduler to use - * @param run_on_shutdown run on shutdown? - * @param prio how important is this task? * @param prerequisite_task run this task after the task with the given * task identifier completes (and any of our other * conditions, such as delay, read or write-readyness * are satisfied). Use GNUNET_SCHEDULER_NO_TASK to not have any dependency - * on completion of other tasks. - * @param main main function of the task - * @param cls closure for 'main' + * on completion of other tasks (this will cause the task to run as + * soon as possible). + * @param task main function of the task + * @param task_cls closure of task * @return unique task identifier for the job - * only valid until "main" is started! + * only valid until "task" is started! */ GNUNET_SCHEDULER_TaskIdentifier GNUNET_SCHEDULER_add_after (struct GNUNET_SCHEDULER_Handle *sched, - int run_on_shutdown, - enum GNUNET_SCHEDULER_Priority prio, GNUNET_SCHEDULER_TaskIdentifier prerequisite_task, - GNUNET_SCHEDULER_Task main, void *cls) + GNUNET_SCHEDULER_Task task, + void *task_cls) { - return GNUNET_SCHEDULER_add_select (sched, run_on_shutdown, prio, + return GNUNET_SCHEDULER_add_select (sched, + GNUNET_SCHEDULER_PRIORITY_KEEP, prerequisite_task, GNUNET_TIME_UNIT_ZERO, - NULL, NULL, main, cls); + NULL, NULL, task, task_cls); } +/** + * Schedule a new task to be run with a specified priority. + * + * @param sched scheduler to use + * @param prio how important is the new task? + * @param task main function of the task + * @param task_cls closure of task + * @return unique task identifier for the job + * only valid until "task" is started! + */ +GNUNET_SCHEDULER_TaskIdentifier +GNUNET_SCHEDULER_add_with_priority (struct GNUNET_SCHEDULER_Handle *sched, + enum GNUNET_SCHEDULER_Priority prio, + GNUNET_SCHEDULER_Task task, + void *task_cls) +{ + return GNUNET_SCHEDULER_add_select (sched, + prio, + GNUNET_SCHEDULER_NO_TASK, + GNUNET_TIME_UNIT_ZERO, + NULL, NULL, task, task_cls); +} + + + /** * Schedule a new task to be run with a specified delay. The task - * will be scheduled for execution once the delay has expired and the - * prerequisite task has completed. + * will be scheduled for execution once the delay has expired. It + * will be run with the priority of the calling task. * * @param sched scheduler to use - * @param run_on_shutdown run on shutdown? You can use this - * argument to run a function only during shutdown - * by setting delay to -1. Set this - * argument to GNUNET_NO to skip this task if - * the user requested process termination. - * @param prio how important is this task? - * @param prerequisite_task run this task after the task with the given - * task identifier completes (and any of our other - * conditions, such as delay, read or write-readyness - * are satisfied). Use GNUNET_SCHEDULER_NO_TASK to not have any dependency - * on completion of other tasks. - * @param delay how long should we wait? Use GNUNET_TIME_UNIT_FOREVER_REL for "forever" - * @param main main function of the task - * @param cls closure of task + * @param delay when should this operation time out? Use + * GNUNET_TIME_UNIT_FOREVER_REL for "on shutdown" + * @param task main function of the task + * @param task_cls closure of task * @return unique task identifier for the job - * only valid until "main" is started! + * only valid until "task" is started! */ GNUNET_SCHEDULER_TaskIdentifier -GNUNET_SCHEDULER_add_delayed (struct GNUNET_SCHEDULER_Handle * sched, - int run_on_shutdown, - enum GNUNET_SCHEDULER_Priority prio, - GNUNET_SCHEDULER_TaskIdentifier - prerequisite_task, +GNUNET_SCHEDULER_add_delayed (struct GNUNET_SCHEDULER_Handle *sched, struct GNUNET_TIME_Relative delay, - GNUNET_SCHEDULER_Task main, void *cls) + GNUNET_SCHEDULER_Task task, + void *task_cls) { - return GNUNET_SCHEDULER_add_select (sched, run_on_shutdown, prio, - prerequisite_task, delay, - NULL, NULL, main, cls); + return GNUNET_SCHEDULER_add_select (sched, + GNUNET_SCHEDULER_PRIORITY_KEEP, + GNUNET_SCHEDULER_NO_TASK, delay, + NULL, NULL, task, task_cls); } @@ -819,34 +824,24 @@ GNUNET_SCHEDULER_add_delayed (struct GNUNET_SCHEDULER_Handle * sched, * specified file descriptor is ready for reading. The delay can be * used as a timeout on the socket being ready. The task will be * scheduled for execution once either the delay has expired or the - * socket operation is ready. + * socket operation is ready. It will be run with the priority of + * the calling task. * * @param sched scheduler to use - * @param run_on_shutdown run on shutdown? Set this - * argument to GNUNET_NO to skip this task if - * the user requested process termination. - * @param prio how important is this task? - * @param prerequisite_task run this task after the task with the given - * task identifier completes (and any of our other - * conditions, such as delay, read or write-readyness - * are satisfied). Use GNUNET_SCHEDULER_NO_TASK to not have any dependency - * on completion of other tasks. - * @param delay how long should we wait? Use GNUNET_TIME_UNIT_FOREVER_REL for "forever" + * @param delay when should this operation time out? Use + * GNUNET_TIME_UNIT_FOREVER_REL for "on shutdown" * @param rfd read file-descriptor - * @param main main function of the task - * @param cls closure of task + * @param task main function of the task + * @param task_cls closure of task * @return unique task identifier for the job - * only valid until "main" is started! + * only valid until "task" is started! */ GNUNET_SCHEDULER_TaskIdentifier -GNUNET_SCHEDULER_add_read_net (struct GNUNET_SCHEDULER_Handle * sched, - int run_on_shutdown, - enum GNUNET_SCHEDULER_Priority prio, - GNUNET_SCHEDULER_TaskIdentifier - prerequisite_task, - struct GNUNET_TIME_Relative delay, - struct GNUNET_NETWORK_Handle * rfd, - GNUNET_SCHEDULER_Task main, void *cls) +GNUNET_SCHEDULER_add_read_net (struct GNUNET_SCHEDULER_Handle *sched, + struct GNUNET_TIME_Relative delay, + struct GNUNET_NETWORK_Handle *rfd, + GNUNET_SCHEDULER_Task task, + void *task_cls) { struct GNUNET_NETWORK_FDSet *rs; GNUNET_SCHEDULER_TaskIdentifier ret; @@ -854,9 +849,11 @@ GNUNET_SCHEDULER_add_read_net (struct GNUNET_SCHEDULER_Handle * sched, GNUNET_assert (rfd != NULL); rs = GNUNET_NETWORK_fdset_create (); GNUNET_NETWORK_fdset_set (rs, rfd); - ret = GNUNET_SCHEDULER_add_select (sched, run_on_shutdown, prio, - prerequisite_task, delay, - rs, NULL, main, cls); + ret = GNUNET_SCHEDULER_add_select (sched, + GNUNET_SCHEDULER_PRIORITY_KEEP, + GNUNET_SCHEDULER_NO_TASK, + delay, + rs, NULL, task, task_cls); GNUNET_NETWORK_fdset_destroy (rs); return ret; } @@ -867,34 +864,24 @@ GNUNET_SCHEDULER_add_read_net (struct GNUNET_SCHEDULER_Handle * sched, * specified file descriptor is ready for writing. The delay can be * used as a timeout on the socket being ready. The task will be * scheduled for execution once either the delay has expired or the - * socket operation is ready. + * socket operation is ready. It will be run with the priority of + * the calling task. * * @param sched scheduler to use - * @param run_on_shutdown run on shutdown? Set this - * argument to GNUNET_NO to skip this task if - * the user requested process termination. - * @param prio how important is this task? - * @param prerequisite_task run this task after the task with the given - * task identifier completes (and any of our other - * conditions, such as delay, read or write-readyness - * are satisfied). Use GNUNET_SCHEDULER_NO_TASK to not have any dependency - * on completion of other tasks. - * @param delay how long should we wait? Use GNUNET_TIME_UNIT_FOREVER_REL for "forever" + * @param delay when should this operation time out? Use + * GNUNET_TIME_UNIT_FOREVER_REL for "on shutdown" * @param wfd write file-descriptor - * @param main main function of the task - * @param cls closure of task + * @param task main function of the task + * @param task_cls closure of task * @return unique task identifier for the job - * only valid until "main" is started! + * only valid until "task" is started! */ GNUNET_SCHEDULER_TaskIdentifier -GNUNET_SCHEDULER_add_write_net (struct GNUNET_SCHEDULER_Handle * sched, - int run_on_shutdown, - enum GNUNET_SCHEDULER_Priority prio, - GNUNET_SCHEDULER_TaskIdentifier - prerequisite_task, - struct GNUNET_TIME_Relative delay, - struct GNUNET_NETWORK_Handle * wfd, - GNUNET_SCHEDULER_Task main, void *cls) +GNUNET_SCHEDULER_add_write_net (struct GNUNET_SCHEDULER_Handle *sched, + struct GNUNET_TIME_Relative delay, + struct GNUNET_NETWORK_Handle *wfd, + GNUNET_SCHEDULER_Task task, + void *task_cls) { struct GNUNET_NETWORK_FDSet *ws; GNUNET_SCHEDULER_TaskIdentifier ret; @@ -902,14 +889,95 @@ GNUNET_SCHEDULER_add_write_net (struct GNUNET_SCHEDULER_Handle * sched, GNUNET_assert (wfd != NULL); ws = GNUNET_NETWORK_fdset_create (); GNUNET_NETWORK_fdset_set (ws, wfd); - ret = GNUNET_SCHEDULER_add_select (sched, run_on_shutdown, prio, - prerequisite_task, delay, - NULL, ws, main, cls); + ret = GNUNET_SCHEDULER_add_select (sched, + GNUNET_SCHEDULER_PRIORITY_KEEP, + GNUNET_SCHEDULER_NO_TASK, delay, + NULL, ws, task, task_cls); + GNUNET_NETWORK_fdset_destroy (ws); + return ret; +} + + +/** + * Schedule a new task to be run with a specified delay or when the + * specified file descriptor is ready for reading. The delay can be + * used as a timeout on the socket being ready. The task will be + * scheduled for execution once either the delay has expired or the + * socket operation is ready. It will be run with the priority of + * the calling task. + * + * @param sched scheduler to use + * @param delay when should this operation time out? Use + * GNUNET_TIME_UNIT_FOREVER_REL for "on shutdown" + * @param rfd read file-descriptor + * @param task main function of the task + * @param task_cls closure of task + * @return unique task identifier for the job + * only valid until "task" is started! + */ +GNUNET_SCHEDULER_TaskIdentifier +GNUNET_SCHEDULER_add_read_file (struct GNUNET_SCHEDULER_Handle *sched, + struct GNUNET_TIME_Relative delay, + const struct GNUNET_DISK_FileHandle *rfd, + GNUNET_SCHEDULER_Task task, + void *task_cls) +{ + struct GNUNET_NETWORK_FDSet *rs; + GNUNET_SCHEDULER_TaskIdentifier ret; + + GNUNET_assert (rfd != NULL); + rs = GNUNET_NETWORK_fdset_create (); + GNUNET_NETWORK_fdset_handle_set (rs, rfd); + ret = GNUNET_SCHEDULER_add_select (sched, + GNUNET_SCHEDULER_PRIORITY_KEEP, + GNUNET_SCHEDULER_NO_TASK, delay, + rs, NULL, task, task_cls); + GNUNET_NETWORK_fdset_destroy (rs); + return ret; +} + + +/** + * Schedule a new task to be run with a specified delay or when the + * specified file descriptor is ready for writing. The delay can be + * used as a timeout on the socket being ready. The task will be + * scheduled for execution once either the delay has expired or the + * socket operation is ready. It will be run with the priority of + * the calling task. + * + * @param sched scheduler to use + * @param delay when should this operation time out? Use + * GNUNET_TIME_UNIT_FOREVER_REL for "on shutdown" + * @param wfd write file-descriptor + * @param task main function of the task + * @param task_cls closure of task + * @return unique task identifier for the job + * only valid until "task" is started! + */ +GNUNET_SCHEDULER_TaskIdentifier +GNUNET_SCHEDULER_add_write_file (struct GNUNET_SCHEDULER_Handle *sched, + struct GNUNET_TIME_Relative delay, + const struct GNUNET_DISK_FileHandle *wfd, + GNUNET_SCHEDULER_Task task, + void *task_cls) +{ + struct GNUNET_NETWORK_FDSet *ws; + GNUNET_SCHEDULER_TaskIdentifier ret; + + GNUNET_assert (wfd != NULL); + ws = GNUNET_NETWORK_fdset_create (); + GNUNET_NETWORK_fdset_handle_set (ws, wfd); + ret = GNUNET_SCHEDULER_add_select (sched, + GNUNET_SCHEDULER_PRIORITY_KEEP, + GNUNET_SCHEDULER_NO_TASK, + delay, + NULL, ws, task, task_cls); GNUNET_NETWORK_fdset_destroy (ws); return ret; } + /** * Schedule a new task to be run with a specified delay or when any of * the specified file descriptor sets is ready. The delay can be used @@ -928,160 +996,61 @@ GNUNET_SCHEDULER_add_write_net (struct GNUNET_SCHEDULER_Handle * sched, * * * @param sched scheduler to use - * @param run_on_shutdown run on shutdown? Set this - * argument to GNUNET_NO to skip this task if - * the user requested process termination. * @param prio how important is this task? * @param prerequisite_task run this task after the task with the given * task identifier completes (and any of our other * conditions, such as delay, read or write-readyness * are satisfied). Use GNUNET_SCHEDULER_NO_TASK to not have any dependency * on completion of other tasks. - * @param delay how long should we wait? Use GNUNET_TIME_UNIT_FOREVER_REL for "forever" + * @param delay how long should we wait? Use GNUNET_TIME_UNIT_FOREVER_REL for "forever", + * which means that the task will only be run after we receive SIGTERM * @param rs set of file descriptors we want to read (can be NULL) * @param ws set of file descriptors we want to write (can be NULL) - * @param main main function of the task - * @param cls closure of task + * @param task main function of the task + * @param task_cls closure of task * @return unique task identifier for the job - * only valid until "main" is started! + * only valid until "task" is started! */ GNUNET_SCHEDULER_TaskIdentifier -GNUNET_SCHEDULER_add_select (struct GNUNET_SCHEDULER_Handle * sched, - int run_on_shutdown, +GNUNET_SCHEDULER_add_select (struct GNUNET_SCHEDULER_Handle *sched, enum GNUNET_SCHEDULER_Priority prio, GNUNET_SCHEDULER_TaskIdentifier prerequisite_task, struct GNUNET_TIME_Relative delay, const struct GNUNET_NETWORK_FDSet * rs, - const struct GNUNET_NETWORK_FDSet * ws, - GNUNET_SCHEDULER_Task main, void *cls) + const struct GNUNET_NETWORK_FDSet * ws, + GNUNET_SCHEDULER_Task task, + void *task_cls) { - struct Task *task; + struct Task *t; - task = GNUNET_malloc (sizeof (struct Task)); - task->callback = main; - task->callback_cls = cls; + t = GNUNET_malloc (sizeof (struct Task)); + t->callback = task; + t->callback_cls = task_cls; if (rs != NULL) { - task->read_set = GNUNET_NETWORK_fdset_create (); - GNUNET_NETWORK_fdset_copy (task->read_set, rs); + t->read_set = GNUNET_NETWORK_fdset_create (); + GNUNET_NETWORK_fdset_copy (t->read_set, rs); } if (ws != NULL) { - task->write_set = GNUNET_NETWORK_fdset_create (); - GNUNET_NETWORK_fdset_copy (task->write_set, ws); + t->write_set = GNUNET_NETWORK_fdset_create (); + GNUNET_NETWORK_fdset_copy (t->write_set, ws); } - task->id = ++sched->last_id; - task->prereq_id = prerequisite_task; - task->timeout = GNUNET_TIME_relative_to_absolute (delay); - task->priority = + t->id = ++sched->last_id; + t->prereq_id = prerequisite_task; + t->timeout = GNUNET_TIME_relative_to_absolute (delay); + t->priority = check_priority ((prio == GNUNET_SCHEDULER_PRIORITY_KEEP) ? sched->current_priority : prio); - task->run_on_shutdown = run_on_shutdown; - task->next = sched->pending; - sched->pending = task; + t->next = sched->pending; + sched->pending = t; #if DEBUG_TASKS GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Adding task: %llu / %p\n", task->id, task->callback_cls); + "Adding task: %llu / %p\n", t->id, t->callback_cls); #endif - return task->id; + return t->id; } -/** - * Schedule a new task to be run with a specified delay or when the - * specified file descriptor is ready for reading. The delay can be - * used as a timeout on the socket being ready. The task will be - * scheduled for execution once either the delay has expired or the - * socket operation is ready. - * - * @param sched scheduler to use - * @param run_on_shutdown run on shutdown? Set this - * argument to GNUNET_NO to skip this task if - * the user requested process termination. - * @param prio how important is this task? - * @param prerequisite_task run this task after the task with the given - * task identifier completes (and any of our other - * conditions, such as delay, read or write-readyness - * are satisfied). Use GNUNET_SCHEDULER_NO_TASK to not have any dependency - * on completion of other tasks. - * @param delay how long should we wait? Use GNUNET_TIME_UNIT_FOREVER_REL for "forever" - * @param rfd read file-descriptor - * @param main main function of the task - * @param cls closure of task - * @return unique task identifier for the job - * only valid until "main" is started! - */ -GNUNET_SCHEDULER_TaskIdentifier -GNUNET_SCHEDULER_add_read_file (struct GNUNET_SCHEDULER_Handle * sched, - int run_on_shutdown, - enum GNUNET_SCHEDULER_Priority prio, - GNUNET_SCHEDULER_TaskIdentifier - prerequisite_task, - struct GNUNET_TIME_Relative delay, - const struct GNUNET_DISK_FileHandle * rfd, - GNUNET_SCHEDULER_Task main, void *cls) -{ - struct GNUNET_NETWORK_FDSet *rs; - GNUNET_SCHEDULER_TaskIdentifier ret; - - GNUNET_assert (rfd != NULL); - rs = GNUNET_NETWORK_fdset_create (); - GNUNET_NETWORK_fdset_handle_set (rs, rfd); - ret = GNUNET_SCHEDULER_add_select (sched, run_on_shutdown, prio, - prerequisite_task, delay, - rs, NULL, main, cls); - GNUNET_NETWORK_fdset_destroy (rs); - return ret; -} - - -/** - * Schedule a new task to be run with a specified delay or when the - * specified file descriptor is ready for writing. The delay can be - * used as a timeout on the socket being ready. The task will be - * scheduled for execution once either the delay has expired or the - * socket operation is ready. - * - * @param sched scheduler to use - * @param run_on_shutdown run on shutdown? Set this - * argument to GNUNET_NO to skip this task if - * the user requested process termination. - * @param prio how important is this task? - * @param prerequisite_task run this task after the task with the given - * task identifier completes (and any of our other - * conditions, such as delay, read or write-readyness - * are satisfied). Use GNUNET_SCHEDULER_NO_TASK to not have any dependency - * on completion of other tasks. - * @param delay how long should we wait? Use GNUNET_TIME_UNIT_FOREVER_REL for "forever" - * @param wfd write file-descriptor - * @param main main function of the task - * @param cls closure of task - * @return unique task identifier for the job - * only valid until "main" is started! - */ -GNUNET_SCHEDULER_TaskIdentifier -GNUNET_SCHEDULER_add_write_file (struct GNUNET_SCHEDULER_Handle * sched, - int run_on_shutdown, - enum GNUNET_SCHEDULER_Priority prio, - GNUNET_SCHEDULER_TaskIdentifier - prerequisite_task, - struct GNUNET_TIME_Relative delay, - const struct GNUNET_DISK_FileHandle * wfd, - GNUNET_SCHEDULER_Task main, void *cls) -{ - struct GNUNET_NETWORK_FDSet *ws; - GNUNET_SCHEDULER_TaskIdentifier ret; - - GNUNET_assert (wfd != NULL); - ws = GNUNET_NETWORK_fdset_create (); - GNUNET_NETWORK_fdset_handle_set (ws, wfd); - ret = GNUNET_SCHEDULER_add_select (sched, run_on_shutdown, prio, - prerequisite_task, delay, - NULL, ws, main, cls); - GNUNET_NETWORK_fdset_destroy (ws); - return ret; -} - - /* end of scheduler.c */ diff --git a/src/util/server.c b/src/util/server.c index 42fa8c46c..ff9c8c192 100644 --- a/src/util/server.c +++ b/src/util/server.c @@ -349,7 +349,6 @@ process_listen_socket (void *cls, GNUNET_NETWORK_fdset_set (r, server->listen_socket); GNUNET_NETWORK_fdset_handle_set (r, shutpipe); GNUNET_SCHEDULER_add_select (server->sched, - GNUNET_YES, GNUNET_SCHEDULER_PRIORITY_HIGH, GNUNET_SCHEDULER_NO_TASK, GNUNET_TIME_UNIT_FOREVER_REL, @@ -475,7 +474,7 @@ GNUNET_SERVER_create (struct GNUNET_SCHEDULER_Handle *sched, GNUNET_NETWORK_fdset_handle_set (r, GNUNET_DISK_pipe_handle (ret->shutpipe, GNUNET_DISK_PIPE_END_READ)); - GNUNET_SCHEDULER_add_select (sched, GNUNET_YES, + GNUNET_SCHEDULER_add_select (sched, GNUNET_SCHEDULER_PRIORITY_HIGH, GNUNET_SCHEDULER_NO_TASK, GNUNET_TIME_UNIT_FOREVER_REL, r, NULL, @@ -1167,7 +1166,6 @@ GNUNET_SERVER_receive_done (struct GNUNET_SERVER_Client *client, int success) if (GNUNET_YES != client->shutdown_now) { GNUNET_SCHEDULER_add_continuation (client->server->sched, - GNUNET_NO, &restart_processing, client, GNUNET_SCHEDULER_REASON_PREREQ_DONE); diff --git a/src/util/service.c b/src/util/service.c index 0a33809be..173c0f566 100644 --- a/src/util/service.c +++ b/src/util/service.c @@ -1067,6 +1067,22 @@ write_pid_file (struct GNUNET_SERVICE_Context *sctx, pid_t pid) } +/** + * Task run during shutdown. + * + * @param cls unused + * @param tc unused + */ +static void +shutdown_task (void *cls, + const struct GNUNET_SCHEDULER_TaskContext *tc) +{ + struct GNUNET_SERVER_Handle *server = cls; + + GNUNET_SERVER_destroy (server); +} + + /** * Initial task for the service. */ @@ -1092,6 +1108,10 @@ service_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) sctx->ret = GNUNET_SYSERR; return; } + GNUNET_SCHEDULER_add_delayed (tc->sched, + GNUNET_TIME_UNIT_FOREVER_REL, + &shutdown_task, + sctx->server); sctx->my_handlers = GNUNET_malloc (sizeof (defhandlers)); memcpy (sctx->my_handlers, defhandlers, sizeof (defhandlers)); i = 0; @@ -1249,6 +1269,7 @@ pid_file_delete (struct GNUNET_SERVICE_Context *sctx) GNUNET_free (pif); } + /** * Run a standard GNUnet service startup sequence (initialize loggers * and configuration, parse options). @@ -1258,8 +1279,6 @@ pid_file_delete (struct GNUNET_SERVICE_Context *sctx) * @param serviceName our service name * @param task main task of the service * @param task_cls closure for task - * @param term termination task of the service - * @param term_cls closure for term * @return GNUNET_SYSERR on error, GNUNET_OK * if we shutdown nicely */ @@ -1268,7 +1287,7 @@ GNUNET_SERVICE_run (int argc, char *const *argv, const char *serviceName, GNUNET_SERVICE_Main task, - void *task_cls, GNUNET_SERVICE_Term term, void *term_cls) + void *task_cls) { char *cfg_fn; char *loglev; @@ -1347,12 +1366,8 @@ GNUNET_SERVICE_run (int argc, } /* shutdown */ - if (term != NULL) - term (term_cls, sctx.cfg); if ((do_daemonize == 1) && (sctx.server != NULL)) pid_file_delete (&sctx); - if (sctx.server != NULL) - GNUNET_SERVER_destroy (sctx.server); GNUNET_free_non_null (sctx.my_handlers); GNUNET_CONFIGURATION_destroy (cfg); GNUNET_free_non_null (sctx.addr); @@ -1413,8 +1428,6 @@ GNUNET_SERVICE_start (const char *serviceName, while ((sctx->my_handlers[i].callback != NULL)) sctx->my_handlers[i++].callback_cls = sctx; GNUNET_SERVER_add_handlers (sctx->server, sctx->my_handlers); - - return sctx; } diff --git a/src/util/test_connection.c b/src/util/test_connection.c index 0f4c46b3b..07b5e843d 100644 --- a/src/util/test_connection.c +++ b/src/util/test_connection.c @@ -175,9 +175,6 @@ task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test prepares to accept\n"); #endif GNUNET_SCHEDULER_add_read_net (tc->sched, - GNUNET_NO, - GNUNET_SCHEDULER_PRIORITY_HIGH, - GNUNET_SCHEDULER_NO_TASK, GNUNET_TIME_UNIT_FOREVER_REL, ls, &run_accept, cls); } diff --git a/src/util/test_connection_addressing.c b/src/util/test_connection_addressing.c index 1b85dfac6..d6ac309f7 100644 --- a/src/util/test_connection_addressing.c +++ b/src/util/test_connection_addressing.c @@ -169,9 +169,6 @@ task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) &make_hello, NULL)); GNUNET_CONNECTION_destroy (csock); GNUNET_SCHEDULER_add_read_net (tc->sched, - GNUNET_NO, - GNUNET_SCHEDULER_PRIORITY_HIGH, - GNUNET_SCHEDULER_NO_TASK, GNUNET_TIME_UNIT_FOREVER_REL, ls, &run_accept, cls); } diff --git a/src/util/test_connection_receive_cancel.c b/src/util/test_connection_receive_cancel.c index 5856e27ed..b90191384 100644 --- a/src/util/test_connection_receive_cancel.c +++ b/src/util/test_connection_receive_cancel.c @@ -124,15 +124,9 @@ task_receive_cancel (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) "localhost", PORT, 1024); GNUNET_assert (csock != NULL); GNUNET_SCHEDULER_add_read_net (tc->sched, - GNUNET_NO, - GNUNET_SCHEDULER_PRIORITY_HIGH, - GNUNET_SCHEDULER_NO_TASK, GNUNET_TIME_UNIT_FOREVER_REL, ls, &run_accept_cancel, cls); GNUNET_SCHEDULER_add_delayed (tc->sched, - GNUNET_NO, - GNUNET_SCHEDULER_PRIORITY_KEEP, - GNUNET_SCHEDULER_NO_TASK, GNUNET_TIME_UNIT_SECONDS, &receive_cancel_task, cls); } diff --git a/src/util/test_crypto_hash.c b/src/util/test_crypto_hash.c index 97ef4ec88..b650355c0 100644 --- a/src/util/test_crypto_hash.c +++ b/src/util/test_crypto_hash.c @@ -124,7 +124,7 @@ file_hasher (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { GNUNET_CRYPTO_hash_file (tc->sched, GNUNET_SCHEDULER_PRIORITY_DEFAULT, - GNUNET_NO, FILENAME, 1024, &finished_task, cls); + FILENAME, 1024, &finished_task, cls); } diff --git a/src/util/test_scheduler.c b/src/util/test_scheduler.c index 98dce6f97..3021dce19 100644 --- a/src/util/test_scheduler.c +++ b/src/util/test_scheduler.c @@ -29,14 +29,6 @@ #define VERBOSE GNUNET_NO -static void -task2 (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) -{ - int *ok = cls; - GNUNET_assert (2 == *ok); - (*ok) = 3; -} - static void task3 (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { @@ -48,6 +40,19 @@ task3 (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) (*ok) = 4; } + +static void +task2 (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) +{ + int *ok = cls; + GNUNET_assert (2 == *ok); + (*ok) = 3; + /* t3 will go before t4: higher priority */ + GNUNET_SCHEDULER_add_with_priority (tc->sched, + GNUNET_SCHEDULER_PRIORITY_UI, + &task3, cls); +} + static void task4 (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { @@ -96,14 +101,9 @@ taskRd (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) GNUNET_assert (GNUNET_NETWORK_fdset_handle_isset (tc->read_ready, fds[0])); GNUNET_assert (1 == GNUNET_DISK_file_read (fds[0], &c, 1)); (*ok) = 8; - GNUNET_SCHEDULER_add_after (tc->sched, - GNUNET_NO, - GNUNET_SCHEDULER_PRIORITY_UI, - 0, &taskNeverRun, NULL); - GNUNET_SCHEDULER_add_after (tc->sched, - GNUNET_YES, - GNUNET_SCHEDULER_PRIORITY_IDLE, - 0, &taskLast, cls); + GNUNET_SCHEDULER_add_with_priority (tc->sched, + GNUNET_SCHEDULER_PRIORITY_IDLE, + &taskLast, cls); GNUNET_SCHEDULER_shutdown (tc->sched); } @@ -119,15 +119,9 @@ task5 (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) fds[0] = GNUNET_DISK_pipe_handle (p, GNUNET_DISK_PIPE_END_READ); fds[1] = GNUNET_DISK_pipe_handle (p, GNUNET_DISK_PIPE_END_WRITE); GNUNET_SCHEDULER_add_read_file (tc->sched, - GNUNET_NO, - GNUNET_SCHEDULER_PRIORITY_DEFAULT, - GNUNET_SCHEDULER_NO_TASK, GNUNET_TIME_UNIT_FOREVER_REL, fds[0], &taskRd, cls); GNUNET_SCHEDULER_add_write_file (tc->sched, - GNUNET_NO, - GNUNET_SCHEDULER_PRIORITY_DEFAULT, - GNUNET_SCHEDULER_NO_TASK, GNUNET_TIME_UNIT_FOREVER_REL, fds[1], &taskWrt, cls); } @@ -144,24 +138,13 @@ task1 (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) (*ok) = 2; /* t2 will go first -- prereq for all */ t2 = GNUNET_SCHEDULER_add_after (tc->sched, - GNUNET_NO, - GNUNET_SCHEDULER_PRIORITY_IDLE, GNUNET_SCHEDULER_NO_TASK, &task2, cls); - /* t3 will go before t4: higher priority */ + /* t4 will go after t2 ('add after') and after t3 (priority) */ t4 = GNUNET_SCHEDULER_add_after (tc->sched, - GNUNET_NO, - GNUNET_SCHEDULER_PRIORITY_IDLE, t2, &task4, cls); - GNUNET_SCHEDULER_add_delayed (tc->sched, - GNUNET_NO, - GNUNET_SCHEDULER_PRIORITY_DEFAULT, - t2, - GNUNET_TIME_relative_get_zero (), - &task3, cls); - /* t4 will go first: lower prio, but prereq! */ + /* t5 will go last (after p4) */ GNUNET_SCHEDULER_add_after (tc->sched, - GNUNET_NO, - GNUNET_SCHEDULER_PRIORITY_UI, t4, &task5, cls); + t4, &task5, cls); } @@ -181,21 +164,48 @@ check () } +static void +taskShutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) +{ + int *ok = cls; + GNUNET_assert (1 == *ok); + *ok = 8; + GNUNET_SCHEDULER_add_delayed (tc->sched, + GNUNET_TIME_UNIT_FOREVER_REL, + &taskLast, cls); + GNUNET_SCHEDULER_shutdown (tc->sched); +} + + +/** + * Main method, starts scheduler with task1, + * checks that "ok" is correct at the end. + */ +static int +checkShutdown () +{ + int ok; + + ok = 1; + GNUNET_SCHEDULER_run (&taskShutdown, &ok); + return ok; +} + + static void taskSig (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { int *ok = cls; GNUNET_assert (1 == *ok); *ok = 8; - GNUNET_SCHEDULER_add_after (tc->sched, - GNUNET_NO, - GNUNET_SCHEDULER_PRIORITY_UI, - 0, &taskNeverRun, NULL); - GNUNET_SCHEDULER_add_after (tc->sched, - GNUNET_YES, - GNUNET_SCHEDULER_PRIORITY_UI, - 0, &taskLast, cls); + GNUNET_SCHEDULER_add_delayed (tc->sched, + GNUNET_TIME_UNIT_FOREVER_REL, + &taskLast, cls); +#ifndef MINGW GNUNET_break (0 == PLIBC_KILL (getpid (), SIGTERM)); +#else + GNUNET_SCHEDULER_shutdown (tc->sched); +#endif } @@ -214,8 +224,6 @@ checkSignal () } - - static void taskCancel (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { @@ -225,9 +233,7 @@ taskCancel (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) *ok = 0; GNUNET_SCHEDULER_cancel (tc->sched, GNUNET_SCHEDULER_add_after (tc->sched, - GNUNET_NO, - GNUNET_SCHEDULER_PRIORITY_UI, - 0, + GNUNET_SCHEDULER_NO_TASK, &taskNeverRun, NULL)); } @@ -256,6 +262,7 @@ main (int argc, char *argv[]) GNUNET_log_setup ("test_scheduler", "WARNING", NULL); ret += check (); ret += checkSignal (); + ret += checkShutdown (); ret += checkCancel (); GNUNET_DISK_pipe_close (p); diff --git a/src/util/test_scheduler_delay.c b/src/util/test_scheduler_delay.c index f5477fd4c..d1d61c3e4 100644 --- a/src/util/test_scheduler_delay.c +++ b/src/util/test_scheduler_delay.c @@ -66,9 +66,6 @@ test_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) return; } GNUNET_SCHEDULER_add_delayed (tc->sched, - GNUNET_NO, - GNUNET_SCHEDULER_PRIORITY_DEFAULT, - GNUNET_SCHEDULER_NO_TASK, GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, i), &test_task, NULL); diff --git a/src/util/test_server.c b/src/util/test_server.c index ae5609de0..95206c0f1 100644 --- a/src/util/test_server.c +++ b/src/util/test_server.c @@ -100,9 +100,6 @@ my_receive (void *cls, stctx->cb = receiver; stctx->cb_cls = receiver_cls; ret = GNUNET_SCHEDULER_add_delayed (sched, - GNUNET_NO, - GNUNET_SCHEDULER_PRIORITY_KEEP, - GNUNET_SCHEDULER_NO_TASK, timeout, &signal_timeout, stctx); break; default: diff --git a/src/util/test_server_disconnect.c b/src/util/test_server_disconnect.c index c5ce5e736..30fc34b08 100644 --- a/src/util/test_server_disconnect.c +++ b/src/util/test_server_disconnect.c @@ -95,9 +95,6 @@ recv_cb (void *cls, case 2: ok++; GNUNET_SCHEDULER_add_delayed (sched, - GNUNET_YES, - GNUNET_SCHEDULER_PRIORITY_KEEP, - GNUNET_SCHEDULER_NO_TASK, GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 50), &send_done, argclient); @@ -105,9 +102,6 @@ recv_cb (void *cls, case 4: ok++; GNUNET_SCHEDULER_add_delayed (sched, - GNUNET_YES, - GNUNET_SCHEDULER_PRIORITY_KEEP, - GNUNET_SCHEDULER_NO_TASK, GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 50), &server_disconnect, argclient); diff --git a/src/util/test_server_with_client.c b/src/util/test_server_with_client.c index 508c505b1..860ed3837 100644 --- a/src/util/test_server_with_client.c +++ b/src/util/test_server_with_client.c @@ -87,9 +87,6 @@ recv_cb (void *cls, case 2: ok++; GNUNET_SCHEDULER_add_delayed (sched, - GNUNET_YES, - GNUNET_SCHEDULER_PRIORITY_KEEP, - GNUNET_SCHEDULER_NO_TASK, GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 50), &send_done, argclient); diff --git a/src/util/test_service.c b/src/util/test_service.c index 93cafb4d2..fa35da6e9 100644 --- a/src/util/test_service.c +++ b/src/util/test_service.c @@ -30,6 +30,7 @@ #include "gnunet_scheduler_lib.h" #include "gnunet_time_lib.h" + #define VERBOSE GNUNET_NO #define PORT 12435 @@ -40,6 +41,9 @@ static struct GNUNET_SCHEDULER_Handle *sched; static struct GNUNET_SERVICE_Context *sctx; +static int ok = 1; + + static void end_it (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { @@ -47,8 +51,11 @@ end_it (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutting down service\n"); GNUNET_CLIENT_service_shutdown (client); - if (sctx != NULL) + if (sctx != NULL) GNUNET_SERVICE_stop (sctx); + else + GNUNET_SCHEDULER_shutdown (sched); + ok = 0; } @@ -63,7 +70,6 @@ build_msg (void *cls, size_t size, void *buf) msg->type = htons (MY_TYPE); msg->size = htons (sizeof (struct GNUNET_MessageHeader)); GNUNET_SCHEDULER_add_continuation (sched, - GNUNET_YES, &end_it, client, GNUNET_SCHEDULER_REASON_PREREQ_DONE); @@ -103,6 +109,9 @@ static struct GNUNET_SERVER_MessageHandler myhandlers[] = { {NULL, NULL, 0, 0} }; + + + static void runner (void *cls, struct GNUNET_SCHEDULER_Handle *sched, @@ -117,12 +126,6 @@ runner (void *cls, (void *) cfg); } -static void -term (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg) -{ - int *ok = cls; - *ok = 0; -} /** * Main method, starts scheduler with task1, @@ -131,7 +134,7 @@ term (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg) static int check () { - int ok = 1; + ok = 1; char *const argv[] = { "test_service", "-c", @@ -149,12 +152,12 @@ check () GNUNET_SERVICE_run (5, argv, "test_service", - &runner, &ok, &term, &ok)); + &runner, &ok)); GNUNET_assert (0 == ok); return ok; } -static void +static void ready6 (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { const struct GNUNET_CONFIGURATION_Handle *cfg = cls; @@ -193,7 +196,6 @@ runner6 (void *cls, static int check6 () { - int ok = 1; char *const argv[] = { "test_service6", "-c", @@ -211,7 +213,7 @@ check6 () GNUNET_SERVICE_run (5, argv, "test_service6", - &runner6, &ok, &term, &ok)); + &runner6, &ok)); GNUNET_assert (0 == ok); return ok; } @@ -224,7 +226,7 @@ check6 () static int check6d () { - int ok = 1; + ok = 1; char *const argv[] = { "test_service6", "-c", @@ -243,7 +245,7 @@ check6d () GNUNET_SERVICE_run (6, argv, "test_service6", - &runner6, &ok, &term, &ok)); + &runner6, &ok)); GNUNET_break (0 == ok); return ok; }