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)
+ {
+ rval = GNUNET_NO;
+ goto ret;
+ }
if ((opq->active + need) <= opq->max_active)
goto ret;
deficit = need - (opq->max_active - opq->active);
ret:
GNUNET_free_non_null (evict_entries);
- if (NULL != ops_) *ops_ = ops;
- if (NULL != n_ops_) *n_ops_ = n_ops;
+ if (NULL != ops_)
+ *ops_ = ops;
+ else
+ GNUNET_free (ops);
+ if (NULL != n_ops_)
+ *n_ops_ = n_ops;
return rval;
}
*
* @param op the operation
*/
-static void
+static int
check_readiness (struct GNUNET_TESTBED_Operation *op)
{
struct GNUNET_TESTBED_Operation **evict_ops;
&ops, &n_ops))
{
GNUNET_free_non_null (evict_ops);
- return;
+ return GNUNET_NO;
}
if (NULL == ops)
continue;
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;
}
while (NULL != entry)
{
entry2 = entry->next;
- check_readiness (entry->op);
+ if (GNUNET_NO == check_readiness (entry->op))
+ break;
entry = entry2;
}
}
{
GNUNET_assert (NULL == op->rq_entry);
change_state (op, OP_STATE_WAITING);
- check_readiness (op);
+ (void) check_readiness (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]);