- opaque mq structs
[oweals/gnunet.git] / src / testbed / testbed_api_operations.c
index a96549810c658f6ccfa5722a3f91e430c9142b10..47d135ffd47d09532d5c44a61bd788c6a88b5156 100644 (file)
@@ -463,12 +463,17 @@ decide_capacity (struct OperationQueue *opq,
 
   GNUNET_assert (NULL != (op = entry->op));
   GNUNET_assert (0 < (need = entry->nres));
-  GNUNET_assert (opq->active <= opq->max_active);
   ops = NULL;
   n_ops = 0;
   evict_entries = NULL;
   n_evict_entries = 0;
-  rval = GNUNET_OK;
+  rval = GNUNET_YES;
+  if (opq->active > opq->max_active)
+  {
+    need += opq->active - opq->max_active;
+    rval = GNUNET_NO;
+    goto ret;
+  }
   if ((opq->active + need) <= opq->max_active)
     goto ret;
   deficit = need - (opq->max_active - opq->active);
@@ -543,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;
@@ -564,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;
@@ -579,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;
 }
 
 
@@ -694,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;
   }
 }
@@ -781,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);
 }
 
 
@@ -807,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]);