gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r9275 - in gnunet/src: . datastore hostlist include statist


From: gnunet
Subject: [GNUnet-SVN] r9275 - in gnunet/src: . datastore hostlist include statistics
Date: Sun, 25 Oct 2009 04:57:43 -0600

Author: grothoff
Date: 2009-10-25 04:57:43 -0600 (Sun, 25 Oct 2009)
New Revision: 9275

Modified:
   gnunet/src/Makefile.am
   gnunet/src/datastore/plugin_datastore_sqlite.c
   gnunet/src/hostlist/gnunet-daemon-hostlist.c
   gnunet/src/include/gnunet_statistics_service.h
   gnunet/src/statistics/gnunet-statistics.c
   gnunet/src/statistics/statistics_api.c
   gnunet/src/statistics/test_statistics_api.c
Log:
make sure stats that are being set can be committed on destroy

Modified: gnunet/src/Makefile.am
===================================================================
--- gnunet/src/Makefile.am      2009-10-25 10:27:47 UTC (rev 9274)
+++ gnunet/src/Makefile.am      2009-10-25 10:57:43 UTC (rev 9275)
@@ -13,7 +13,6 @@
   arm \
   fragmentation \
   hello \
-  nat \
   peerinfo \
   statistics \
   datacache \
@@ -24,5 +23,6 @@
   testing \
   $(HOSTLIST_DIR) \
   topology \
-  fs
+  fs \
+  nat
 

Modified: gnunet/src/datastore/plugin_datastore_sqlite.c
===================================================================
--- gnunet/src/datastore/plugin_datastore_sqlite.c      2009-10-25 10:27:47 UTC 
(rev 9274)
+++ gnunet/src/datastore/plugin_datastore_sqlite.c      2009-10-25 10:57:43 UTC 
(rev 9275)
@@ -1631,7 +1631,8 @@
   if (plugin->drop_on_shutdown)
     fn = GNUNET_strdup (plugin->fn);
   database_shutdown (plugin);
-  GNUNET_STATISTICS_destroy (plugin->statistics);
+  GNUNET_STATISTICS_destroy (plugin->statistics,
+                            GNUNET_YES);
   plugin->env = NULL; 
   plugin->payload = 0;
   GNUNET_free (api);

Modified: gnunet/src/hostlist/gnunet-daemon-hostlist.c
===================================================================
--- gnunet/src/hostlist/gnunet-daemon-hostlist.c        2009-10-25 10:27:47 UTC 
(rev 9274)
+++ gnunet/src/hostlist/gnunet-daemon-hostlist.c        2009-10-25 10:57:43 UTC 
(rev 9275)
@@ -115,7 +115,8 @@
 {
   if (stats != NULL)
     {
-      GNUNET_STATISTICS_destroy (stats);
+      GNUNET_STATISTICS_destroy (stats,
+                                GNUNET_NO);
       stats = NULL;
     }
 }

Modified: gnunet/src/include/gnunet_statistics_service.h
===================================================================
--- gnunet/src/include/gnunet_statistics_service.h      2009-10-25 10:27:47 UTC 
(rev 9274)
+++ gnunet/src/include/gnunet_statistics_service.h      2009-10-25 10:57:43 UTC 
(rev 9275)
@@ -84,8 +84,13 @@
 /**
  * Destroy a handle (free all state associated with
  * it).
+ *
+ * @param h statistics handle to destroy
+ * @param sync_first set to GNUNET_YES if pending SET requests should
+ *        be completed
  */
-void GNUNET_STATISTICS_destroy (struct GNUNET_STATISTICS_Handle *handle);
+void GNUNET_STATISTICS_destroy (struct GNUNET_STATISTICS_Handle *h,
+                               int sync_first);
 
 
 /**

Modified: gnunet/src/statistics/gnunet-statistics.c
===================================================================
--- gnunet/src/statistics/gnunet-statistics.c   2009-10-25 10:27:47 UTC (rev 
9274)
+++ gnunet/src/statistics/gnunet-statistics.c   2009-10-25 10:57:43 UTC (rev 
9275)
@@ -91,7 +91,8 @@
   if (success != GNUNET_OK)
     ret = 1;
   if (h != NULL)
-    GNUNET_STATISTICS_destroy (h);
+    GNUNET_STATISTICS_destroy (h,
+                              GNUNET_NO);
 }
 
 
@@ -130,7 +131,7 @@
           return;
         }
       GNUNET_STATISTICS_set (h, name, (uint64_t) val, persistent);
-      GNUNET_STATISTICS_destroy (h);
+      GNUNET_STATISTICS_destroy (h, GNUNET_YES);
       return;
     }
   h = GNUNET_STATISTICS_create (sched, "gnunet-statistics", cfg);

Modified: gnunet/src/statistics/statistics_api.c
===================================================================
--- gnunet/src/statistics/statistics_api.c      2009-10-25 10:27:47 UTC (rev 
9274)
+++ gnunet/src/statistics/statistics_api.c      2009-10-25 10:57:43 UTC (rev 
9275)
@@ -161,6 +161,11 @@
    */
   struct ActionItem *current;
 
