diff options
author | Christian Grothoff <christian@grothoff.org> | 2020-02-04 18:56:17 +0100 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2020-02-04 18:56:17 +0100 |
commit | f40520b094620f160a582af8810bfba7da61004b (patch) | |
tree | 35ec7bf7ac46085a6bc5d5edece81d15281ebf5c /src/util/scheduler.c | |
parent | 4caa0d2907082868e32a77c5a8ebf85c527497ca (diff) | |
download | gnunet-f40520b094620f160a582af8810bfba7da61004b.tar.gz gnunet-f40520b094620f160a582af8810bfba7da61004b.zip |
speed up running of tasks via GNUNTE_SCHEDULER_add_now() by a factor of at least 5
Diffstat (limited to 'src/util/scheduler.c')
-rw-r--r-- | src/util/scheduler.c | 36 |
1 files changed, 28 insertions, 8 deletions
diff --git a/src/util/scheduler.c b/src/util/scheduler.c index 48a3f04ce..4be690d44 100644 --- a/src/util/scheduler.c +++ b/src/util/scheduler.c | |||
@@ -719,9 +719,11 @@ GNUNET_SCHEDULER_run (GNUNET_SCHEDULER_TaskCallback task, | |||
719 | { | 719 | { |
720 | struct GNUNET_SCHEDULER_Handle *sh; | 720 | struct GNUNET_SCHEDULER_Handle *sh; |
721 | struct GNUNET_SCHEDULER_Driver *driver; | 721 | struct GNUNET_SCHEDULER_Driver *driver; |
722 | struct DriverContext context = { .scheduled_head = NULL, | 722 | struct DriverContext context = { |
723 | .scheduled_tail = NULL, | 723 | .scheduled_head = NULL, |
724 | .timeout = GNUNET_TIME_absolute_get () }; | 724 | .scheduled_tail = NULL, |
725 | .timeout = GNUNET_TIME_absolute_get () | ||
726 | }; | ||
725 | 727 | ||
726 | driver = GNUNET_SCHEDULER_driver_select (); | 728 | driver = GNUNET_SCHEDULER_driver_select (); |
727 | driver->cls = &context; | 729 | driver->cls = &context; |
@@ -1280,9 +1282,24 @@ struct GNUNET_SCHEDULER_Task * | |||
1280 | GNUNET_SCHEDULER_add_now (GNUNET_SCHEDULER_TaskCallback task, | 1282 | GNUNET_SCHEDULER_add_now (GNUNET_SCHEDULER_TaskCallback task, |
1281 | void *task_cls) | 1283 | void *task_cls) |
1282 | { | 1284 | { |
1283 | return GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_ZERO, | 1285 | struct GNUNET_SCHEDULER_Task *t; |
1284 | task, | 1286 | |
1285 | task_cls); | 1287 | t = GNUNET_new (struct GNUNET_SCHEDULER_Task); |
1288 | GNUNET_async_scope_get (&t->scope); | ||
1289 | t->callback = task; | ||
1290 | t->callback_cls = task_cls; | ||
1291 | t->read_fd = -1; | ||
1292 | t->write_fd = -1; | ||
1293 | #if PROFILE_DELAYS | ||
1294 | t->start_time = GNUNET_TIME_absolute_get (); | ||
1295 | #endif | ||
1296 | t->timeout = GNUNET_TIME_UNIT_ZERO_ABS; | ||
1297 | t->priority = current_priority; | ||
1298 | t->on_shutdown = GNUNET_YES; | ||
1299 | t->lifeness = current_lifeness; | ||
1300 | queue_ready_task (t); | ||
1301 | init_backtrace (t); | ||
1302 | return t; | ||
1286 | } | 1303 | } |
1287 | 1304 | ||
1288 | 1305 | ||
@@ -2290,6 +2307,8 @@ select_loop (struct GNUNET_SCHEDULER_Handle *sh, | |||
2290 | (GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us != | 2307 | (GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us != |
2291 | context->timeout.abs_value_us)) | 2308 | context->timeout.abs_value_us)) |
2292 | { | 2309 | { |
2310 | struct GNUNET_TIME_Relative time_remaining; | ||
2311 | |||
2293 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 2312 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
2294 | "select timeout = %s\n", | 2313 | "select timeout = %s\n", |
2295 | GNUNET_STRINGS_absolute_time_to_string (context->timeout)); | 2314 | GNUNET_STRINGS_absolute_time_to_string (context->timeout)); |
@@ -2310,8 +2329,9 @@ select_loop (struct GNUNET_SCHEDULER_Handle *sh, | |||
2310 | GNUNET_NETWORK_fdset_set_native (ws, pos->fdi->sock); | 2329 | GNUNET_NETWORK_fdset_set_native (ws, pos->fdi->sock); |
2311 | } | 2330 | } |
2312 | } | 2331 | } |
2313 | struct GNUNET_TIME_Relative time_remaining = | 2332 | time_remaining = GNUNET_TIME_absolute_get_remaining (context->timeout); |
2314 | GNUNET_TIME_absolute_get_remaining (context->timeout); | 2333 | if (0 < ready_count) |
2334 | time_remaining = GNUNET_TIME_UNIT_ZERO; | ||
2315 | if (NULL == scheduler_select) | 2335 | if (NULL == scheduler_select) |
2316 | { | 2336 | { |
2317 | select_result = GNUNET_NETWORK_socket_select (rs, | 2337 | select_result = GNUNET_NETWORK_socket_select (rs, |