diff options
author | Christian Grothoff <christian@grothoff.org> | 2009-10-25 10:57:43 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2009-10-25 10:57:43 +0000 |
commit | 42dbd0d48e6bd38d58c7d58d523f5f71efed22a0 (patch) | |
tree | 55113c83d4002cfd8a044ac736d579ad2bc85118 /src/statistics | |
parent | f4dfb3bfeadf3ce0788fef942804fe4f25e7fc99 (diff) | |
download | gnunet-42dbd0d48e6bd38d58c7d58d523f5f71efed22a0.tar.gz gnunet-42dbd0d48e6bd38d58c7d58d523f5f71efed22a0.zip |
make sure stats that are being set can be committed on destroy
Diffstat (limited to 'src/statistics')
-rw-r--r-- | src/statistics/gnunet-statistics.c | 5 | ||||
-rw-r--r-- | src/statistics/statistics_api.c | 221 | ||||
-rw-r--r-- | src/statistics/test_statistics_api.c | 2 |
3 files changed, 155 insertions, 73 deletions
diff --git a/src/statistics/gnunet-statistics.c b/src/statistics/gnunet-statistics.c index dd9850418..f51452699 100644 --- a/src/statistics/gnunet-statistics.c +++ b/src/statistics/gnunet-statistics.c | |||
@@ -91,7 +91,8 @@ cleanup (void *cls, int success) | |||
91 | if (success != GNUNET_OK) | 91 | if (success != GNUNET_OK) |
92 | ret = 1; | 92 | ret = 1; |
93 | if (h != NULL) | 93 | if (h != NULL) |
94 | GNUNET_STATISTICS_destroy (h); | 94 | GNUNET_STATISTICS_destroy (h, |
95 | GNUNET_NO); | ||
95 | } | 96 | } |
96 | 97 | ||
97 | 98 | ||
@@ -130,7 +131,7 @@ run (void *cls, | |||
130 | return; | 131 | return; |
131 | } | 132 | } |
132 | GNUNET_STATISTICS_set (h, name, (uint64_t) val, persistent); | 133 | GNUNET_STATISTICS_set (h, name, (uint64_t) val, persistent); |
133 | GNUNET_STATISTICS_destroy (h); | 134 | GNUNET_STATISTICS_destroy (h, GNUNET_YES); |
134 | return; | 135 | return; |
135 | } | 136 | } |
136 | h = GNUNET_STATISTICS_create (sched, "gnunet-statistics", cfg); | 137 | h = GNUNET_STATISTICS_create (sched, "gnunet-statistics", cfg); |
diff --git a/src/statistics/statistics_api.c b/src/statistics/statistics_api.c index 49709cc72..9606d20d1 100644 --- a/src/statistics/statistics_api.c +++ b/src/statistics/statistics_api.c | |||
@@ -161,6 +161,11 @@ struct GNUNET_STATISTICS_Handle | |||
161 | */ | 161 | */ |
162 | struct ActionItem *current; | 162 | struct ActionItem *current; |
163 | 163 | ||
164 | /** | ||
165 | * Should this handle auto-destruct once all actions have | ||
166 | * been processed? | ||
167 | */ | ||
168 | int do_destroy; | ||
164 | 169 | ||
165 | }; | 170 | }; |
166 | 171 | ||
@@ -198,60 +203,27 @@ free_action_item (struct ActionItem *ai) | |||
198 | } | 203 | } |
199 | 204 | ||
200 | 205 | ||
206 | |||
207 | |||
208 | |||
201 | /** | 209 | /** |
202 | * Get handle for the statistics service. | 210 | * Schedule the next action to be performed. |
203 | * | ||
204 | * @param sched scheduler to use | ||
205 | * @param subsystem name of subsystem using the service | ||
206 | * @param cfg services configuration in use | ||
207 | * @return handle to use | ||
208 | */ | 211 | */ |
209 | struct GNUNET_STATISTICS_Handle * | 212 | static void schedule_action (struct GNUNET_STATISTICS_Handle *h); |
210 | GNUNET_STATISTICS_create (struct GNUNET_SCHEDULER_Handle *sched, | ||
211 | const char *subsystem, | ||
212 | const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
213 | { | ||
214 | struct GNUNET_STATISTICS_Handle *ret; | ||
215 | |||
216 | GNUNET_assert (subsystem != NULL); | ||
217 | GNUNET_assert (sched != NULL); | ||
218 | GNUNET_assert (cfg != NULL); | ||
219 | ret = GNUNET_malloc (sizeof (struct GNUNET_STATISTICS_Handle)); | ||
220 | ret->sched = sched; | ||
221 | ret->cfg = cfg; | ||
222 | ret->subsystem = GNUNET_strdup (subsystem); | ||
223 | try_connect (ret); | ||
224 | return ret; | ||
225 | } | ||
226 | 213 | ||
227 | 214 | ||
228 | /** | 215 | /** |
229 | * Destroy a handle (free all state associated with | 216 | * GET processing is complete, tell client about it. |
230 | * it). | ||
231 | */ | 217 | */ |
232 | void | 218 | static void |
233 | GNUNET_STATISTICS_destroy (struct GNUNET_STATISTICS_Handle *h) | 219 | finish (struct GNUNET_STATISTICS_Handle *h, int code) |
234 | { | 220 | { |
235 | struct ActionItem *pos; | 221 | struct ActionItem *pos = h->current; |
236 | if (NULL != h->th) | 222 | h->current = NULL; |
237 | { | 223 | schedule_action (h); |
238 | GNUNET_CLIENT_notify_transmit_ready_cancel (h->th); | 224 | if (pos->cont != NULL) |
239 | h->th = NULL; | 225 | pos->cont (pos->cls, code); |
240 | } | 226 | free_action_item (pos); |
241 | if (h->current != NULL) | ||
242 | free_action_item (h->current); | ||
243 | while (NULL != (pos = h->action_head)) | ||
244 | { | ||
245 | h->action_head = pos->next; | ||
246 | free_action_item (pos); | ||
247 | } | ||
248 | if (h->client != NULL) | ||
249 | { | ||
250 | GNUNET_CLIENT_disconnect (h->client); | ||
251 | h->client = NULL; | ||
252 | } | ||
253 | GNUNET_free (h->subsystem); | ||
254 | GNUNET_free (h); | ||
255 | } | 227 | } |
256 | 228 | ||
257 | 229 | ||
@@ -308,28 +280,6 @@ process_message (struct GNUNET_STATISTICS_Handle *h, | |||
308 | } | 280 | } |
309 | 281 | ||
310 | 282 | ||
311 | |||
312 | /** | ||
313 | * Schedule the next action to be performed. | ||
314 | */ | ||
315 | static void schedule_action (struct GNUNET_STATISTICS_Handle *h); | ||
316 | |||
317 | |||
318 | /** | ||
319 | * GET processing is complete, tell client about it. | ||
320 | */ | ||
321 | static void | ||
322 | finish (struct GNUNET_STATISTICS_Handle *h, int code) | ||
323 | { | ||
324 | struct ActionItem *pos = h->current; | ||
325 | h->current = NULL; | ||
326 | schedule_action (h); | ||
327 | if (pos->cont != NULL) | ||
328 | pos->cont (pos->cls, code); | ||
329 | free_action_item (pos); | ||
330 | } | ||
331 | |||
332 | |||
333 | /** | 283 | /** |
334 | * Function called with messages from stats service. | 284 | * Function called with messages from stats service. |
335 | * | 285 | * |
@@ -507,6 +457,127 @@ transmit_action (void *cls, size_t size, void *buf) | |||
507 | 457 | ||
508 | 458 | ||
509 | /** | 459 | /** |
460 | * Get handle for the statistics service. | ||
461 | * | ||
462 | * @param sched scheduler to use | ||
463 | * @param subsystem name of subsystem using the service | ||
464 | * @param cfg services configuration in use | ||
465 | * @return handle to use | ||
466 | */ | ||
467 | struct GNUNET_STATISTICS_Handle * | ||
468 | GNUNET_STATISTICS_create (struct GNUNET_SCHEDULER_Handle *sched, | ||
469 | const char *subsystem, | ||
470 | const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
471 | { | ||
472 | struct GNUNET_STATISTICS_Handle *ret; | ||
473 | |||
474 | GNUNET_assert (subsystem != NULL); | ||
475 | GNUNET_assert (sched != NULL); | ||
476 | GNUNET_assert (cfg != NULL); | ||
477 | ret = GNUNET_malloc (sizeof (struct GNUNET_STATISTICS_Handle)); | ||
478 | ret->sched = sched; | ||
479 | ret->cfg = cfg; | ||
480 | ret->subsystem = GNUNET_strdup (subsystem); | ||
481 | try_connect (ret); | ||
482 | return ret; | ||
483 | } | ||
484 | |||
485 | |||
486 | /** | ||
487 | * Destroy a handle (free all state associated with | ||
488 | * it). | ||
489 | * | ||
490 | * @param h statistics handle to destroy | ||
491 | * @param sync_first set to GNUNET_YES if pending SET requests should | ||
492 | * be completed | ||
493 | */ | ||
494 | void | ||
495 | GNUNET_STATISTICS_destroy (struct GNUNET_STATISTICS_Handle *h, | ||
496 | int sync_first) | ||
497 | { | ||
498 | struct ActionItem *pos; | ||
499 | struct ActionItem *next; | ||
500 | struct ActionItem *prev; | ||
501 | struct GNUNET_TIME_Relative timeout; | ||
502 | |||
503 | if (sync_first) | ||
504 | { | ||
505 | if (h->current != NULL) | ||
506 | { | ||
507 | if (h->current->type == ACTION_GET) | ||
508 | { | ||
509 | GNUNET_CLIENT_notify_transmit_ready_cancel (h->th); | ||
510 | h->th = NULL; | ||
511 | } | ||
512 | } | ||
513 | pos = h->action_head; | ||
514 | prev = NULL; | ||
515 | while (pos != NULL) | ||
516 | { | ||
517 | next = pos->next; | ||
518 | if (pos->type == ACTION_GET) | ||
519 | { | ||
520 | if (prev == NULL) | ||
521 | h->action_head = next; | ||
522 | else | ||
523 | prev->next = next; | ||
524 | free_action_item (pos); | ||
525 | } | ||
526 | else | ||
527 | { | ||
528 | prev = pos; | ||
529 | } | ||
530 | pos = next; | ||
531 | } | ||
532 | h->action_tail = prev; | ||
533 | if (h->current == NULL) | ||
534 | { | ||
535 | h->current = h->action_head; | ||
536 | if (h->action_head != NULL) | ||
537 | { | ||
538 | h->action_head = h->action_head->next; | ||
539 | if (h->action_head == NULL) | ||
540 | h->action_tail = NULL; | ||
541 | } | ||
542 | } | ||
543 | if ( (h->current != NULL) && | ||
544 | (h->th == NULL) ) | ||
545 | { | ||
546 | timeout = GNUNET_TIME_absolute_get_remaining (h->current->timeout); | ||
547 | h->th = GNUNET_CLIENT_notify_transmit_ready (h->client, | ||
548 | h->current->msize, | ||
549 | timeout, | ||
550 | GNUNET_YES, | ||
551 | &transmit_action, h); | ||
552 | GNUNET_assert (NULL != h->th); | ||
553 | } | ||
554 | h->do_destroy = GNUNET_YES; | ||
555 | return; | ||
556 | } | ||
557 | if (NULL != h->th) | ||
558 | { | ||
559 | GNUNET_CLIENT_notify_transmit_ready_cancel (h->th); | ||
560 | h->th = NULL; | ||
561 | } | ||
562 | if (h->current != NULL) | ||
563 | free_action_item (h->current); | ||
564 | while (NULL != (pos = h->action_head)) | ||
565 | { | ||
566 | h->action_head = pos->next; | ||
567 | free_action_item (pos); | ||
568 | } | ||
569 | if (h->client != NULL) | ||
570 | { | ||
571 | GNUNET_CLIENT_disconnect (h->client); | ||
572 | h->client = NULL; | ||
573 | } | ||
574 | GNUNET_free (h->subsystem); | ||
575 | GNUNET_free (h); | ||
576 | } | ||
577 | |||
578 | |||
579 | |||
580 | /** | ||
510 | * Schedule the next action to be performed. | 581 | * Schedule the next action to be performed. |
511 | */ | 582 | */ |
512 | static void | 583 | static void |
@@ -525,7 +596,14 @@ schedule_action (struct GNUNET_STATISTICS_Handle *h) | |||
525 | /* schedule next action */ | 596 | /* schedule next action */ |
526 | h->current = h->action_head; | 597 | h->current = h->action_head; |
527 | if (NULL == h->current) | 598 | if (NULL == h->current) |
528 | return; | 599 | { |
600 | if (h->do_destroy) | ||
601 | { | ||
602 | h->do_destroy = GNUNET_NO; | ||
603 | GNUNET_STATISTICS_destroy (h, GNUNET_YES); | ||
604 | } | ||
605 | return; | ||
606 | } | ||
529 | h->action_head = h->action_head->next; | 607 | h->action_head = h->action_head->next; |
530 | if (NULL == h->action_head) | 608 | if (NULL == h->action_head) |
531 | h->action_tail = NULL; | 609 | h->action_tail = NULL; |
@@ -590,6 +668,7 @@ GNUNET_STATISTICS_get (struct GNUNET_STATISTICS_Handle *handle, | |||
590 | 668 | ||
591 | GNUNET_assert (handle != NULL); | 669 | GNUNET_assert (handle != NULL); |
592 | GNUNET_assert (proc != NULL); | 670 | GNUNET_assert (proc != NULL); |
671 | GNUNET_assert (GNUNET_NO == handle->do_destroy); | ||
593 | if (GNUNET_YES != try_connect (handle)) | 672 | if (GNUNET_YES != try_connect (handle)) |
594 | { | 673 | { |
595 | #if DEBUG_STATISTICS | 674 | #if DEBUG_STATISTICS |
@@ -673,6 +752,7 @@ GNUNET_STATISTICS_set (struct GNUNET_STATISTICS_Handle *handle, | |||
673 | const char *name, | 752 | const char *name, |
674 | uint64_t value, int make_persistent) | 753 | uint64_t value, int make_persistent) |
675 | { | 754 | { |
755 | GNUNET_assert (GNUNET_NO == handle->do_destroy); | ||
676 | add_setter_action (handle, name, make_persistent, value, ACTION_SET); | 756 | add_setter_action (handle, name, make_persistent, value, ACTION_SET); |
677 | } | 757 | } |
678 | 758 | ||
@@ -691,6 +771,7 @@ GNUNET_STATISTICS_update (struct GNUNET_STATISTICS_Handle *handle, | |||
691 | const char *name, | 771 | const char *name, |
692 | int64_t delta, int make_persistent) | 772 | int64_t delta, int make_persistent) |
693 | { | 773 | { |
774 | GNUNET_assert (GNUNET_NO == handle->do_destroy); | ||
694 | add_setter_action (handle, name, make_persistent, | 775 | add_setter_action (handle, name, make_persistent, |
695 | (unsigned long long) delta, ACTION_UPDATE); | 776 | (unsigned long long) delta, ACTION_UPDATE); |
696 | } | 777 | } |
diff --git a/src/statistics/test_statistics_api.c b/src/statistics/test_statistics_api.c index 97e2f59c7..a03a8c3ed 100644 --- a/src/statistics/test_statistics_api.c +++ b/src/statistics/test_statistics_api.c | |||
@@ -74,7 +74,7 @@ next_fin (void *cls, int success) | |||
74 | { | 74 | { |
75 | int *ok = cls; | 75 | int *ok = cls; |
76 | 76 | ||
77 | GNUNET_STATISTICS_destroy (h); | 77 | GNUNET_STATISTICS_destroy (h, GNUNET_NO); |
78 | GNUNET_assert (success == GNUNET_OK); | 78 | GNUNET_assert (success == GNUNET_OK); |
79 | *ok = 0; | 79 | *ok = 0; |
80 | } | 80 | } |