diff options
author | Christian Grothoff <christian@grothoff.org> | 2014-12-24 01:10:47 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2014-12-24 01:10:47 +0000 |
commit | f1f603c7d0b3f03dca46a4f313472288eb080eb1 (patch) | |
tree | 3a29966b02dfb83e0a8a8d5c42b3116380209fb0 /src/cadet/test_cadet.c | |
parent | 53cd5b8eda2fa8db86b0907a62a39598981d008a (diff) | |
download | gnunet-f1f603c7d0b3f03dca46a4f313472288eb080eb1.tar.gz gnunet-f1f603c7d0b3f03dca46a4f313472288eb080eb1.zip |
making GNUNET_SCHEDULER_cancel() perform in O(1) instead of O(n) to help or even fully address #3247
Diffstat (limited to 'src/cadet/test_cadet.c')
-rw-r--r-- | src/cadet/test_cadet.c | 28 |
1 files changed, 14 insertions, 14 deletions
diff --git a/src/cadet/test_cadet.c b/src/cadet/test_cadet.c index b9661a9b7..df605d0a9 100644 --- a/src/cadet/test_cadet.c +++ b/src/cadet/test_cadet.c | |||
@@ -144,17 +144,17 @@ struct GNUNET_CADET_TEST_Context *test_ctx; | |||
144 | /** | 144 | /** |
145 | * Task called to disconnect peers. | 145 | * Task called to disconnect peers. |
146 | */ | 146 | */ |
147 | static GNUNET_SCHEDULER_TaskIdentifier disconnect_task; | 147 | static struct GNUNET_SCHEDULER_Task * disconnect_task; |
148 | 148 | ||
149 | /** | 149 | /** |
150 | * Task To perform tests | 150 | * Task To perform tests |
151 | */ | 151 | */ |
152 | static GNUNET_SCHEDULER_TaskIdentifier test_task; | 152 | static struct GNUNET_SCHEDULER_Task * test_task; |
153 | 153 | ||
154 | /** | 154 | /** |
155 | * Task called to shutdown test. | 155 | * Task called to shutdown test. |
156 | */ | 156 | */ |
157 | static GNUNET_SCHEDULER_TaskIdentifier shutdown_handle; | 157 | static struct GNUNET_SCHEDULER_Task * shutdown_handle; |
158 | 158 | ||
159 | /** | 159 | /** |
160 | * Cadet handle for the root peer | 160 | * Cadet handle for the root peer |
@@ -254,7 +254,7 @@ static void | |||
254 | shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 254 | shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
255 | { | 255 | { |
256 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Ending test.\n"); | 256 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Ending test.\n"); |
257 | shutdown_handle = GNUNET_SCHEDULER_NO_TASK; | 257 | shutdown_handle = NULL; |
258 | } | 258 | } |
259 | 259 | ||
260 | 260 | ||
@@ -278,7 +278,7 @@ disconnect_cadet_peers (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc | |||
278 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 278 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
279 | "disconnecting cadet service of peers, called from line %ld\n", | 279 | "disconnecting cadet service of peers, called from line %ld\n", |
280 | line); | 280 | line); |
281 | disconnect_task = GNUNET_SCHEDULER_NO_TASK; | 281 | disconnect_task = NULL; |
282 | for (i = 0; i < 2; i++) | 282 | for (i = 0; i < 2; i++) |
283 | { | 283 | { |
284 | GNUNET_TESTBED_operation_done (t_op[i]); | 284 | GNUNET_TESTBED_operation_done (t_op[i]); |
@@ -294,7 +294,7 @@ disconnect_cadet_peers (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc | |||
294 | incoming_ch = NULL; | 294 | incoming_ch = NULL; |
295 | } | 295 | } |
296 | GNUNET_CADET_TEST_cleanup (test_ctx); | 296 | GNUNET_CADET_TEST_cleanup (test_ctx); |
297 | if (GNUNET_SCHEDULER_NO_TASK != shutdown_handle) | 297 | if (NULL != shutdown_handle) |
298 | { | 298 | { |
299 | GNUNET_SCHEDULER_cancel (shutdown_handle); | 299 | GNUNET_SCHEDULER_cancel (shutdown_handle); |
300 | } | 300 | } |
@@ -310,7 +310,7 @@ disconnect_cadet_peers (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc | |||
310 | static void | 310 | static void |
311 | abort_test (long line) | 311 | abort_test (long line) |
312 | { | 312 | { |
313 | if (disconnect_task != GNUNET_SCHEDULER_NO_TASK) | 313 | if (disconnect_task != NULL) |
314 | { | 314 | { |
315 | GNUNET_SCHEDULER_cancel (disconnect_task); | 315 | GNUNET_SCHEDULER_cancel (disconnect_task); |
316 | disconnect_task = GNUNET_SCHEDULER_add_now (&disconnect_cadet_peers, | 316 | disconnect_task = GNUNET_SCHEDULER_add_now (&disconnect_cadet_peers, |
@@ -474,7 +474,7 @@ data_callback (void *cls, struct GNUNET_CADET_Channel *channel, | |||
474 | 474 | ||
475 | if ((ok % 20) == 0) | 475 | if ((ok % 20) == 0) |
476 | { | 476 | { |
477 | if (GNUNET_SCHEDULER_NO_TASK != disconnect_task) | 477 | if (NULL != disconnect_task) |
478 | { | 478 | { |
479 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, " reschedule timeout\n"); | 479 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, " reschedule timeout\n"); |
480 | GNUNET_SCHEDULER_cancel (disconnect_task); | 480 | GNUNET_SCHEDULER_cancel (disconnect_task); |
@@ -573,7 +573,7 @@ data_callback (void *cls, struct GNUNET_CADET_Channel *channel, | |||
573 | } | 573 | } |
574 | } | 574 | } |
575 | 575 | ||
576 | if (GNUNET_SCHEDULER_NO_TASK != disconnect_task) | 576 | if (NULL != disconnect_task) |
577 | { | 577 | { |
578 | GNUNET_SCHEDULER_cancel (disconnect_task); | 578 | GNUNET_SCHEDULER_cancel (disconnect_task); |
579 | disconnect_task = GNUNET_SCHEDULER_add_delayed (SHORT_TIME, | 579 | disconnect_task = GNUNET_SCHEDULER_add_delayed (SHORT_TIME, |
@@ -604,7 +604,7 @@ stats_cont (void *cls, struct GNUNET_TESTBED_Operation *op, const char *emsg) | |||
604 | ok--; | 604 | ok--; |
605 | GNUNET_TESTBED_operation_done (stats_op); | 605 | GNUNET_TESTBED_operation_done (stats_op); |
606 | 606 | ||
607 | if (GNUNET_SCHEDULER_NO_TASK != disconnect_task) | 607 | if (NULL != disconnect_task) |
608 | GNUNET_SCHEDULER_cancel (disconnect_task); | 608 | GNUNET_SCHEDULER_cancel (disconnect_task); |
609 | disconnect_task = GNUNET_SCHEDULER_add_now (&disconnect_cadet_peers, | 609 | disconnect_task = GNUNET_SCHEDULER_add_now (&disconnect_cadet_peers, |
610 | (void *) __LINE__); | 610 | (void *) __LINE__); |
@@ -657,7 +657,7 @@ check_keepalives (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
657 | if ((GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason) != 0) | 657 | if ((GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason) != 0) |
658 | return; | 658 | return; |
659 | 659 | ||
660 | disconnect_task = GNUNET_SCHEDULER_NO_TASK; | 660 | disconnect_task = NULL; |
661 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "check keepalives\n"); | 661 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "check keepalives\n"); |
662 | GNUNET_CADET_channel_destroy (ch); | 662 | GNUNET_CADET_channel_destroy (ch); |
663 | stats_op = GNUNET_TESTBED_get_statistics (peers_running, testbed_peers, | 663 | stats_op = GNUNET_TESTBED_get_statistics (peers_running, testbed_peers, |
@@ -705,7 +705,7 @@ incoming_channel (void *cls, struct GNUNET_CADET_Channel *channel, | |||
705 | "Incoming channel for unknown client %lu\n", (long) cls); | 705 | "Incoming channel for unknown client %lu\n", (long) cls); |
706 | GNUNET_break(0); | 706 | GNUNET_break(0); |
707 | } | 707 | } |
708 | if (GNUNET_SCHEDULER_NO_TASK != disconnect_task) | 708 | if (NULL != disconnect_task) |
709 | { | 709 | { |
710 | GNUNET_SCHEDULER_cancel (disconnect_task); | 710 | GNUNET_SCHEDULER_cancel (disconnect_task); |
711 | if (KEEPALIVE == test) | 711 | if (KEEPALIVE == test) |
@@ -761,7 +761,7 @@ channel_cleaner (void *cls, const struct GNUNET_CADET_Channel *channel, | |||
761 | "Unknown peer! %d\n", i); | 761 | "Unknown peer! %d\n", i); |
762 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, " ok: %d\n", ok); | 762 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, " ok: %d\n", ok); |
763 | 763 | ||
764 | if (GNUNET_SCHEDULER_NO_TASK != disconnect_task) | 764 | if (NULL != disconnect_task) |
765 | { | 765 | { |
766 | GNUNET_SCHEDULER_cancel (disconnect_task); | 766 | GNUNET_SCHEDULER_cancel (disconnect_task); |
767 | disconnect_task = GNUNET_SCHEDULER_add_now (&disconnect_cadet_peers, | 767 | disconnect_task = GNUNET_SCHEDULER_add_now (&disconnect_cadet_peers, |
@@ -791,7 +791,7 @@ do_test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
791 | 791 | ||
792 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test_task\n"); | 792 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test_task\n"); |
793 | 793 | ||
794 | if (GNUNET_SCHEDULER_NO_TASK != disconnect_task) | 794 | if (NULL != disconnect_task) |
795 | { | 795 | { |
796 | GNUNET_SCHEDULER_cancel (disconnect_task); | 796 | GNUNET_SCHEDULER_cancel (disconnect_task); |
797 | } | 797 | } |