gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r34427 - gnunet/src/set


From: gnunet
Subject: [GNUnet-SVN] r34427 - gnunet/src/set
Date: Mon, 24 Nov 2014 15:06:24 +0100

Author: grothoff
Date: 2014-11-24 15:06:23 +0100 (Mon, 24 Nov 2014)
New Revision: 34427

Modified:
   gnunet/src/set/gnunet-service-set.c
   gnunet/src/set/gnunet-service-set.h
   gnunet/src/set/gnunet-service-set_intersection.c
   gnunet/src/set/gnunet-service-set_union.c
Log:
-do not do GC for each destroyed operation on client disconnect

Modified: gnunet/src/set/gnunet-service-set.c
===================================================================
--- gnunet/src/set/gnunet-service-set.c 2014-11-24 13:57:17 UTC (rev 34426)
+++ gnunet/src/set/gnunet-service-set.c 2014-11-24 14:06:23 UTC (rev 34427)
@@ -327,32 +327,34 @@
 
 
 /**
- * Destroy the given operation.  Call the implementation-specific cancel 
function
- * of the operation.  Disconnects from the remote peer.
- * Does not disconnect the client, as there may be multiple operations per set.
+ * Destroy the given operation.  Call the implementation-specific
+ * cancel function of the operation.  Disconnects from the remote
+ * peer.  Does not disconnect the client, as there may be multiple
+ * operations per set.
  *
  * @param op operation to destroy
+ * @param gc #GNUNET_YES to perform garbage collection on the set
  */
 void
-_GSS_operation_destroy (struct Operation *op)
+_GSS_operation_destroy (struct Operation *op,
+                        int gc)
 {
   struct Set *set;
   struct GNUNET_CADET_Channel *channel;
 
   if (NULL == op->vt)
+  {
+    /* already in #_GSS_operation_destroy() */
     return;
-
-  set = op->spec->set;
-
+  }
   GNUNET_assert (GNUNET_NO == op->is_incoming);
   GNUNET_assert (NULL != op->spec);
+  set = op->spec->set;
   GNUNET_CONTAINER_DLL_remove (op->spec->set->ops_head,
                                op->spec->set->ops_tail,
                                op);
-
   op->vt->cancel (op);
   op->vt = NULL;
-
   if (NULL != op->spec)
   {
     if (NULL != op->spec->context_msg)
@@ -363,40 +365,34 @@
     GNUNET_free (op->spec);
     op->spec = NULL;
   }
-
   if (NULL != op->mq)
   {
     GNUNET_MQ_destroy (op->mq);
     op->mq = NULL;
   }
-
   if (NULL != (channel = op->channel))
   {
     op->channel = NULL;
     GNUNET_CADET_channel_destroy (channel);
   }
-
-  collect_generation_garbage (set);
-
+  if (GNUNET_YES == gc)
+    collect_generation_garbage (set);
   /* We rely on the channel end handler to free 'op'. When 'op->channel' was 
NULL,
    * there was a channel end handler that will free 'op' on the call stack. */
 }
 
 
 /**
- * Iterator over hash map entries to free
- * element entries.
+ * Iterator over hash map entries to free element entries.
  *
  * @param cls closure
  * @param key current key code
  * @param value a `struct ElementEntry *` to be free'd
- * @return #GNUNET_YES if we should continue to
- *         iterate,
- *         #GNUNET_NO if not.
+ * @return #GNUNET_YES (continue to iterate)
  */
 static int
 destroy_elements_iterator (void *cls,
-                           const struct GNUNET_HashCode * key,
+                           const struct GNUNET_HashCode *key,
                            void *value)
 {
   struct ElementEntry *ee = value;
@@ -407,27 +403,28 @@
 
 
 /**
- * Destroy a set, and free all resources associated with it.
+ * Destroy a set, and free all resources and operations associated with it.
  *
  * @param set the set to destroy
  */
 static void
 set_destroy (struct Set *set)
 {
-  /* If the client is not dead yet, destroy it.
-   * The client's destroy callback will destroy the set again.
-   * We do this so that the channel end handler still has a valid set handle
-   * to destroy. */
   if (NULL != set->client)
   {
+    /* If the client is not dead yet, destroy it.  The client's destroy
+     * callback will call `set_destroy()` again in this case.  We do
+     * this so that the channel end handler still has a valid set handle
+     * to destroy. */
     struct GNUNET_SERVER_Client *client = set->client;
+
     set->client = NULL;
     GNUNET_SERVER_client_disconnect (client);
     return;
   }
   GNUNET_assert (NULL != set->state);
   while (NULL != set->ops_head)
-    _GSS_operation_destroy (set->ops_head);
+    _GSS_operation_destroy (set->ops_head, GNUNET_NO);
   set->vt->destroy_set (set->state);
   set->state = NULL;
   if (NULL != set->client_mq)
@@ -1103,7 +1100,9 @@
     return;
   }
 
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "client requested cancel for op %u\n", 
ntohl (msg->request_id));
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+              "client requested cancel for op %u\n",
+              ntohl (msg->request_id));
 
   found = GNUNET_NO;
   for (op = set->ops_head; NULL != op; op = op->next)
