- Document statistics api and fix testing's usage of it
authorBart Polot <bart@net.in.tum.de>
Tue, 8 May 2012 13:33:51 +0000 (13:33 +0000)
committerBart Polot <bart@net.in.tum.de>
Tue, 8 May 2012 13:33:51 +0000 (13:33 +0000)
src/include/gnunet_statistics_service.h
src/statistics/statistics_api.c
src/testing/testing_group.c

index bfd65f883511a12625e385814ec6c6e10b39db31..051533182e360f0e887c1f37dbc48883ce1ddec7 100644 (file)
@@ -145,6 +145,7 @@ struct GNUNET_STATISTICS_GetHandle;
  * @param timeout after how long should we give up (and call
  *        notify with buf NULL and size 0)?
  * @param cont continuation to call when done (can be NULL)
+ *        This callback CANNOT destroy the statistics handle in the same call.
  * @param proc function to call on each value
  * @param cls closure for proc and cont
  * @return NULL on error
index 0533ff95007c2cf38e67074c7040545f7377900a..e1b3698e63367341e5c041c2893e66bc808ef861 100644 (file)
@@ -1075,6 +1075,7 @@ schedule_action (struct GNUNET_STATISTICS_Handle *h)
  * @param timeout after how long should we give up (and call
  *        cont with an error code)?
  * @param cont continuation to call when done (can be NULL)
+ *        This callback CANNOT destroy the statistics handle in the same call.
  * @param proc function to call on each value
  * @param cls closure for cont and proc
  * @return NULL on error
index 607d455b626951e9e03ca7883425217697c7c27d..40cab604b7f099bd9c304aa06122139075761206 100644 (file)
@@ -4884,6 +4884,22 @@ internal_stats_callback (void *cls, const char *subsystem, const char *name,
                               subsystem, name, value, is_persistent);
 }
 
+
+/**
+ * We don't need the statistics handle anymore, destroy it.
+ * 
+ * @param cls Closure (the statistics handle to destroy)
+ * @param tc Task Context
+ */
+static void
+internal_destroy_statistics (void *cls, GNUNET_SCHEDULER_TaskContext *tc)
+{
+  struct GNUNET_STATISTICS_Handle *h = cls;
+
+  GNUNET_STATISTICS_destroy (h, GNUNET_NO);
+}
+
+
 /**
  * Internal continuation call for statistics iteration.
  *
@@ -4908,7 +4924,9 @@ internal_stats_cont (void *cls, int success)
   }
 
   if (core_context->stats_handle != NULL)
-    GNUNET_STATISTICS_destroy (core_context->stats_handle, GNUNET_NO);
+    /* Cannot destroy handle inside the continuation */
+    GNUNET_SCHEDULER_add_now (&internal_destroy_statistics,
+                              core_context->stats_handle);
 
   GNUNET_free (core_context);
 }
@@ -5290,9 +5308,9 @@ increment_outstanding_at_host (const char *hostname,
   struct OutstandingSSH *pos;
 
   pos = pg->ssh_head;
-  while ((pos != NULL) && (strcmp (pos->hostname, hostname) != 0))
+  while ((NULL != pos) && (strcmp (pos->hostname, hostname) != 0))
     pos = pos->next;
-  GNUNET_assert (pos != NULL);
+  GNUNET_assert (NULL != pos);
   pos->outstanding++;
 }