+  /**
+   * Should this handle auto-destruct once all actions have
+   * been processed?
+   */
+  int do_destroy;
 
 };
 
@@ -198,60 +203,27 @@
 }
 
 
+
+
+
 /**
- * Get handle for the statistics service.
- *
- * @param sched scheduler to use
- * @param subsystem name of subsystem using the service
- * @param cfg services configuration in use
- * @return handle to use
+ * Schedule the next action to be performed.
  */
-struct GNUNET_STATISTICS_Handle *
-GNUNET_STATISTICS_create (struct GNUNET_SCHEDULER_Handle *sched,
-                          const char *subsystem,
-                          const struct GNUNET_CONFIGURATION_Handle *cfg)
-{
-  struct GNUNET_STATISTICS_Handle *ret;
+static void schedule_action (struct GNUNET_STATISTICS_Handle *h);
 
-  GNUNET_assert (subsystem != NULL);
-  GNUNET_assert (sched != NULL);
-  GNUNET_assert (cfg != NULL);
-  ret = GNUNET_malloc (sizeof (struct GNUNET_STATISTICS_Handle));
-  ret->sched = sched;
-  ret->cfg = cfg;
-  ret->subsystem = GNUNET_strdup (subsystem);
-  try_connect (ret);
-  return ret;
-}
 
-
 /**
- * Destroy a handle (free all state associated with
- * it).
+ * GET processing is complete, tell client about it.
  */
-void
-GNUNET_STATISTICS_destroy (struct GNUNET_STATISTICS_Handle *h)
+static void
+finish (struct GNUNET_STATISTICS_Handle *h, int code)
 {
-  struct ActionItem *pos;
-  if (NULL != h->th)
-    {
-      GNUNET_CLIENT_notify_transmit_ready_cancel (h->th);
-      h->th = NULL;
-    }
-  if (h->current != NULL)
-    free_action_item (h->current);
-  while (NULL != (pos = h->action_head))
-    {
-      h->action_head = pos->next;
-      free_action_item (pos);
-    }
-  if (h->client != NULL)
-    {
-      GNUNET_CLIENT_disconnect (h->client);
-      h->client = NULL;
-    }
-  GNUNET_free (h->subsystem);
-  GNUNET_free (h);
+  struct ActionItem *pos = h->current;
+  h->current = NULL;
+  schedule_action (h);
+  if (pos->cont != NULL)
+    pos->cont (pos->cls, code);
+  free_action_item (pos);
 }
 
 
@@ -308,29 +280,7 @@
 }
 
 
