Explorar el Código

multiple operation queues for an operation

Sree Harsha Totakura hace 11 años
padre
commit
e58e6a7ff7

+ 2 - 2
src/testbed/gnunet-service-testbed.c

@@ -3265,8 +3265,8 @@ handle_overlay_connect (void *cls, struct GNUNET_SERVER_Client *client,
           /* rhc is now set to the existing one from the hash map by
              reghost_match_iterator() */
           /* if queue is empty then ignore creating focc and proceed with
-             normal forwarding */
-          if (NULL == rhc->focc_dll_head)
+             normal forwarding */	  	  
+          if (RHC_OL_CONNECT == rhc->state)
             skip_focc = GNUNET_YES;
         }
         if (GNUNET_NO == skip_focc)

+ 2 - 0
src/testbed/test_testbed_api_operations.c

@@ -194,8 +194,10 @@ run (void *cls, char *const *args, const char *cfgfile,
   op2 = GNUNET_TESTBED_operation_create_ (&op2, start_cb, release_cb);
   GNUNET_TESTBED_operation_queue_insert_ (q1, op1);
   GNUNET_TESTBED_operation_queue_insert_ (q2, op1);
+  GNUNET_TESTBED_operation_begin_wait_ (op1);
   GNUNET_TESTBED_operation_queue_insert_ (q1, op2);
   GNUNET_TESTBED_operation_queue_insert_ (q2, op2);
+  GNUNET_TESTBED_operation_begin_wait_ (op2);
   result = TEST_INIT;
 }
 

+ 2 - 0
src/testbed/testbed_api.c

@@ -1884,6 +1884,7 @@ GNUNET_TESTBED_controller_link_2_ (void *op_cls,
                                         &oprelease_link_controllers);
   GNUNET_TESTBED_operation_queue_insert_ (master->opq_parallel_operations,
                                           opc->op);
+  GNUNET_TESTBED_operation_begin_wait_ (opc->op);
   return opc->op;
 }
 
@@ -2103,6 +2104,7 @@ GNUNET_TESTBED_get_slave_config_ (void *op_cls,
                                         &oprelease_get_slave_config);
   GNUNET_TESTBED_operation_queue_insert_ (master->opq_parallel_operations,
 					  opc->op); 
+  GNUNET_TESTBED_operation_begin_wait_ (opc->op);
   return opc->op;
 }
 

+ 43 - 17
src/testbed/testbed_api_operations.c

@@ -78,14 +78,24 @@ struct OperationQueue
  */
 enum OperationState
 {
-    /**
-     * The operation is currently waiting for resources
-     */
+  /**
+   * The operation is just created and is in initial state
+   */
+  OP_STATE_INIT,
+  
+  /**
+   * The operation is currently waiting for resources
+   */
   OP_STATE_WAITING,
-
-    /**
-     * The operation has started
-     */
+  
+  /**
+   * The operation is ready to be started
+   */
+  OP_STATE_READY,
+  
+  /**
+   * The operation has started
+   */
   OP_STATE_STARTED
 };
 
@@ -164,8 +174,7 @@ check_readiness (struct GNUNET_TESTBED_Operation *op)
 {
   unsigned int i;
 
-  if (GNUNET_SCHEDULER_NO_TASK != op->start_task_id)
-    return;
+  GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == op->start_task_id);
   for (i = 0; i < op->nqueues; i++)
   {
     if (0 == op->queues[i]->active)
@@ -175,6 +184,7 @@ check_readiness (struct GNUNET_TESTBED_Operation *op)
   {
     op->queues[i]->active--;
   }
+  op->state = OP_STATE_READY;
   op->start_task_id = GNUNET_SCHEDULER_add_now (&call_start, op);
 }
 
@@ -195,6 +205,7 @@ GNUNET_TESTBED_operation_create_ (void *cls, OperationStart start,
 
   op = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_Operation));
   op->start = start;
