aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSree Harsha Totakura <totakura@in.tum.de>2013-04-10 10:21:07 +0000
committerSree Harsha Totakura <totakura@in.tum.de>2013-04-10 10:21:07 +0000
commitf708bc74bea8e0efa1b8740c00a05c5b4b4707a5 (patch)
tree942936e1ec3591a8ac552b66f88e1ae1881f3abb /src
parent4465acf38d8cb43d06f45ac631586caa334a5fd8 (diff)
downloadgnunet-f708bc74bea8e0efa1b8740c00a05c5b4b4707a5.tar.gz
gnunet-f708bc74bea8e0efa1b8740c00a05c5b4b4707a5.zip
- doc
Diffstat (limited to 'src')
-rw-r--r--src/testbed/testbed_api_operations.c84
1 files changed, 70 insertions, 14 deletions
diff --git a/src/testbed/testbed_api_operations.c b/src/testbed/testbed_api_operations.c
index 72d1733c9..bd094887e 100644
--- a/src/testbed/testbed_api_operations.c
+++ b/src/testbed/testbed_api_operations.c
@@ -22,7 +22,9 @@
22 * @file testbed/testbed_api_operations.c 22 * @file testbed/testbed_api_operations.c
23 * @brief functions to manage operation queues 23 * @brief functions to manage operation queues
24 * @author Christian Grothoff 24 * @author Christian Grothoff
25 * @author Sree Harsha Totakura
25 */ 26 */
27
26#include "platform.h" 28#include "platform.h"
27#include "testbed_api_operations.h" 29#include "testbed_api_operations.h"
28 30
@@ -139,9 +141,9 @@ enum OperationState
139 OP_STATE_READY, 141 OP_STATE_READY,
140 142
141 /** 143 /**
142 * The operation has started 144 * The operation has started and is active
143 */ 145 */
144 OP_STATE_STARTED, 146 OP_STATE_ACTIVE,
145 147
146 /** 148 /**
147 * The operation is inactive. It still holds resources on the operation 149 * The operation is inactive. It still holds resources on the operation
@@ -246,7 +248,15 @@ struct ReadyQueueEntry *rq_tail;
246 */ 248 */
247GNUNET_SCHEDULER_TaskIdentifier process_rq_task_id; 249GNUNET_SCHEDULER_TaskIdentifier process_rq_task_id;
248 250
249void 251
252/**
253 * Removes a queue entry of an operation from one of the operation queues' lists
254 * depending on the state of the operation
255 *
256 * @param op the operation whose entry has to be removed
257 * @param index the index of the entry in the operation's array of queue entries
258 */
259static void
250remove_queue_entry (struct GNUNET_TESTBED_Operation *op, unsigned int index) 260remove_queue_entry (struct GNUNET_TESTBED_Operation *op, unsigned int index)
251{ 261{
252 struct OperationQueue *opq; 262 struct OperationQueue *opq;
@@ -265,7 +275,7 @@ remove_queue_entry (struct GNUNET_TESTBED_Operation *op, unsigned int index)
265 case OP_STATE_READY: 275 case OP_STATE_READY:
266 GNUNET_CONTAINER_DLL_remove (opq->rq_head, opq->rq_tail, entry); 276 GNUNET_CONTAINER_DLL_remove (opq->rq_head, opq->rq_tail, entry);
267 break; 277 break;
268 case OP_STATE_STARTED: 278 case OP_STATE_ACTIVE:
269 GNUNET_CONTAINER_DLL_remove (opq->aq_head, opq->aq_tail, entry); 279 GNUNET_CONTAINER_DLL_remove (opq->aq_head, opq->aq_tail, entry);
270 break; 280 break;
271 case OP_STATE_INACTIVE: 281 case OP_STATE_INACTIVE:
@@ -274,7 +284,15 @@ remove_queue_entry (struct GNUNET_TESTBED_Operation *op, unsigned int index)
274 } 284 }
275} 285}
276 286
277void 287
288/**
289 * Changes the state of the operation while moving its associated queue entries
290 * in the operation's operation queues
291 *
292 * @param op the operation whose state has to be changed
293 * @param state the state the operation should have. It cannot be OP_STATE_INIT
294 */
295static void
278change_state (struct GNUNET_TESTBED_Operation *op, enum OperationState state) 296change_state (struct GNUNET_TESTBED_Operation *op, enum OperationState state)
279{ 297{
280 struct QueueEntry *entry; 298 struct QueueEntry *entry;
@@ -314,7 +332,7 @@ change_state (struct GNUNET_TESTBED_Operation *op, enum OperationState state)
314 case OP_STATE_READY: 332 case OP_STATE_READY:
315 GNUNET_CONTAINER_DLL_insert_tail (opq->rq_head, opq->rq_tail, entry); 333 GNUNET_CONTAINER_DLL_insert_tail (opq->rq_head, opq->rq_tail, entry);
316 break; 334 break;
317 case OP_STATE_STARTED: 335 case OP_STATE_ACTIVE:
318 GNUNET_CONTAINER_DLL_insert_tail (opq->aq_head, opq->aq_tail, entry); 336 GNUNET_CONTAINER_DLL_insert_tail (opq->aq_head, opq->aq_tail, entry);
319 break; 337 break;
320 case OP_STATE_INACTIVE: 338 case OP_STATE_INACTIVE:
@@ -367,7 +385,7 @@ process_rq_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
367 rq_remove (op); 385 rq_remove (op);
368 if (NULL != rq_head) 386 if (NULL != rq_head)
369 process_rq_task_id = GNUNET_SCHEDULER_add_now (&process_rq_task, NULL); 387 process_rq_task_id = GNUNET_SCHEDULER_add_now (&process_rq_task, NULL);
370 change_state (op, OP_STATE_STARTED); 388 change_state (op, OP_STATE_ACTIVE);
371 if (NULL != op->start) 389 if (NULL != op->start)
372 op->start (op->cb_cls); 390 op->start (op->cb_cls);
373} 391}
@@ -393,6 +411,13 @@ rq_add (struct GNUNET_TESTBED_Operation *op)
393} 411}
394 412
395 413
414/**
415 * Checks if the given operation queue is empty or not
416 *
417 * @param opq the operation queue
418 * @return GNUNET_YES if the given operation queue has no operations; GNUNET_NO
419 * otherwise
420 */
396static int 421static int
397is_queue_empty (struct OperationQueue *opq) 422is_queue_empty (struct OperationQueue *opq)
398{ 423{
@@ -405,7 +430,23 @@ is_queue_empty (struct OperationQueue *opq)
405} 430}
406 431
407 432
408int 433/**
434 * Checks if the given operation queue has enough resources to provide for the
435 * operation of the given queue entry. It also checks if any inactive
436 * operations are to be released in order to accommodate the needed resources
437 * and returns them as an array.
438 *
439 * @param opq the operation queue to check for resource accommodation
440 * @param entry the operation queue entry whose operation's resources are to be
441 * accommodated
442 * @param ops_ pointer to return the array of operations which are to be released
443 * in order to accommodate the new operation. Can be NULL
444 * @param n_ops_ the number of operations in ops_
445 * @return GNUNET_YES if the given entry's operation can be accommodated in this
446 * queue. GNUNET_NO if it cannot be accommodated; ops_ and n_ops_ will
447 * be set to NULL and 0 respectively.
448 */
449static int
409decide_capacity (struct OperationQueue *opq, 450decide_capacity (struct OperationQueue *opq,
410 struct QueueEntry *entry, 451 struct QueueEntry *entry,
411 struct GNUNET_TESTBED_Operation ***ops_, 452 struct GNUNET_TESTBED_Operation ***ops_,
@@ -456,8 +497,17 @@ decide_capacity (struct OperationQueue *opq,
456 return rval; 497 return rval;
457} 498}
458 499
459/* FIXME: improve.. */ 500
460void 501/**
502 * Merges an array of operations into another, eliminating duplicates. No
503 * ordering is guaranteed.
504 *
505 * @param old the array into which the merging is done.
506 * @param n_old the number of operations in old array
507 * @param new the array from which operations are to be merged
508 * @param n_new the number of operations in new array
509 */
510static void
461merge_ops (struct GNUNET_TESTBED_Operation ***old, 511merge_ops (struct GNUNET_TESTBED_Operation ***old,
462 unsigned int *n_old, 512 unsigned int *n_old,
463 struct GNUNET_TESTBED_Operation **new, 513 struct GNUNET_TESTBED_Operation **new,
@@ -628,7 +678,13 @@ GNUNET_TESTBED_operation_queue_destroy_empty_ (struct OperationQueue *queue)
628} 678}
629 679
630 680
631void 681/**
682 * Rechecks if any of the operations in the given operation queue's waiting list
683 * can be made active
684 *
685 * @param opq the operation queue
686 */
687static void
632recheck_waiting (struct OperationQueue *opq) 688recheck_waiting (struct OperationQueue *opq)
633{ 689{
634 struct QueueEntry *entry; 690 struct QueueEntry *entry;
@@ -746,7 +802,7 @@ GNUNET_TESTBED_operation_inactivate_ (struct GNUNET_TESTBED_Operation *op)
746 unsigned int nqueues; 802 unsigned int nqueues;
747 unsigned int i; 803 unsigned int i;
748 804
749 GNUNET_assert (OP_STATE_STARTED == op->state); 805 GNUNET_assert (OP_STATE_ACTIVE == op->state);
750 change_state (op, OP_STATE_INACTIVE); 806 change_state (op, OP_STATE_INACTIVE);
751 nqueues = op->nqueues; 807 nqueues = op->nqueues;
752 ms = sizeof (struct OperationQueue *) * nqueues; 808 ms = sizeof (struct OperationQueue *) * nqueues;
@@ -770,7 +826,7 @@ GNUNET_TESTBED_operation_activate_ (struct GNUNET_TESTBED_Operation *op)
770{ 826{
771 827
772 GNUNET_assert (OP_STATE_INACTIVE == op->state); 828 GNUNET_assert (OP_STATE_INACTIVE == op->state);
773 change_state (op, OP_STATE_STARTED); 829 change_state (op, OP_STATE_ACTIVE);
774} 830}
775 831
776 832
@@ -812,7 +868,7 @@ GNUNET_TESTBED_operation_release_ (struct GNUNET_TESTBED_Operation *op)
812 case OP_STATE_WAITING: 868 case OP_STATE_WAITING:
813 break; 869 break;
814 case OP_STATE_READY: 870 case OP_STATE_READY:
815 case OP_STATE_STARTED: 871 case OP_STATE_ACTIVE:
816 GNUNET_assert (0 != opq->active); 872 GNUNET_assert (0 != opq->active);
817 GNUNET_assert (opq->active >= entry->nres); 873 GNUNET_assert (opq->active >= entry->nres);
818 opq->active -= entry->nres; 874 opq->active -= entry->nres;