aboutsummaryrefslogtreecommitdiff
path: root/src/fragmentation
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/fragmentation
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/fragmentation')
-rw-r--r--src/fragmentation/defragmentation.c14
-rw-r--r--src/fragmentation/fragmentation.c14
-rw-r--r--src/fragmentation/test_fragmentation.c6
3 files changed, 17 insertions, 17 deletions
diff --git a/src/fragmentation/defragmentation.c b/src/fragmentation/defragmentation.c
index 478a9c658..e3cf2298b 100644
--- a/src/fragmentation/defragmentation.c
+++ b/src/fragmentation/defragmentation.c
@@ -83,7 +83,7 @@ struct MessageContext
83 * Task scheduled for transmitting the next ACK to the 83 * Task scheduled for transmitting the next ACK to the
84 * other peer. 84 * other peer.
85 */ 85 */
86 GNUNET_SCHEDULER_TaskIdentifier ack_task; 86 struct GNUNET_SCHEDULER_Task * ack_task;
87 87
88 /** 88 /**
89 * When did we receive which fragment? Used to calculate 89 * When did we receive which fragment? Used to calculate
@@ -236,10 +236,10 @@ GNUNET_DEFRAGMENT_context_destroy (struct GNUNET_DEFRAGMENT_Context *dc)
236 { 236 {
237 GNUNET_CONTAINER_DLL_remove (dc->head, dc->tail, mc); 237 GNUNET_CONTAINER_DLL_remove (dc->head, dc->tail, mc);
238 dc->list_size--; 238 dc->list_size--;
239 if (GNUNET_SCHEDULER_NO_TASK != mc->ack_task) 239 if (NULL != mc->ack_task)
240 { 240 {
241 GNUNET_SCHEDULER_cancel (mc->ack_task); 241 GNUNET_SCHEDULER_cancel (mc->ack_task);
242 mc->ack_task = GNUNET_SCHEDULER_NO_TASK; 242 mc->ack_task = NULL;
243 } 243 }
244 GNUNET_free (mc); 244 GNUNET_free (mc);
245 } 245 }
@@ -261,7 +261,7 @@ send_ack (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
261 struct GNUNET_DEFRAGMENT_Context *dc = mc->dc; 261 struct GNUNET_DEFRAGMENT_Context *dc = mc->dc;
262 struct FragmentAcknowledgement fa; 262 struct FragmentAcknowledgement fa;
263 263
264 mc->ack_task = GNUNET_SCHEDULER_NO_TASK; 264 mc->ack_task = NULL;
265 fa.header.size = htons (sizeof (struct FragmentAcknowledgement)); 265 fa.header.size = htons (sizeof (struct FragmentAcknowledgement));
266 fa.header.type = htons (GNUNET_MESSAGE_TYPE_FRAGMENT_ACK); 266 fa.header.type = htons (GNUNET_MESSAGE_TYPE_FRAGMENT_ACK);
267 fa.fragment_id = htonl (mc->fragment_id); 267 fa.fragment_id = htonl (mc->fragment_id);
@@ -388,10 +388,10 @@ discard_oldest_mc (struct GNUNET_DEFRAGMENT_Context *dc)
388 GNUNET_assert (NULL != old); 388 GNUNET_assert (NULL != old);
389 GNUNET_CONTAINER_DLL_remove (dc->head, dc->tail, old); 389 GNUNET_CONTAINER_DLL_remove (dc->head, dc->tail, old);
390 dc->list_size--; 390 dc->list_size--;
391 if (GNUNET_SCHEDULER_NO_TASK != old->ack_task) 391 if (NULL != old->ack_task)
392 { 392 {
393 GNUNET_SCHEDULER_cancel (old->ack_task); 393 GNUNET_SCHEDULER_cancel (old->ack_task);
394 old->ack_task = GNUNET_SCHEDULER_NO_TASK; 394 old->ack_task = NULL;
395 } 395 }
396 GNUNET_free (old); 396 GNUNET_free (old);
397} 397}
@@ -550,7 +550,7 @@ GNUNET_DEFRAGMENT_process_fragment (struct GNUNET_DEFRAGMENT_Context *dc,
550 linear sequence; ACK now! */ 550 linear sequence; ACK now! */
551 delay = GNUNET_TIME_UNIT_ZERO; 551 delay = GNUNET_TIME_UNIT_ZERO;
552 } 552 }
553 if (GNUNET_SCHEDULER_NO_TASK != mc->ack_task) 553 if (NULL != mc->ack_task)
554 GNUNET_SCHEDULER_cancel (mc->ack_task); 554 GNUNET_SCHEDULER_cancel (mc->ack_task);
555 mc->ack_task = GNUNET_SCHEDULER_add_delayed (delay, &send_ack, mc); 555 mc->ack_task = GNUNET_SCHEDULER_add_delayed (delay, &send_ack, mc);
556 if (duplicate == GNUNET_YES) 556 if (duplicate == GNUNET_YES)
diff --git a/src/fragmentation/fragmentation.c b/src/fragmentation/fragmentation.c
index bf7491815..a72bda4ce 100644
--- a/src/fragmentation/fragmentation.c
+++ b/src/fragmentation/fragmentation.c
@@ -98,7 +98,7 @@ struct GNUNET_FRAGMENT_Context
98 /** 98 /**
99 * Task performing work for the fragmenter. 99 * Task performing work for the fragmenter.
100 */ 100 */
101 GNUNET_SCHEDULER_TaskIdentifier task; 101 struct GNUNET_SCHEDULER_Task * task;
102 102
103 /** 103 /**
104 * Our fragmentation ID. (chosen at random) 104 * Our fragmentation ID. (chosen at random)
@@ -157,7 +157,7 @@ transmit_next (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
157 size_t fsize; 157 size_t fsize;
158 int wrap; 158 int wrap;
159 159
160 fc->task = GNUNET_SCHEDULER_NO_TASK; 160 fc->task = NULL;
161 GNUNET_assert (GNUNET_NO == fc->proc_busy); 161 GNUNET_assert (GNUNET_NO == fc->proc_busy);
162 if (0 == fc->acks) 162 if (0 == fc->acks)
163 return; /* all done */ 163 return; /* all done */
@@ -323,7 +323,7 @@ GNUNET_FRAGMENT_context_transmission_done (struct GNUNET_FRAGMENT_Context *fc)
323{ 323{
324 GNUNET_assert (fc->proc_busy == GNUNET_YES); 324 GNUNET_assert (fc->proc_busy == GNUNET_YES);
325 fc->proc_busy = GNUNET_NO; 325 fc->proc_busy = GNUNET_NO;
326 GNUNET_assert (fc->task == GNUNET_SCHEDULER_NO_TASK); 326 GNUNET_assert (fc->task == NULL);
327 fc->task = 327 fc->task =
328 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_absolute_get_remaining 328 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_absolute_get_remaining
329 (fc->delay_until), &transmit_next, fc); 329 (fc->delay_until), &transmit_next, fc);
@@ -415,7 +415,7 @@ GNUNET_FRAGMENT_process_ack (struct GNUNET_FRAGMENT_Context *fc,
415 if (0 != fc->acks) 415 if (0 != fc->acks)
416 { 416 {
417 /* more to transmit, do so right now (if tracker permits...) */ 417 /* more to transmit, do so right now (if tracker permits...) */
418 if (fc->task != GNUNET_SCHEDULER_NO_TASK) 418 if (fc->task != NULL)
419 { 419 {
420 /* schedule next transmission now, no point in waiting... */ 420 /* schedule next transmission now, no point in waiting... */
421 GNUNET_SCHEDULER_cancel (fc->task); 421 GNUNET_SCHEDULER_cancel (fc->task);
@@ -434,10 +434,10 @@ GNUNET_FRAGMENT_process_ack (struct GNUNET_FRAGMENT_Context *fc,
434 GNUNET_STATISTICS_update (fc->stats, 434 GNUNET_STATISTICS_update (fc->stats,
435 _("# fragmentation transmissions completed"), 1, 435 _("# fragmentation transmissions completed"), 1,
436 GNUNET_NO); 436 GNUNET_NO);
437 if (fc->task != GNUNET_SCHEDULER_NO_TASK) 437 if (fc->task != NULL)
438 { 438 {
439 GNUNET_SCHEDULER_cancel (fc->task); 439 GNUNET_SCHEDULER_cancel (fc->task);
440 fc->task = GNUNET_SCHEDULER_NO_TASK; 440 fc->task = NULL;
441 } 441 }
442 return GNUNET_OK; 442 return GNUNET_OK;
443} 443}
@@ -458,7 +458,7 @@ GNUNET_FRAGMENT_context_destroy (struct GNUNET_FRAGMENT_Context *fc,
458 struct GNUNET_TIME_Relative *msg_delay, 458 struct GNUNET_TIME_Relative *msg_delay,
459 struct GNUNET_TIME_Relative *ack_delay) 459 struct GNUNET_TIME_Relative *ack_delay)
460{ 460{
461 if (fc->task != GNUNET_SCHEDULER_NO_TASK) 461 if (fc->task != NULL)
462 GNUNET_SCHEDULER_cancel (fc->task); 462 GNUNET_SCHEDULER_cancel (fc->task);
463 if (NULL != ack_delay) 463 if (NULL != ack_delay)
464 *ack_delay = fc->ack_delay; 464 *ack_delay = fc->ack_delay;
diff --git a/src/fragmentation/test_fragmentation.c b/src/fragmentation/test_fragmentation.c
index 5f102f439..50779c98b 100644
--- a/src/fragmentation/test_fragmentation.c
+++ b/src/fragmentation/test_fragmentation.c
@@ -60,7 +60,7 @@ static struct GNUNET_BANDWIDTH_Tracker trackers[NUM_MSGS];
60 60
61static struct GNUNET_FRAGMENT_Context *frags[NUM_MSGS]; 61static struct GNUNET_FRAGMENT_Context *frags[NUM_MSGS];
62 62
63static GNUNET_SCHEDULER_TaskIdentifier shutdown_task; 63static struct GNUNET_SCHEDULER_Task * shutdown_task;
64 64
65static void 65static void
66do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 66do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
@@ -68,7 +68,7 @@ do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
68 unsigned int i; 68 unsigned int i;
69 69
70 ret = 0; 70 ret = 0;
71 shutdown_task = GNUNET_SCHEDULER_NO_TASK; 71 shutdown_task = NULL;
72 GNUNET_DEFRAGMENT_context_destroy (defrag); 72 GNUNET_DEFRAGMENT_context_destroy (defrag);
73 defrag = NULL; 73 defrag = NULL;
74 for (i = 0; i < NUM_MSGS; i++) 74 for (i = 0; i < NUM_MSGS; i++)
@@ -102,7 +102,7 @@ proc_msgs (void *cls, const struct GNUNET_MessageHeader *hdr)
102 /* tolerate 10% loss, i.e. due to duplicate fragment IDs */ 102 /* tolerate 10% loss, i.e. due to duplicate fragment IDs */
103 if ((total >= NUM_MSGS - (NUM_MSGS / 10)) && (ret != 0)) 103 if ((total >= NUM_MSGS - (NUM_MSGS / 10)) && (ret != 0))
104 { 104 {
105 if (GNUNET_SCHEDULER_NO_TASK == shutdown_task) 105 if (NULL == shutdown_task)
106 shutdown_task = GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); 106 shutdown_task = GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
107 } 107 }
108} 108}