+  op->state = OP_STATE_INIT;
   op->release = release;
   op->cb_cls = cls;
   op->start_task_id = GNUNET_SCHEDULER_NO_TASK;
@@ -236,13 +247,10 @@ GNUNET_TESTBED_operation_queue_destroy_ (struct OperationQueue *queue)
 
 
 /**
- * Add an operation to a queue.  An operation can be in multiple
- * queues at once.  Once all queues permit the operation to become
- * active, the operation will be activated.  The actual activation
- * will occur in a separate task (thus allowing multiple queue
- * insertions to be made without having the first one instantly
- * trigger the operation if the first queue has sufficient
- * resources).
+ * Add an operation to a queue.  An operation can be in multiple queues at
+ * once. Once the operation is inserted into all the queues
+ * GNUNET_TESTBED_operation_begin_wait_() has to be called to actually start
+ * waiting for the operation to become active.
  *
  * @param queue queue to add the operation to
  * @param operation operation to add to the queue
@@ -262,6 +270,24 @@ GNUNET_TESTBED_operation_queue_insert_ (struct OperationQueue *queue,
                       sizeof (struct OperationQueue *) *
                       (++operation->nqueues));
   operation->queues[operation->nqueues - 1] = queue;
+}
+
+
+/**
+ * Marks the given operation as waiting on the queues.  Once all queues permit
+ * the operation to become active, the operation will be activated.  The actual
+ * activation will occur in a separate task (thus allowing multiple queue
+ * insertions to be made without having the first one instantly trigger the
+ * operation if the first queue has sufficient resources).
+ *
+ * @param operation the operation to marks as waiting
+ */
+void
+GNUNET_TESTBED_operation_begin_wait_ (struct GNUNET_TESTBED_Operation
+				      *operation)
+{
+  GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == operation->start_task_id);
+  operation->state = OP_STATE_WAITING;
   check_readiness (operation);
 }
 
