diff options
author | Christian Grothoff <christian@grothoff.org> | 2016-06-22 17:24:29 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2016-06-22 17:24:29 +0000 |
commit | f3edb5a8d6ba6f43f5df18f2e98bc1dae90c9d7a (patch) | |
tree | eacad48dc99b856c0b60233f1136efa231c7f68d /src/statistics/statistics_api.c | |
parent | d9700d289ed67cb853b2095aafaa063c5ac595fa (diff) | |
download | gnunet-f3edb5a8d6ba6f43f5df18f2e98bc1dae90c9d7a.tar.gz gnunet-f3edb5a8d6ba6f43f5df18f2e98bc1dae90c9d7a.zip |
-fix statistics termination issue
Diffstat (limited to 'src/statistics/statistics_api.c')
-rw-r--r-- | src/statistics/statistics_api.c | 73 |
1 files changed, 55 insertions, 18 deletions
diff --git a/src/statistics/statistics_api.c b/src/statistics/statistics_api.c index 37aa99017..6e4c768ba 100644 --- a/src/statistics/statistics_api.c +++ b/src/statistics/statistics_api.c | |||
@@ -223,6 +223,11 @@ struct GNUNET_STATISTICS_Handle | |||
223 | struct GNUNET_SCHEDULER_Task *backoff_task; | 223 | struct GNUNET_SCHEDULER_Task *backoff_task; |
224 | 224 | ||
225 | /** | 225 | /** |
226 | * Task for running #do_destroy(). | ||
227 | */ | ||
228 | struct GNUNET_SCHEDULER_Task *destroy_task; | ||
229 | |||
230 | /** | ||
226 | * Time for next connect retry. | 231 | * Time for next connect retry. |
227 | */ | 232 | */ |
228 | struct GNUNET_TIME_Relative backoff; | 233 | struct GNUNET_TIME_Relative backoff; |
@@ -304,10 +309,10 @@ update_memory_statistics (struct GNUNET_STATISTICS_Handle *h) | |||
304 | /** | 309 | /** |
305 | * Schedule the next action to be performed. | 310 | * Schedule the next action to be performed. |
306 | * | 311 | * |
307 | * @param h statistics handle to reconnect | 312 | * @param cls statistics handle to reconnect |
308 | */ | 313 | */ |
309 | static void | 314 | static void |
310 | schedule_action (struct GNUNET_STATISTICS_Handle *h); | 315 | schedule_action (void *cls); |
311 | 316 | ||
312 | 317 | ||
313 | /** | 318 | /** |
@@ -550,7 +555,10 @@ destroy_task (void *cls) | |||
550 | { | 555 | { |
551 | struct GNUNET_STATISTICS_Handle *h = cls; | 556 | struct GNUNET_STATISTICS_Handle *h = cls; |
552 | 557 | ||
553 | GNUNET_STATISTICS_destroy (h, GNUNET_NO); | 558 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
559 | "Running final destruction\n"); | ||
560 | GNUNET_STATISTICS_destroy (h, | ||
561 | GNUNET_NO); | ||
554 | } | 562 | } |
555 | 563 | ||
556 | 564 | ||
@@ -577,6 +585,8 @@ handle_test (void *cls, | |||
577 | return; | 585 | return; |
578 | } | 586 | } |
579 | h->do_destroy = GNUNET_NO; | 587 | h->do_destroy = GNUNET_NO; |
588 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
589 | "Received TEST message from statistics, can complete disconnect\n"); | ||
580 | GNUNET_SCHEDULER_add_now (&destroy_task, | 590 | GNUNET_SCHEDULER_add_now (&destroy_task, |
581 | h); | 591 | h); |
582 | } | 592 | } |
@@ -710,6 +720,8 @@ do_destroy (void *cls) | |||
710 | { | 720 | { |
711 | struct GNUNET_STATISTICS_Handle *h = cls; | 721 | struct GNUNET_STATISTICS_Handle *h = cls; |
712 | 722 | ||
723 | h->destroy_task = NULL; | ||
724 | h->do_destroy = GNUNET_NO; | ||
713 | GNUNET_STATISTICS_destroy (h, | 725 | GNUNET_STATISTICS_destroy (h, |
714 | GNUNET_NO); | 726 | GNUNET_NO); |
715 | } | 727 | } |
@@ -742,8 +754,10 @@ reconnect_later (struct GNUNET_STATISTICS_Handle *h) | |||
742 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 754 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
743 | _("Could not save some persistent statistics\n")); | 755 | _("Could not save some persistent statistics\n")); |
744 | h->do_destroy = GNUNET_NO; | 756 | h->do_destroy = GNUNET_NO; |
745 | GNUNET_SCHEDULER_add_now (&do_destroy, | 757 | if (NULL != h->destroy_task) |
746 | h); | 758 | GNUNET_SCHEDULER_cancel (h->destroy_task); |
759 | h->destroy_task = GNUNET_SCHEDULER_add_now (&do_destroy, | ||
760 | h); | ||
747 | return; | 761 | return; |
748 | } | 762 | } |
749 | h->backoff_task | 763 | h->backoff_task |
@@ -820,6 +834,7 @@ transmit_watch (struct GNUNET_STATISTICS_Handle *handle) | |||
820 | GNUNET_assert (NULL == handle->current->cont); | 834 | GNUNET_assert (NULL == handle->current->cont); |
821 | free_action_item (handle->current); | 835 | free_action_item (handle->current); |
822 | handle->current = NULL; | 836 | handle->current = NULL; |
837 | schedule_action (handle); | ||
823 | } | 838 | } |
824 | 839 | ||
825 | 840 | ||
@@ -857,6 +872,9 @@ transmit_set (struct GNUNET_STATISTICS_Handle *handle) | |||
857 | free_action_item (handle->current); | 872 | free_action_item (handle->current); |
858 | handle->current = NULL; | 873 | handle->current = NULL; |
859 | update_memory_statistics (handle); | 874 | update_memory_statistics (handle); |
875 | GNUNET_MQ_notify_sent (env, | ||
876 | &schedule_action, | ||
877 | handle); | ||
860 | GNUNET_MQ_send (handle->mq, | 878 | GNUNET_MQ_send (handle->mq, |
861 | env); | 879 | env); |
862 | } | 880 | } |
@@ -873,18 +891,18 @@ struct GNUNET_STATISTICS_Handle * | |||
873 | GNUNET_STATISTICS_create (const char *subsystem, | 891 | GNUNET_STATISTICS_create (const char *subsystem, |
874 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 892 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
875 | { | 893 | { |
876 | struct GNUNET_STATISTICS_Handle *ret; | 894 | struct GNUNET_STATISTICS_Handle *h; |
877 | 895 | ||
878 | if (GNUNET_YES == | 896 | if (GNUNET_YES == |
879 | GNUNET_CONFIGURATION_get_value_yesno (cfg, | 897 | GNUNET_CONFIGURATION_get_value_yesno (cfg, |
880 | "statistics", | 898 | "statistics", |
881 | "DISABLE")) | 899 | "DISABLE")) |
882 | return NULL; | 900 | return NULL; |
883 | ret = GNUNET_new (struct GNUNET_STATISTICS_Handle); | 901 | h = GNUNET_new (struct GNUNET_STATISTICS_Handle); |
884 | ret->cfg = cfg; | 902 | h->cfg = cfg; |
885 | ret->subsystem = GNUNET_strdup (subsystem); | 903 | h->subsystem = GNUNET_strdup (subsystem); |
886 | ret->backoff = GNUNET_TIME_UNIT_MILLISECONDS; | 904 | h->backoff = GNUNET_TIME_UNIT_MILLISECONDS; |
887 | return ret; | 905 | return h; |
888 | } | 906 | } |
889 | 907 | ||
890 | 908 | ||
@@ -906,11 +924,6 @@ GNUNET_STATISTICS_destroy (struct GNUNET_STATISTICS_Handle *h, | |||
906 | if (NULL == h) | 924 | if (NULL == h) |
907 | return; | 925 | return; |
908 | GNUNET_assert (GNUNET_NO == h->do_destroy); // Don't call twice. | 926 | GNUNET_assert (GNUNET_NO == h->do_destroy); // Don't call twice. |
909 | if (NULL != h->backoff_task) | ||
910 | { | ||
911 | GNUNET_SCHEDULER_cancel (h->backoff_task); | ||
912 | h->backoff_task = NULL; | ||
913 | } | ||
914 | if ( (sync_first) && | 927 | if ( (sync_first) && |
915 | (GNUNET_YES == try_connect (h)) ) | 928 | (GNUNET_YES == try_connect (h)) ) |
916 | { | 929 | { |
@@ -933,9 +946,18 @@ GNUNET_STATISTICS_destroy (struct GNUNET_STATISTICS_Handle *h, | |||
933 | } | 946 | } |
934 | h->do_destroy = GNUNET_YES; | 947 | h->do_destroy = GNUNET_YES; |
935 | schedule_action (h); | 948 | schedule_action (h); |
949 | h->destroy_task | ||
950 | = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (h->backoff, | ||
951 | 5), | ||
952 | &do_destroy, | ||
953 | h); | ||
954 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
955 | "Deferring destruction\n"); | ||
936 | return; /* do not finish destruction just yet */ | 956 | return; /* do not finish destruction just yet */ |
937 | } | 957 | } |
938 | /* do clean up all */ | 958 | /* do clean up all */ |
959 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
960 | "Cleaning all up\n"); | ||
939 | while (NULL != (pos = h->action_head)) | 961 | while (NULL != (pos = h->action_head)) |
940 | { | 962 | { |
941 | GNUNET_CONTAINER_DLL_remove (h->action_head, | 963 | GNUNET_CONTAINER_DLL_remove (h->action_head, |
@@ -944,6 +966,17 @@ GNUNET_STATISTICS_destroy (struct GNUNET_STATISTICS_Handle *h, | |||
944 | free_action_item (pos); | 966 | free_action_item (pos); |
945 | } | 967 | } |
946 | do_disconnect (h); | 968 | do_disconnect (h); |
969 | if (NULL != h->backoff_task) | ||
970 | { | ||
971 | GNUNET_SCHEDULER_cancel (h->backoff_task); | ||
972 | h->backoff_task = NULL; | ||
973 | } | ||
974 | if (NULL != h->destroy_task) | ||
975 | { | ||
976 | GNUNET_break (0); | ||
977 | GNUNET_SCHEDULER_cancel (h->destroy_task); | ||
978 | h->destroy_task = NULL; | ||
979 | } | ||
947 | for (unsigned int i = 0; i < h->watches_size; i++) | 980 | for (unsigned int i = 0; i < h->watches_size; i++) |
948 | { | 981 | { |
949 | if (NULL == h->watches[i]) | 982 | if (NULL == h->watches[i]) |
@@ -963,11 +996,13 @@ GNUNET_STATISTICS_destroy (struct GNUNET_STATISTICS_Handle *h, | |||
963 | /** | 996 | /** |
964 | * Schedule the next action to be performed. | 997 | * Schedule the next action to be performed. |
965 | * | 998 | * |
966 | * @param h statistics handle | 999 | * @param cls statistics handle |
967 | */ | 1000 | */ |
968 | static void | 1001 | static void |
969 | schedule_action (struct GNUNET_STATISTICS_Handle *h) | 1002 | schedule_action (void *cls) |
970 | { | 1003 | { |
1004 | struct GNUNET_STATISTICS_Handle *h = cls; | ||
1005 | |||
971 | if (NULL != h->backoff_task) | 1006 | if (NULL != h->backoff_task) |
972 | return; /* action already pending */ | 1007 | return; /* action already pending */ |
973 | if (GNUNET_YES != try_connect (h)) | 1008 | if (GNUNET_YES != try_connect (h)) |
@@ -987,6 +1022,8 @@ schedule_action (struct GNUNET_STATISTICS_Handle *h) | |||
987 | if (GNUNET_YES != h->do_destroy) | 1022 | if (GNUNET_YES != h->do_destroy) |
988 | return; /* nothing to do */ | 1023 | return; /* nothing to do */ |
989 | /* let service know that we're done */ | 1024 | /* let service know that we're done */ |
1025 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1026 | "Notifying service that we are done\n"); | ||
990 | h->do_destroy = GNUNET_SYSERR; /* in 'TEST' mode */ | 1027 | h->do_destroy = GNUNET_SYSERR; /* in 'TEST' mode */ |
991 | env = GNUNET_MQ_msg (hdr, | 1028 | env = GNUNET_MQ_msg (hdr, |
992 | GNUNET_MESSAGE_TYPE_TEST); | 1029 | GNUNET_MESSAGE_TYPE_TEST); |