-
 /**
- * Schedule the next action to be performed.
- */
-static void schedule_action (struct GNUNET_STATISTICS_Handle *h);
-
-
-/**
- * GET processing is complete, tell client about it.
- */
-static void
-finish (struct GNUNET_STATISTICS_Handle *h, int code)
-{
-  struct ActionItem *pos = h->current;
-  h->current = NULL;
-  schedule_action (h);
-  if (pos->cont != NULL)
-    pos->cont (pos->cls, code);
-  free_action_item (pos);
-}
-
-
-/**
  * Function called with messages from stats service.
  *
  * @param cls closure
@@ -507,6 +457,127 @@
 
 
 /**
+ * Get handle for the statistics service.
+ *
+ * @param sched scheduler to use
+ * @param subsystem name of subsystem using the service
+ * @param cfg services configuration in use
+ * @return handle to use
+ */
+struct GNUNET_STATISTICS_Handle *
+GNUNET_STATISTICS_create (struct GNUNET_SCHEDULER_Handle *sched,
+                          const char *subsystem,
+                          const struct GNUNET_CONFIGURATION_Handle *cfg)
+{
+  struct GNUNET_STATISTICS_Handle *ret;
+
+  GNUNET_assert (subsystem != NULL);
+  GNUNET_assert (sched != NULL);
+  GNUNET_assert (cfg != NULL);
+  ret = GNUNET_malloc (sizeof (struct GNUNET_STATISTICS_Handle));
+  ret->sched = sched;
+  ret->cfg = cfg;
+  ret->subsystem = GNUNET_strdup (subsystem);
+  try_connect (ret);
+  return ret;
+}
+
+
+/**
+ * Destroy a handle (free all state associated with
+ * it).
+ *
+ * @param h statistics handle to destroy
+ * @param sync_first set to GNUNET_YES if pending SET requests should
+ *        be completed
+ */
+void
+GNUNET_STATISTICS_destroy (struct GNUNET_STATISTICS_Handle *h,
+                          int sync_first)
+{
+  struct ActionItem *pos;
+  struct ActionItem *next;
+  struct ActionItem *prev;
+  struct GNUNET_TIME_Relative timeout;
+
+  if (sync_first)
+    {
+      if (h->current != NULL)
+       {
+         if (h->current->type == ACTION_GET)
+           {
+             GNUNET_CLIENT_notify_transmit_ready_cancel (h->th);
+             h->th = NULL;
+           }
+       }
+      pos = h->action_head;
+      prev = NULL;
+      while (pos != NULL)
+       {
+         next = pos->next;
+         if (pos->type == ACTION_GET)
+           {
+             if (prev == NULL)
+               h->action_head = next;
+             else
+               prev->next = next;
+             free_action_item (pos);
+           }
+         else
+           {
+             prev = pos;
+           }
+         pos = next;
+       }
+      h->action_tail = prev;
+      if (h->current == NULL)
+       {
+         h->current = h->action_head;
+         if (h->action_head != NULL)
+           {
+             h->action_head = h->action_head->next;
+             if (h->action_head == NULL)
+               h->action_tail = NULL;
+           }
+       }
+      if ( (h->current != NULL) &&
+          (h->th == NULL) )
+       {                                       
+         timeout = GNUNET_TIME_absolute_get_remaining (h->current->timeout);
+         h->th = GNUNET_CLIENT_notify_transmit_ready (h->client,
+                                                      h->current->msize,
+                                                      timeout,
+                                                      GNUNET_YES,
+                                                      &transmit_action, h);
+         GNUNET_assert (NULL != h->th);
+       }
+      h->do_destroy = GNUNET_YES;
+      return;
+    }
+  if (NULL != h->th)
+    {
+      GNUNET_CLIENT_notify_transmit_ready_cancel (h->th);
+      h->th = NULL;
+    }
+  if (h->current != NULL)
+    free_action_item (h->current);
+  while (NULL != (pos = h->action_head))
+    {
+      h->action_head = pos->next;
+      free_action_item (pos);
+    }
+  if (h->client != NULL)
+    {
+      GNUNET_CLIENT_disconnect (h->client);
+      h->client = NULL;
+    }
+  GNUNET_free (h->subsystem);
+  GNUNET_free (h);
+}
+
+
+
+/**
  * Schedule the next action to be performed.
  */
 static void
@@ -525,7 +596,14 @@
   /* schedule next action */
   h->current = h->action_head;
   if (NULL == h->current)
-    return;
+    {
+      if (h->do_destroy)
+       {
+         h->do_destroy = GNUNET_NO;
+         GNUNET_STATISTICS_destroy (h, GNUNET_YES);
+       }
+      return;
+    }
   h->action_head = h->action_head->next;
   if (NULL == h->action_head)
     h->action_tail = NULL;
@@ -590,6 +668,7 @@
 
   GNUNET_assert (handle != NULL);
   GNUNET_assert (proc != NULL);
+  GNUNET_assert (GNUNET_NO == handle->do_destroy);
   if (GNUNET_YES != try_connect (handle))
     {
 #if DEBUG_STATISTICS
@@ -673,6 +752,7 @@
                        const char *name,
                        uint64_t value, int make_persistent)
 {
+  GNUNET_assert (GNUNET_NO == handle->do_destroy);
   add_setter_action (handle, name, make_persistent, value, ACTION_SET);
 }
 
@@ -691,6 +771,7 @@
                           const char *name,
                           int64_t delta, int make_persistent)
 {
+  GNUNET_assert (GNUNET_NO == handle->do_destroy);
   add_setter_action (handle, name, make_persistent,
                      (unsigned long long) delta, ACTION_UPDATE);
 }

Modified: gnunet/src/statistics/test_statistics_api.c
===================================================================
--- gnunet/src/statistics/test_statistics_api.c 2009-10-25 10:27:47 UTC (rev 
9274)
+++ gnunet/src/statistics/test_statistics_api.c 2009-10-25 10:57:43 UTC (rev 
9275)
@@ -74,7 +74,7 @@
 {
   int *ok = cls;
 
-  GNUNET_STATISTICS_destroy (h);
+  GNUNET_STATISTICS_destroy (h, GNUNET_NO);
   GNUNET_assert (success == GNUNET_OK);
   *ok = 0;
 }





reply via email to

[Prev in Thread] Current Thread [Next in Thread]