@@ -293,7 +319,7 @@ GNUNET_TESTBED_operation_queue_remove_ (struct OperationQueue *queue,
   GNUNET_CONTAINER_DLL_remove (queue->head, queue->tail, entry);
   GNUNET_free (entry);
   for (; NULL != entry2; entry2 = entry2->next)
-    if (OP_STATE_STARTED != entry2->op->state)
+    if (OP_STATE_WAITING == entry2->op->state)
       break;
   if (NULL == entry2)
     return;

+ 18 - 7
src/testbed/testbed_api_operations.h

@@ -59,13 +59,10 @@ GNUNET_TESTBED_operation_queue_destroy_ (struct OperationQueue *queue);
 
 
 /**
- * Add an operation to a queue.  An operation can be in multiple
- * queues at once.  Once all queues permit the operation to become
- * active, the operation will be activated.  The actual activation
- * will occur in a separate task (thus allowing multiple queue
- * insertions to be made without having the first one instantly
- * trigger the operation if the first queue has sufficient
- * resources).
+ * Add an operation to a queue.  An operation can be in multiple queues at
+ * once. Once the operation is inserted into all the queues
+ * GNUNET_TESTBED_operation_begin_wait_() has to be called to actually start
+ * waiting for the operation to become active.
  *
  * @param queue queue to add the operation to
  * @param operation operation to add to the queue
@@ -76,6 +73,20 @@ GNUNET_TESTBED_operation_queue_insert_ (struct OperationQueue *queue,
                                         *operation);
 
 
+/**
+ * Marks the given operation as waiting on the queues.  Once all queues permit
+ * the operation to become active, the operation will be activated.  The actual
+ * activation will occur in a separate task (thus allowing multiple queue
+ * insertions to be made without having the first one instantly trigger the
+ * operation if the first queue has sufficient resources).
+ *
+ * @param operation the operation to marks as waiting
+ */
+void
+GNUNET_TESTBED_operation_begin_wait_ (struct GNUNET_TESTBED_Operation
+				      *operation);
+
+
 /**
  * Remove an operation from a queue.  This can be because the
  * oeration was active and has completed (and the resources have

+ 6 - 0
src/testbed/testbed_api_peers.c

@@ -452,6 +452,7 @@ GNUNET_TESTBED_peer_create_with_id_ (uint32_t unique_id,
                                         &oprelease_peer_create);
   GNUNET_TESTBED_operation_queue_insert_ (controller->opq_parallel_operations,
                                           opc->op);
+  GNUNET_TESTBED_operation_begin_wait_ (opc->op);
   return opc->op;
 }
 
@@ -532,6 +533,7 @@ GNUNET_TESTBED_peer_start (void *op_cls,
                                         &oprelease_peer_start);
   GNUNET_TESTBED_operation_queue_insert_ (opc->c->opq_parallel_operations,
                                           opc->op);
+  GNUNET_TESTBED_operation_begin_wait_ (opc->op);
   return opc->op;
 }
 
@@ -568,6 +570,7 @@ GNUNET_TESTBED_peer_stop (struct GNUNET_TESTBED_Peer *peer,
                                         &oprelease_peer_stop);
   GNUNET_TESTBED_operation_queue_insert_ (opc->c->opq_parallel_operations,
                                           opc->op);
+  GNUNET_TESTBED_operation_begin_wait_ (opc->op);
   return opc->op;
 }
 
@@ -611,6 +614,7 @@ GNUNET_TESTBED_peer_get_information (struct GNUNET_TESTBED_Peer *peer,
                                         &oprelease_peer_getinfo);
   GNUNET_TESTBED_operation_queue_insert_ (opc->c->opq_parallel_operations,
                                           opc->op);
+  GNUNET_TESTBED_operation_begin_wait_ (opc->op);
   return opc->op;
 }
 
@@ -658,6 +662,7 @@ GNUNET_TESTBED_peer_destroy (struct GNUNET_TESTBED_Peer *peer)
                                         &oprelease_peer_destroy);
   GNUNET_TESTBED_operation_queue_insert_ (opc->c->opq_parallel_operations,
                                           opc->op);
+  GNUNET_TESTBED_operation_begin_wait_ (opc->op);
   return opc->op;
 }
 
@@ -730,6 +735,7 @@ GNUNET_TESTBED_overlay_connect (void *op_cls,
   /*                                         opc->op); */
   GNUNET_TESTBED_operation_queue_insert_
       (opc->c->opq_parallel_overlay_connect_operations, opc->op);
+  GNUNET_TESTBED_operation_begin_wait_ (opc->op);
   return opc->op;
 }
 

+ 1 - 0
src/testbed/testbed_api_services.c

@@ -282,6 +282,7 @@ GNUNET_TESTBED_service_connect (void *op_cls,
   GNUNET_TESTBED_operation_queue_insert_ (peer->
                                           controller->opq_parallel_operations,
                                           data->operation);
+  GNUNET_TESTBED_operation_begin_wait_ (data->operation);
   return data->operation;
 }
 

+ 1 - 0
src/testbed/testbed_api_topology.c

@@ -349,6 +349,7 @@ GNUNET_TESTBED_overlay_configure_topology_va (void *op_cls,
 					 &oprelease_overlay_configure_topology);
   GNUNET_TESTBED_operation_queue_insert_
       (c->opq_parallel_topology_config_operations, op);
+  GNUNET_TESTBED_operation_begin_wait_ (op);
   return op;
 }
 

+ 10 - 0
src/testbed/x64_misc.supp

@@ -22,3 +22,13 @@
    obj:/home/harsha/repos/gnunet/src/util/.libs/libgnunetutil.so.8.0.0
 }
 
+{
+   <insert_a_suppression_name_here>
+   Memcheck:Leak
+   fun:malloc
+   ...
+   fun:gcry_control
+   fun:GNUNET_CRYPTO_random_init
+   obj:/home/totakura/gnunet/src/util/.libs/libgnunetutil.so.8.0.0
+   obj:/home/totakura/gnunet/src/util/.libs/libgnunetutil.so.8.0.0
+}