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/transport/transport_api.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/transport/transport_api.c')
-rw-r--r-- | src/transport/transport_api.c | 54 |
1 files changed, 27 insertions, 27 deletions
diff --git a/src/transport/transport_api.c b/src/transport/transport_api.c index 7fa035c06..fd352a1e5 100644 --- a/src/transport/transport_api.c +++ b/src/transport/transport_api.c | |||
@@ -84,7 +84,7 @@ struct GNUNET_TRANSPORT_TransmitHandle | |||
84 | * Task to trigger request timeout if the request is stalled due to | 84 | * Task to trigger request timeout if the request is stalled due to |
85 | * congestion. | 85 | * congestion. |
86 | */ | 86 | */ |
87 | GNUNET_SCHEDULER_TaskIdentifier timeout_task; | 87 | struct GNUNET_SCHEDULER_Task * timeout_task; |
88 | 88 | ||
89 | /** | 89 | /** |
90 | * How many bytes is our notify callback waiting for? | 90 | * How many bytes is our notify callback waiting for? |
@@ -171,7 +171,7 @@ struct GNUNET_TRANSPORT_GetHelloHandle | |||
171 | /** | 171 | /** |
172 | * Task for calling the HelloUpdateCallback when we already have a HELLO | 172 | * Task for calling the HelloUpdateCallback when we already have a HELLO |
173 | */ | 173 | */ |
174 | GNUNET_SCHEDULER_TaskIdentifier notify_task; | 174 | struct GNUNET_SCHEDULER_Task * notify_task; |
175 | 175 | ||
176 | /** | 176 | /** |
177 | * Closure for @e rec. | 177 | * Closure for @e rec. |
@@ -295,7 +295,7 @@ struct GNUNET_TRANSPORT_OfferHelloHandle | |||
295 | /** | 295 | /** |
296 | * Function to call once we are done. | 296 | * Function to call once we are done. |
297 | */ | 297 | */ |
298 | GNUNET_SCHEDULER_Task cont; | 298 | GNUNET_SCHEDULER_TaskCallback cont; |
299 | 299 | ||
300 | /** | 300 | /** |
301 | * Closure for @e cont | 301 | * Closure for @e cont |
@@ -434,7 +434,7 @@ struct GNUNET_TRANSPORT_Handle | |||
434 | /** | 434 | /** |
435 | * ID of the task trying to reconnect to the service. | 435 | * ID of the task trying to reconnect to the service. |
436 | */ | 436 | */ |
437 | GNUNET_SCHEDULER_TaskIdentifier reconnect_task; | 437 | struct GNUNET_SCHEDULER_Task * reconnect_task; |
438 | 438 | ||
439 | /** | 439 | /** |
440 | * ID of the task trying to trigger transmission for a peer while | 440 | * ID of the task trying to trigger transmission for a peer while |
@@ -442,7 +442,7 @@ struct GNUNET_TRANSPORT_Handle | |||
442 | * messages and the smallest entry in the 'ready_heap' has a time | 442 | * messages and the smallest entry in the 'ready_heap' has a time |
443 | * stamp in the future. | 443 | * stamp in the future. |
444 | */ | 444 | */ |
445 | GNUNET_SCHEDULER_TaskIdentifier quota_task; | 445 | struct GNUNET_SCHEDULER_Task * quota_task; |
446 | 446 | ||
447 | /** | 447 | /** |
448 | * Delay until we try to reconnect. | 448 | * Delay until we try to reconnect. |
@@ -754,9 +754,9 @@ demultiplexer (void *cls, | |||
754 | n->is_ready = GNUNET_YES; | 754 | n->is_ready = GNUNET_YES; |
755 | if ((NULL != n->th) && (NULL == n->hn)) | 755 | if ((NULL != n->th) && (NULL == n->hn)) |
756 | { | 756 | { |
757 | GNUNET_assert (GNUNET_SCHEDULER_NO_TASK != n->th->timeout_task); | 757 | GNUNET_assert (NULL != n->th->timeout_task); |
758 | GNUNET_SCHEDULER_cancel (n->th->timeout_task); | 758 | GNUNET_SCHEDULER_cancel (n->th->timeout_task); |
759 | n->th->timeout_task = GNUNET_SCHEDULER_NO_TASK; | 759 | n->th->timeout_task = NULL; |
760 | /* we've been waiting for this (congestion, not quota, | 760 | /* we've been waiting for this (congestion, not quota, |
761 | * caused delayed transmission) */ | 761 | * caused delayed transmission) */ |
762 | n->hn = GNUNET_CONTAINER_heap_insert (h->ready_heap, n, 0); | 762 | n->hn = GNUNET_CONTAINER_heap_insert (h->ready_heap, n, 0); |
@@ -835,7 +835,7 @@ timeout_request_due_to_congestion (void *cls, | |||
835 | struct GNUNET_TRANSPORT_TransmitHandle *th = cls; | 835 | struct GNUNET_TRANSPORT_TransmitHandle *th = cls; |
836 | struct Neighbour *n = th->neighbour; | 836 | struct Neighbour *n = th->neighbour; |
837 | 837 | ||
838 | n->th->timeout_task = GNUNET_SCHEDULER_NO_TASK; | 838 | n->th->timeout_task = NULL; |
839 | GNUNET_assert (th == n->th); | 839 | GNUNET_assert (th == n->th); |
840 | GNUNET_assert (NULL == n->hn); | 840 | GNUNET_assert (NULL == n->hn); |
841 | n->th = NULL; | 841 | n->th = NULL; |
@@ -897,7 +897,7 @@ transport_notify_ready (void *cls, size_t size, void *buf) | |||
897 | /* peer not ready, wait for notification! */ | 897 | /* peer not ready, wait for notification! */ |
898 | GNUNET_assert (n == GNUNET_CONTAINER_heap_remove_root (h->ready_heap)); | 898 | GNUNET_assert (n == GNUNET_CONTAINER_heap_remove_root (h->ready_heap)); |
899 | n->hn = NULL; | 899 | n->hn = NULL; |
900 | GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == n->th->timeout_task); | 900 | GNUNET_assert (NULL == n->th->timeout_task); |
901 | n->th->timeout_task = | 901 | n->th->timeout_task = |
902 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_absolute_get_remaining | 902 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_absolute_get_remaining |
903 | (n->th->timeout), | 903 | (n->th->timeout), |
@@ -963,7 +963,7 @@ schedule_transmission_task (void *cls, | |||
963 | struct GNUNET_TRANSPORT_TransmitHandle *th; | 963 | struct GNUNET_TRANSPORT_TransmitHandle *th; |
964 | struct Neighbour *n; | 964 | struct Neighbour *n; |
965 | 965 | ||
966 | h->quota_task = GNUNET_SCHEDULER_NO_TASK; | 966 | h->quota_task = NULL; |
967 | GNUNET_assert (NULL != h->client); | 967 | GNUNET_assert (NULL != h->client); |
968 | /* destroy all requests that have timed out */ | 968 | /* destroy all requests that have timed out */ |
969 | while ((NULL != (n = GNUNET_CONTAINER_heap_peek (h->ready_heap))) && | 969 | while ((NULL != (n = GNUNET_CONTAINER_heap_peek (h->ready_heap))) && |
@@ -1018,10 +1018,10 @@ schedule_transmission (struct GNUNET_TRANSPORT_Handle *h) | |||
1018 | struct Neighbour *n; | 1018 | struct Neighbour *n; |
1019 | 1019 | ||
1020 | GNUNET_assert (NULL != h->client); | 1020 | GNUNET_assert (NULL != h->client); |
1021 | if (h->quota_task != GNUNET_SCHEDULER_NO_TASK) | 1021 | if (h->quota_task != NULL) |
1022 | { | 1022 | { |
1023 | GNUNET_SCHEDULER_cancel (h->quota_task); | 1023 | GNUNET_SCHEDULER_cancel (h->quota_task); |
1024 | h->quota_task = GNUNET_SCHEDULER_NO_TASK; | 1024 | h->quota_task = NULL; |
1025 | } | 1025 | } |
1026 | if (NULL != h->control_head) | 1026 | if (NULL != h->control_head) |
1027 | delay = GNUNET_TIME_UNIT_ZERO; | 1027 | delay = GNUNET_TIME_UNIT_ZERO; |
@@ -1127,7 +1127,7 @@ reconnect (void *cls, | |||
1127 | { | 1127 | { |
1128 | struct GNUNET_TRANSPORT_Handle *h = cls; | 1128 | struct GNUNET_TRANSPORT_Handle *h = cls; |
1129 | 1129 | ||
1130 | h->reconnect_task = GNUNET_SCHEDULER_NO_TASK; | 1130 | h->reconnect_task = NULL; |
1131 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) | 1131 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) |
1132 | { | 1132 | { |
1133 | /* shutdown, just give up */ | 1133 | /* shutdown, just give up */ |
@@ -1158,7 +1158,7 @@ disconnect_and_schedule_reconnect (struct GNUNET_TRANSPORT_Handle *h) | |||
1158 | { | 1158 | { |
1159 | struct GNUNET_TRANSPORT_TransmitHandle *th; | 1159 | struct GNUNET_TRANSPORT_TransmitHandle *th; |
1160 | 1160 | ||
1161 | GNUNET_assert (h->reconnect_task == GNUNET_SCHEDULER_NO_TASK); | 1161 | GNUNET_assert (h->reconnect_task == NULL); |
1162 | if (NULL != h->cth) | 1162 | if (NULL != h->cth) |
1163 | { | 1163 | { |
1164 | GNUNET_CLIENT_notify_transmit_ready_cancel (h->cth); | 1164 | GNUNET_CLIENT_notify_transmit_ready_cancel (h->cth); |
@@ -1174,10 +1174,10 @@ disconnect_and_schedule_reconnect (struct GNUNET_TRANSPORT_Handle *h) | |||
1174 | /* Forget about all neighbours that we used to be connected to */ | 1174 | /* Forget about all neighbours that we used to be connected to */ |
1175 | GNUNET_CONTAINER_multipeermap_iterate (h->neighbours, | 1175 | GNUNET_CONTAINER_multipeermap_iterate (h->neighbours, |
1176 | &neighbour_delete, h); | 1176 | &neighbour_delete, h); |
1177 | if (h->quota_task != GNUNET_SCHEDULER_NO_TASK) | 1177 | if (h->quota_task != NULL) |
1178 | { | 1178 | { |
1179 | GNUNET_SCHEDULER_cancel (h->quota_task); | 1179 | GNUNET_SCHEDULER_cancel (h->quota_task); |
1180 | h->quota_task = GNUNET_SCHEDULER_NO_TASK; | 1180 | h->quota_task = NULL; |
1181 | } | 1181 | } |
1182 | while ((NULL != (th = h->control_head))) | 1182 | while ((NULL != (th = h->control_head))) |
1183 | { | 1183 | { |
@@ -1577,7 +1577,7 @@ GNUNET_TRANSPORT_set_traffic_metric (struct GNUNET_TRANSPORT_Handle *handle, | |||
1577 | struct GNUNET_TRANSPORT_OfferHelloHandle * | 1577 | struct GNUNET_TRANSPORT_OfferHelloHandle * |
1578 | GNUNET_TRANSPORT_offer_hello (struct GNUNET_TRANSPORT_Handle *handle, | 1578 | GNUNET_TRANSPORT_offer_hello (struct GNUNET_TRANSPORT_Handle *handle, |
1579 | const struct GNUNET_MessageHeader *hello, | 1579 | const struct GNUNET_MessageHeader *hello, |
1580 | GNUNET_SCHEDULER_Task cont, void *cls) | 1580 | GNUNET_SCHEDULER_TaskCallback cont, void *cls) |
1581 | { | 1581 | { |
1582 | struct GNUNET_TRANSPORT_OfferHelloHandle *ohh; | 1582 | struct GNUNET_TRANSPORT_OfferHelloHandle *ohh; |
1583 | struct GNUNET_MessageHeader *msg; | 1583 | struct GNUNET_MessageHeader *msg; |
@@ -1663,8 +1663,8 @@ call_hello_update_cb_async (void *cls, | |||
1663 | struct GNUNET_TRANSPORT_GetHelloHandle *ghh = cls; | 1663 | struct GNUNET_TRANSPORT_GetHelloHandle *ghh = cls; |
1664 | 1664 | ||
1665 | GNUNET_assert (NULL != ghh->handle->my_hello); | 1665 | GNUNET_assert (NULL != ghh->handle->my_hello); |
1666 | GNUNET_assert (GNUNET_SCHEDULER_NO_TASK != ghh->notify_task); | 1666 | GNUNET_assert (NULL != ghh->notify_task); |
1667 | ghh->notify_task = GNUNET_SCHEDULER_NO_TASK; | 1667 | ghh->notify_task = NULL; |
1668 | ghh->rec (ghh->rec_cls, | 1668 | ghh->rec (ghh->rec_cls, |
1669 | (const struct GNUNET_MessageHeader *) ghh->handle->my_hello); | 1669 | (const struct GNUNET_MessageHeader *) ghh->handle->my_hello); |
1670 | } | 1670 | } |
@@ -1711,7 +1711,7 @@ GNUNET_TRANSPORT_get_hello_cancel (struct GNUNET_TRANSPORT_GetHelloHandle *ghh) | |||
1711 | { | 1711 | { |
1712 | struct GNUNET_TRANSPORT_Handle *handle = ghh->handle; | 1712 | struct GNUNET_TRANSPORT_Handle *handle = ghh->handle; |
1713 | 1713 | ||
1714 | if (GNUNET_SCHEDULER_NO_TASK != ghh->notify_task) | 1714 | if (NULL != ghh->notify_task) |
1715 | GNUNET_SCHEDULER_cancel (ghh->notify_task); | 1715 | GNUNET_SCHEDULER_cancel (ghh->notify_task); |
1716 | GNUNET_CONTAINER_DLL_remove (handle->hwl_head, handle->hwl_tail, ghh); | 1716 | GNUNET_CONTAINER_DLL_remove (handle->hwl_head, handle->hwl_tail, ghh); |
1717 | GNUNET_free (ghh); | 1717 | GNUNET_free (ghh); |
@@ -1810,20 +1810,20 @@ GNUNET_TRANSPORT_disconnect (struct GNUNET_TRANSPORT_Handle *handle) | |||
1810 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1810 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1811 | "Transport disconnect called!\n"); | 1811 | "Transport disconnect called!\n"); |
1812 | /* this disconnects all neighbours... */ | 1812 | /* this disconnects all neighbours... */ |
1813 | if (handle->reconnect_task == GNUNET_SCHEDULER_NO_TASK) | 1813 | if (handle->reconnect_task == NULL) |
1814 | disconnect_and_schedule_reconnect (handle); | 1814 | disconnect_and_schedule_reconnect (handle); |
1815 | /* and now we stop trying to connect again... */ | 1815 | /* and now we stop trying to connect again... */ |
1816 | if (handle->reconnect_task != GNUNET_SCHEDULER_NO_TASK) | 1816 | if (handle->reconnect_task != NULL) |
1817 | { | 1817 | { |
1818 | GNUNET_SCHEDULER_cancel (handle->reconnect_task); | 1818 | GNUNET_SCHEDULER_cancel (handle->reconnect_task); |
1819 | handle->reconnect_task = GNUNET_SCHEDULER_NO_TASK; | 1819 | handle->reconnect_task = NULL; |
1820 | } | 1820 | } |
1821 | GNUNET_CONTAINER_multipeermap_destroy (handle->neighbours); | 1821 | GNUNET_CONTAINER_multipeermap_destroy (handle->neighbours); |
1822 | handle->neighbours = NULL; | 1822 | handle->neighbours = NULL; |
1823 | if (handle->quota_task != GNUNET_SCHEDULER_NO_TASK) | 1823 | if (handle->quota_task != NULL) |
1824 | { | 1824 | { |
1825 | GNUNET_SCHEDULER_cancel (handle->quota_task); | 1825 | GNUNET_SCHEDULER_cancel (handle->quota_task); |
1826 | handle->quota_task = GNUNET_SCHEDULER_NO_TASK; | 1826 | handle->quota_task = NULL; |
1827 | } | 1827 | } |
1828 | GNUNET_free_non_null (handle->my_hello); | 1828 | GNUNET_free_non_null (handle->my_hello); |
1829 | handle->my_hello = NULL; | 1829 | handle->my_hello = NULL; |
@@ -1926,9 +1926,9 @@ GNUNET_TRANSPORT_notify_transmit_ready_cancel (struct GNUNET_TRANSPORT_TransmitH | |||
1926 | } | 1926 | } |
1927 | else | 1927 | else |
1928 | { | 1928 | { |
1929 | GNUNET_assert (GNUNET_SCHEDULER_NO_TASK != th->timeout_task); | 1929 | GNUNET_assert (NULL != th->timeout_task); |
1930 | GNUNET_SCHEDULER_cancel (th->timeout_task); | 1930 | GNUNET_SCHEDULER_cancel (th->timeout_task); |
1931 | th->timeout_task = GNUNET_SCHEDULER_NO_TASK; | 1931 | th->timeout_task = NULL; |
1932 | } | 1932 | } |
1933 | GNUNET_free (th); | 1933 | GNUNET_free (th); |
1934 | } | 1934 | } |