@@ -1120,9 +1119,11 @@
    * yet and try to cancel the (non non-existent) operation.
    */
   if (GNUNET_NO != found)
-    _GSS_operation_destroy (op);
+    _GSS_operation_destroy (op,
+                            GNUNET_YES);
   else
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "client canceled non-existent op\n");
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                "client canceled non-existent op\n");
 
 
   GNUNET_SERVER_receive_done (client, GNUNET_OK);

Modified: gnunet/src/set/gnunet-service-set.h
===================================================================
--- gnunet/src/set/gnunet-service-set.h 2014-11-24 13:57:17 UTC (rev 34426)
+++ gnunet/src/set/gnunet-service-set.h 2014-11-24 14:06:23 UTC (rev 34427)
@@ -444,9 +444,11 @@
  * operations per set.
  *
  * @param op operation to destroy
+ * @param gc #GNUNET_YES to perform garbage collection on the set
  */
 void
-_GSS_operation_destroy (struct Operation *op);
+_GSS_operation_destroy (struct Operation *op,
+                        int gc);
 
 
 /**

Modified: gnunet/src/set/gnunet-service-set_intersection.c
===================================================================
--- gnunet/src/set/gnunet-service-set_intersection.c    2014-11-24 13:57:17 UTC 
(rev 34426)
+++ gnunet/src/set/gnunet-service-set_intersection.c    2014-11-24 14:06:23 UTC 
(rev 34427)
@@ -359,7 +359,7 @@
   msg->request_id = htonl (op->spec->client_request_id);
   msg->element_type = htons (0);
   GNUNET_MQ_send (op->spec->set->client_mq, ev);
-  _GSS_operation_destroy (op);
+  _GSS_operation_destroy (op, GNUNET_YES);
 }
 
 
@@ -525,12 +525,13 @@
   struct Operation *op = cls;
   struct GNUNET_MQ_Envelope *ev;
   struct GNUNET_SET_ResultMessage *rm;
+
   ev = GNUNET_MQ_msg (rm, GNUNET_MESSAGE_TYPE_SET_RESULT);
   rm->request_id = htonl (op->spec->client_request_id);
   rm->result_status = htons (GNUNET_SET_STATUS_DONE);
   rm->element_type = htons (0);
   GNUNET_MQ_send (op->spec->set->client_mq, ev);
-  _GSS_operation_destroy (op);
+  _GSS_operation_destroy (op, GNUNET_YES);
 }
 
 
@@ -1050,7 +1051,7 @@
     GNUNET_MQ_send (op->spec->set->client_mq, ev);
     GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
                 "other peer disconnected prematurely\n");
-    _GSS_operation_destroy (op);
+    _GSS_operation_destroy (op, GNUNET_YES);
     return;
   }
   // else: the session has already been concluded

Modified: gnunet/src/set/gnunet-service-set_union.c
===================================================================
--- gnunet/src/set/gnunet-service-set_union.c   2014-11-24 13:57:17 UTC (rev 
34426)
+++ gnunet/src/set/gnunet-service-set_union.c   2014-11-24 14:06:23 UTC (rev 
34427)
@@ -312,7 +312,7 @@
   msg->request_id = htonl (op->spec->client_request_id);
   msg->element_type = htons (0);
   GNUNET_MQ_send (op->spec->set->client_mq, ev);
-  _GSS_operation_destroy (op);
+  _GSS_operation_destroy (op, GNUNET_YES);
 }
 
 
@@ -984,12 +984,13 @@
   struct GNUNET_MQ_Envelope *ev;
   struct GNUNET_SET_ResultMessage *rm;
   int keep = op->keep;
+
   ev = GNUNET_MQ_msg (rm, GNUNET_MESSAGE_TYPE_SET_RESULT);
   rm->request_id = htonl (op->spec->client_request_id);
   rm->result_status = htons (GNUNET_SET_STATUS_DONE);
   rm->element_type = htons (0);
   GNUNET_MQ_send (op->spec->set->client_mq, ev);
-  _GSS_operation_destroy (op);
+  _GSS_operation_destroy (op, GNUNET_YES);
   if (GNUNET_YES == keep)
     GNUNET_free (op);
 }
@@ -1358,8 +1359,9 @@
     msg->result_status = htons (GNUNET_SET_STATUS_FAILURE);
     msg->element_type = htons (0);
     GNUNET_MQ_send (op->spec->set->client_mq, ev);
-    GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "other peer disconnected 
prematurely\n");
-    _GSS_operation_destroy (op);
+    GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+                "other peer disconnected prematurely\n");
+    _GSS_operation_destroy (op, GNUNET_YES);
     return;
   }
   // else: the session has already been concluded




reply via email to

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