- opaque mq structs
[oweals/gnunet.git] / src / testbed / testbed_api_operations.c
index ed8461606ac5ec89a4d99486887576f1a5be45b2..47d135ffd47d09532d5c44a61bd788c6a88b5156 100644 (file)
@@ -548,7 +548,7 @@ merge_ops (struct GNUNET_TESTBED_Operation ***old,
  *
  * @param op the operation
  */
-static void
+static int
 check_readiness (struct GNUNET_TESTBED_Operation *op)
 {
   struct GNUNET_TESTBED_Operation **evict_ops;
@@ -569,7 +569,7 @@ check_readiness (struct GNUNET_TESTBED_Operation *op)
                                       &ops, &n_ops))
     {
       GNUNET_free_non_null (evict_ops);
-      return;
+      return GNUNET_NO;
     }
     if (NULL == ops)
       continue;
@@ -584,12 +584,13 @@ check_readiness (struct GNUNET_TESTBED_Operation *op)
     evict_ops = NULL;
     /* Evicting the operations should schedule this operation */
     GNUNET_assert (OP_STATE_READY == op->state);
-    return;
+    return GNUNET_YES;
   }
   for (i = 0; i < op->nqueues; i++)
     op->queues[i]->active += op->nres[i];
   change_state (op, OP_STATE_READY);
   rq_add (op);
+  return GNUNET_YES;
 }
 
 
@@ -699,7 +700,8 @@ recheck_waiting (struct OperationQueue *opq)
   while (NULL != entry)
   {
     entry2 = entry->next;
-    check_readiness (entry->op);
+    if (GNUNET_NO == check_readiness (entry->op))
+      break;
     entry = entry2;
   }
 }
@@ -786,7 +788,7 @@ GNUNET_TESTBED_operation_begin_wait_ (struct GNUNET_TESTBED_Operation *op)
 {
   GNUNET_assert (NULL == op->rq_entry);
   change_state (op, OP_STATE_WAITING);
-  check_readiness (op);
+  (void) check_readiness (op);
 }
 
 
@@ -812,6 +814,8 @@ GNUNET_TESTBED_operation_inactivate_ (struct GNUNET_TESTBED_Operation *op)
   nqueues = op->nqueues;
   ms = sizeof (struct OperationQueue *) * nqueues;
   queues = GNUNET_malloc (ms);
+  /* Cloning is needed as the operation be released by waiting operations and
+     hence its nqueues memory ptr will be freed */
   GNUNET_assert (NULL != (queues = memcpy (queues, op->queues, ms)));
   for (i = 0; i < nqueues; i++)
     recheck_waiting (queues[i]);