aboutsummaryrefslogtreecommitdiff
path: root/src/transport/gnunet-transport.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2014-12-24 01:10:47 +0000
committerChristian Grothoff <christian@grothoff.org>2014-12-24 01:10:47 +0000
commitf1f603c7d0b3f03dca46a4f313472288eb080eb1 (patch)
tree3a29966b02dfb83e0a8a8d5c42b3116380209fb0 /src/transport/gnunet-transport.c
parent53cd5b8eda2fa8db86b0907a62a39598981d008a (diff)
downloadgnunet-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/transport/gnunet-transport.c')
-rw-r--r--src/transport/gnunet-transport.c70
1 files changed, 35 insertions, 35 deletions
diff --git a/src/transport/gnunet-transport.c b/src/transport/gnunet-transport.c
index cd74abde7..635213c29 100644
--- a/src/transport/gnunet-transport.c
+++ b/src/transport/gnunet-transport.c
@@ -208,7 +208,7 @@ struct TestContext
208 /** 208 /**
209 * Task identifier for the timeout. 209 * Task identifier for the timeout.
210 */ 210 */
211 GNUNET_SCHEDULER_TaskIdentifier tsk; 211 struct GNUNET_SCHEDULER_Task * tsk;
212 212
213 /** 213 /**
214 * Name of plugin under test. 214 * Name of plugin under test.
@@ -424,12 +424,12 @@ static struct GNUNET_PeerIdentity pid;
424/** 424/**
425 * Task scheduled for cleanup / termination of the process. 425 * Task scheduled for cleanup / termination of the process.
426 */ 426 */
427static GNUNET_SCHEDULER_TaskIdentifier end; 427static struct GNUNET_SCHEDULER_Task * end;
428 428
429/** 429/**
430 * Task for operation timeout 430 * Task for operation timeout
431 */ 431 */
432static GNUNET_SCHEDULER_TaskIdentifier op_timeout; 432static struct GNUNET_SCHEDULER_Task * op_timeout;
433 433
434/** 434/**
435 * Selected level of verbosity. 435 * Selected level of verbosity.
@@ -522,11 +522,11 @@ shutdown_task (void *cls,
522 struct ValidationResolutionContext *cur; 522 struct ValidationResolutionContext *cur;
523 struct ValidationResolutionContext *next; 523 struct ValidationResolutionContext *next;
524 524
525 end = GNUNET_SCHEDULER_NO_TASK; 525 end = NULL;
526 if (GNUNET_SCHEDULER_NO_TASK != op_timeout) 526 if (NULL != op_timeout)
527 { 527 {
528 GNUNET_SCHEDULER_cancel (op_timeout); 528 GNUNET_SCHEDULER_cancel (op_timeout);
529 op_timeout = GNUNET_SCHEDULER_NO_TASK; 529 op_timeout = NULL;
530 } 530 }
531 if (NULL != tc_handle) 531 if (NULL != tc_handle)
532 { 532 {
@@ -612,13 +612,13 @@ operation_timeout (void *cls,
612{ 612{
613 struct PeerResolutionContext *cur; 613 struct PeerResolutionContext *cur;
614 struct PeerResolutionContext *next; 614 struct PeerResolutionContext *next;
615 op_timeout = GNUNET_SCHEDULER_NO_TASK; 615 op_timeout = NULL;
616 if ((try_connect) || (benchmark_send) || (benchmark_receive)) 616 if ((try_connect) || (benchmark_send) || (benchmark_receive))
617 { 617 {
618 FPRINTF (stdout, 618 FPRINTF (stdout,
619 _("Failed to connect to `%s'\n"), 619 _("Failed to connect to `%s'\n"),
620 GNUNET_i2s_full (&pid)); 620 GNUNET_i2s_full (&pid));
621 if (GNUNET_SCHEDULER_NO_TASK != end) 621 if (NULL != end)
622 GNUNET_SCHEDULER_cancel (end); 622 GNUNET_SCHEDULER_cancel (end);
623 end = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL); 623 end = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
624 ret = 1; 624 ret = 1;
@@ -644,7 +644,7 @@ operation_timeout (void *cls,
644 FPRINTF (stdout, 644 FPRINTF (stdout,
645 "%s", 645 "%s",
646 _("Failed to list connections, timeout occured\n")); 646 _("Failed to list connections, timeout occured\n"));
647 if (GNUNET_SCHEDULER_NO_TASK != end) 647 if (NULL != end)
648 GNUNET_SCHEDULER_cancel (end); 648 GNUNET_SCHEDULER_cancel (end);
649 end = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL); 649 end = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
650 ret = 1; 650 ret = 1;
@@ -709,10 +709,10 @@ display_test_result (struct TestContext *tc,
709 _("Configuration for plugin `%s' is working!\n"), 709 _("Configuration for plugin `%s' is working!\n"),
710 tc->name); 710 tc->name);
711 } 711 }
712 if (GNUNET_SCHEDULER_NO_TASK != tc->tsk) 712 if (NULL != tc->tsk)
713 { 713 {
714 GNUNET_SCHEDULER_cancel (tc->tsk); 714 GNUNET_SCHEDULER_cancel (tc->tsk);
715 tc->tsk = GNUNET_SCHEDULER_NO_TASK; 715 tc->tsk = NULL;
716 } 716 }
717 if (NULL != tc->tst) 717 if (NULL != tc->tst)
718 { 718 {
@@ -873,15 +873,15 @@ process_validation_string (void *cls,
873 GNUNET_free (vc); 873 GNUNET_free (vc);
874 if ((0 == address_resolutions) && (iterate_validation)) 874 if ((0 == address_resolutions) && (iterate_validation))
875 { 875 {
876 if (GNUNET_SCHEDULER_NO_TASK != end) 876 if (NULL != end)
877 { 877 {
878 GNUNET_SCHEDULER_cancel (end); 878 GNUNET_SCHEDULER_cancel (end);
879 end = GNUNET_SCHEDULER_NO_TASK; 879 end = NULL;
880 } 880 }
881 if (GNUNET_SCHEDULER_NO_TASK != op_timeout) 881 if (NULL != op_timeout)
882 { 882 {
883 GNUNET_SCHEDULER_cancel (op_timeout); 883 GNUNET_SCHEDULER_cancel (op_timeout);
884 op_timeout = GNUNET_SCHEDULER_NO_TASK; 884 op_timeout = NULL;
885 } 885 }
886 ret = 0; 886 ret = 0;
887 end = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL); 887 end = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
@@ -966,7 +966,7 @@ process_validation_cb (void *cls,
966 966
967 /* done */ 967 /* done */
968 vic = NULL; 968 vic = NULL;
969 if (GNUNET_SCHEDULER_NO_TASK != end) 969 if (NULL != end)
970 GNUNET_SCHEDULER_cancel (end); 970 GNUNET_SCHEDULER_cancel (end);
971 end = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL); 971 end = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
972 return; 972 return;
@@ -975,7 +975,7 @@ process_validation_cb (void *cls,
975 { 975 {
976 /* invalid response */ 976 /* invalid response */
977 vic = NULL; 977 vic = NULL;
978 if (GNUNET_SCHEDULER_NO_TASK != end) 978 if (NULL != end)
979 GNUNET_SCHEDULER_cancel (end); 979 GNUNET_SCHEDULER_cancel (end);
980 end = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL); 980 end = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
981 return; 981 return;
@@ -1140,23 +1140,23 @@ notify_connect (void *cls,
1140 GNUNET_i2s_full (peer)); 1140 GNUNET_i2s_full (peer));
1141 ret = 0; 1141 ret = 0;
1142 1142
1143 if (GNUNET_SCHEDULER_NO_TASK != op_timeout) 1143 if (NULL != op_timeout)
1144 { 1144 {
1145 GNUNET_SCHEDULER_cancel (op_timeout); 1145 GNUNET_SCHEDULER_cancel (op_timeout);
1146 op_timeout = GNUNET_SCHEDULER_NO_TASK; 1146 op_timeout = NULL;
1147 } 1147 }
1148 1148
1149 if (GNUNET_SCHEDULER_NO_TASK != end) 1149 if (NULL != end)
1150 GNUNET_SCHEDULER_cancel (end); 1150 GNUNET_SCHEDULER_cancel (end);
1151 end = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL); 1151 end = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
1152 return; 1152 return;
1153 } 1153 }
1154 if (benchmark_send) 1154 if (benchmark_send)
1155 { 1155 {
1156 if (GNUNET_SCHEDULER_NO_TASK != op_timeout) 1156 if (NULL != op_timeout)
1157 { 1157 {
1158 GNUNET_SCHEDULER_cancel (op_timeout); 1158 GNUNET_SCHEDULER_cancel (op_timeout);
1159 op_timeout = GNUNET_SCHEDULER_NO_TASK; 1159 op_timeout = NULL;
1160 } 1160 }
1161 if (verbosity > 0) 1161 if (verbosity > 0)
1162 FPRINTF (stdout, 1162 FPRINTF (stdout,
@@ -1197,13 +1197,13 @@ notify_disconnect (void *cls,
1197 GNUNET_i2s_full (peer)); 1197 GNUNET_i2s_full (peer));
1198 ret = 0; 1198 ret = 0;
1199 1199
1200 if (GNUNET_SCHEDULER_NO_TASK != op_timeout) 1200 if (NULL != op_timeout)
1201 { 1201 {
1202 GNUNET_SCHEDULER_cancel (op_timeout); 1202 GNUNET_SCHEDULER_cancel (op_timeout);
1203 op_timeout = GNUNET_SCHEDULER_NO_TASK; 1203 op_timeout = NULL;
1204 } 1204 }
1205 1205
1206 if (GNUNET_SCHEDULER_NO_TASK != end) 1206 if (NULL != end)
1207 GNUNET_SCHEDULER_cancel (end); 1207 GNUNET_SCHEDULER_cancel (end);
1208 end = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL); 1208 end = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
1209 return; 1209 return;
@@ -1218,7 +1218,7 @@ notify_disconnect (void *cls,
1218 { 1218 {
1219 FPRINTF (stdout, _("Disconnected from peer `%s' while benchmarking\n"), 1219 FPRINTF (stdout, _("Disconnected from peer `%s' while benchmarking\n"),
1220 GNUNET_i2s (&pid)); 1220 GNUNET_i2s (&pid));
1221 if (GNUNET_SCHEDULER_NO_TASK != end) 1221 if (NULL != end)
1222 GNUNET_SCHEDULER_cancel (end); 1222 GNUNET_SCHEDULER_cancel (end);
1223 return; 1223 return;
1224 } 1224 }
@@ -1431,15 +1431,15 @@ process_peer_string (void *cls,
1431 GNUNET_free (rc); 1431 GNUNET_free (rc);
1432 if ((0 == address_resolutions) && (iterate_connections)) 1432 if ((0 == address_resolutions) && (iterate_connections))
1433 { 1433 {
1434 if (GNUNET_SCHEDULER_NO_TASK != end) 1434 if (NULL != end)
1435 { 1435 {
1436 GNUNET_SCHEDULER_cancel (end); 1436 GNUNET_SCHEDULER_cancel (end);
1437 end = GNUNET_SCHEDULER_NO_TASK; 1437 end = NULL;
1438 } 1438 }
1439 if (GNUNET_SCHEDULER_NO_TASK != op_timeout) 1439 if (NULL != op_timeout)
1440 { 1440 {
1441 GNUNET_SCHEDULER_cancel (op_timeout); 1441 GNUNET_SCHEDULER_cancel (op_timeout);
1442 op_timeout = GNUNET_SCHEDULER_NO_TASK; 1442 op_timeout = NULL;
1443 } 1443 }
1444 ret = 0; 1444 ret = 0;
1445 end = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL); 1445 end = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
@@ -1498,7 +1498,7 @@ process_peer_iteration_cb (void *cls,
1498 /* done */ 1498 /* done */
1499 address_resolution_in_progress = GNUNET_NO; 1499 address_resolution_in_progress = GNUNET_NO;
1500 pic = NULL; 1500 pic = NULL;
1501 if (GNUNET_SCHEDULER_NO_TASK != end) 1501 if (NULL != end)
1502 GNUNET_SCHEDULER_cancel (end); 1502 GNUNET_SCHEDULER_cancel (end);
1503 end = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL); 1503 end = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
1504 return; 1504 return;
@@ -1508,7 +1508,7 @@ process_peer_iteration_cb (void *cls,
1508 (GNUNET_NO == GNUNET_TRANSPORT_is_connected(state))) 1508 (GNUNET_NO == GNUNET_TRANSPORT_is_connected(state)))
1509 return; /* Display only connected peers */ 1509 return; /* Display only connected peers */
1510 1510
1511 if (GNUNET_SCHEDULER_NO_TASK != op_timeout) 1511 if (NULL != op_timeout)
1512 GNUNET_SCHEDULER_cancel (op_timeout); 1512 GNUNET_SCHEDULER_cancel (op_timeout);
1513 op_timeout = GNUNET_SCHEDULER_add_delayed (OP_TIMEOUT, 1513 op_timeout = GNUNET_SCHEDULER_add_delayed (OP_TIMEOUT,
1514 &operation_timeout, 1514 &operation_timeout,
@@ -1713,7 +1713,7 @@ process_peer_monitoring_cb (void *cls,
1713 return; 1713 return;
1714 } 1714 }
1715 1715
1716 if (GNUNET_SCHEDULER_NO_TASK != op_timeout) 1716 if (NULL != op_timeout)
1717 GNUNET_SCHEDULER_cancel (op_timeout); 1717 GNUNET_SCHEDULER_cancel (op_timeout);
1718 op_timeout = GNUNET_SCHEDULER_add_delayed (OP_TIMEOUT, 1718 op_timeout = GNUNET_SCHEDULER_add_delayed (OP_TIMEOUT,
1719 &operation_timeout, 1719 &operation_timeout,
@@ -1792,7 +1792,7 @@ try_connect_cb (void *cls,
1792 FPRINTF (stderr, 1792 FPRINTF (stderr,
1793 "%s", 1793 "%s",
1794 _("Failed to send connect request to transport service\n")); 1794 _("Failed to send connect request to transport service\n"));
1795 if (GNUNET_SCHEDULER_NO_TASK != end) 1795 if (NULL != end)
1796 GNUNET_SCHEDULER_cancel (end); 1796 GNUNET_SCHEDULER_cancel (end);
1797 ret = 1; 1797 ret = 1;
1798 end = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL); 1798 end = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
@@ -1827,7 +1827,7 @@ try_disconnect_cb (void *cls,
1827 } 1827 }
1828 FPRINTF (stderr, "%s", 1828 FPRINTF (stderr, "%s",
1829 _("Failed to send disconnect request to transport service\n")); 1829 _("Failed to send disconnect request to transport service\n"));
1830 if (GNUNET_SCHEDULER_NO_TASK != end) 1830 if (NULL != end)
1831 GNUNET_SCHEDULER_cancel (end); 1831 GNUNET_SCHEDULER_cancel (end);
1832 ret = 1; 1832 ret = 1;
1833 end = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL); 1833 end = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);