+/**
+ * Removes a queue entry of an operation from one of the operation queues' lists
+ * depending on the state of the operation
+ *
+ * @param op the operation whose entry has to be removed
+ * @param index the index of the entry in the operation's array of queue entries
+ */
+static void
+remove_queue_entry (struct GNUNET_TESTBED_Operation *op, unsigned int index)
+{
+ struct OperationQueue *opq;
+ struct QueueEntry *entry;
+
+ opq = op->queues[index];
+ entry = op->qentries[index];
+ switch (op->state)
+ {
+ case OP_STATE_INIT:
+ GNUNET_assert (0);
+ break;
+ case OP_STATE_WAITING:
+ GNUNET_CONTAINER_DLL_remove (opq->wq_head, opq->wq_tail, entry);
+ break;
+ case OP_STATE_READY:
+ GNUNET_CONTAINER_DLL_remove (opq->rq_head, opq->rq_tail, entry);
+ break;
+ case OP_STATE_ACTIVE:
+ GNUNET_CONTAINER_DLL_remove (opq->aq_head, opq->aq_tail, entry);
+ break;
+ case OP_STATE_INACTIVE:
+ GNUNET_CONTAINER_DLL_remove (opq->nq_head, opq->nq_tail, entry);
+ break;
+ }
+}
+
+
+/**
+ * Changes the state of the operation while moving its associated queue entries
+ * in the operation's operation queues
+ *
+ * @param op the operation whose state has to be changed
+ * @param state the state the operation should have. It cannot be OP_STATE_INIT
+ */
+static void
+change_state (struct GNUNET_TESTBED_Operation *op, enum OperationState state)
+{
+ struct QueueEntry *entry;
+ struct OperationQueue *opq;
+ unsigned int cnt;
+ unsigned int s;
+
+ GNUNET_assert (OP_STATE_INIT != state);
+ GNUNET_assert (NULL != op->queues);
+ GNUNET_assert (NULL != op->nres);
+ GNUNET_assert ((OP_STATE_INIT == op->state) || (NULL != op->qentries));
+ GNUNET_assert (op->state != state);
+ for (cnt = 0; cnt < op->nqueues; cnt++)
+ {
+ if (OP_STATE_INIT == op->state)
+ {
+ entry = GNUNET_malloc (sizeof (struct QueueEntry));
+ entry->op = op;
+ entry->nres = op->nres[cnt];
+ s = cnt;
+ GNUNET_array_append (op->qentries, s, entry);
+ }
+ else
+ {
+ entry = op->qentries[cnt];
+ remove_queue_entry (op, cnt);
+ }
+ opq = op->queues[cnt];
+ switch (state)
+ {
+ case OP_STATE_INIT:
+ GNUNET_assert (0);
+ break;
+ case OP_STATE_WAITING:
+ GNUNET_CONTAINER_DLL_insert_tail (opq->wq_head, opq->wq_tail, entry);
+ break;
+ case OP_STATE_READY:
+ GNUNET_CONTAINER_DLL_insert_tail (opq->rq_head, opq->rq_tail, entry);
+ break;
+ case OP_STATE_ACTIVE:
+ GNUNET_CONTAINER_DLL_insert_tail (opq->aq_head, opq->aq_tail, entry);
+ break;
+ case OP_STATE_INACTIVE:
+ GNUNET_CONTAINER_DLL_insert_tail (opq->nq_head, opq->nq_tail, entry);
+ break;
+ }
+ }
+ op->state = state;
+}
+
+