aboutsummaryrefslogtreecommitdiff
path: root/src/testbed/testbed_api_operations.c
diff options
context:
space:
mode:
authorSree Harsha Totakura <totakura@in.tum.de>2013-01-24 12:24:42 +0000
committerSree Harsha Totakura <totakura@in.tum.de>2013-01-24 12:24:42 +0000
commit978b2684641b79bb7b7e4a1378d9f0f6d0f1a443 (patch)
treebb9558cd98c1b1a6737c73b1164a904e3e39f655 /src/testbed/testbed_api_operations.c
parent50ae0b32aca06a0d2b46b070d9a7fde5e227a400 (diff)
downloadgnunet-978b2684641b79bb7b7e4a1378d9f0f6d0f1a443.tar.gz
gnunet-978b2684641b79bb7b7e4a1378d9f0f6d0f1a443.zip
operations now can explicitly register how many resources they require
Diffstat (limited to 'src/testbed/testbed_api_operations.c')
-rw-r--r--src/testbed/testbed_api_operations.c58
1 files changed, 52 insertions, 6 deletions
diff --git a/src/testbed/testbed_api_operations.c b/src/testbed/testbed_api_operations.c
index 137691e78..139448d91 100644
--- a/src/testbed/testbed_api_operations.c
+++ b/src/testbed/testbed_api_operations.c
@@ -46,6 +46,11 @@ struct QueueEntry
46 * The operation this entry holds 46 * The operation this entry holds
47 */ 47 */
48 struct GNUNET_TESTBED_Operation *op; 48 struct GNUNET_TESTBED_Operation *op;
49
50 /**
51 * How many units of resources does the operation need
52 */
53 unsigned int nres;
49}; 54};
50 55
51 56
@@ -132,6 +137,12 @@ struct GNUNET_TESTBED_Operation
132 struct OperationQueue **queues; 137 struct OperationQueue **queues;
133 138
134 /** 139 /**
140 * Array of number resources an operation need from each queue. This numbers
141 * in this array should correspond to the queues array
142 */
143 unsigned int *nres;
144
145 /**
135 * The id of the task which calls OperationStart for this operation 146 * The id of the task which calls OperationStart for this operation
136 */ 147 */
137 GNUNET_SCHEDULER_TaskIdentifier start_task_id; 148 GNUNET_SCHEDULER_TaskIdentifier start_task_id;
@@ -179,10 +190,13 @@ check_readiness (struct GNUNET_TESTBED_Operation *op)
179 190
180 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == op->start_task_id); 191 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == op->start_task_id);
181 for (i = 0; i < op->nqueues; i++) 192 for (i = 0; i < op->nqueues; i++)
182 if (op->queues[i]->active >= op->queues[i]->max_active) 193 {
194 GNUNET_assert (0 < op->nres[i]);
195 if ((op->queues[i]->active + op->nres[i]) > op->queues[i]->max_active)
183 return; 196 return;
197 }
184 for (i = 0; i < op->nqueues; i++) 198 for (i = 0; i < op->nqueues; i++)
185 op->queues[i]->active++; 199 op->queues[i]->active += op->nres[i];
186 op->state = OP_STATE_READY; 200 op->state = OP_STATE_READY;
187 op->start_task_id = GNUNET_SCHEDULER_add_now (&call_start, op); 201 op->start_task_id = GNUNET_SCHEDULER_add_now (&call_start, op);
188} 202}
@@ -311,18 +325,47 @@ GNUNET_TESTBED_operation_queue_reset_max_active_ (struct OperationQueue *queue,
311 * 325 *
312 * @param queue queue to add the operation to 326 * @param queue queue to add the operation to
313 * @param operation operation to add to the queue 327 * @param operation operation to add to the queue
328 * @param nres the number of units of the resources of queue needed by the
329 * operation. Should be greater than 0.
314 */ 330 */
315void 331void
316GNUNET_TESTBED_operation_queue_insert_ (struct OperationQueue *queue, 332GNUNET_TESTBED_operation_queue_insert2_ (struct OperationQueue *queue,
317 struct GNUNET_TESTBED_Operation 333 struct GNUNET_TESTBED_Operation
318 *operation) 334 *operation,
335 unsigned int nres)
319{ 336{
320 struct QueueEntry *entry; 337 struct QueueEntry *entry;
338 unsigned int qsize;
321 339
340 GNUNET_assert (0 < nres);
322 entry = GNUNET_malloc (sizeof (struct QueueEntry)); 341 entry = GNUNET_malloc (sizeof (struct QueueEntry));
323 entry->op = operation; 342 entry->op = operation;
343 entry->nres = nres;
324 GNUNET_CONTAINER_DLL_insert_tail (queue->head, queue->tail, entry); 344 GNUNET_CONTAINER_DLL_insert_tail (queue->head, queue->tail, entry);
345 qsize = operation->nqueues;
325 GNUNET_array_append (operation->queues, operation->nqueues, queue); 346 GNUNET_array_append (operation->queues, operation->nqueues, queue);
347 GNUNET_array_append (operation->nres, qsize, nres);
348 GNUNET_assert (qsize == operation->nqueues);
349}
350
351
352/**
353 * Add an operation to a queue. An operation can be in multiple queues at
354 * once. Once the operation is inserted into all the queues
355 * GNUNET_TESTBED_operation_begin_wait_() has to be called to actually start
356 * waiting for the operation to become active. The operation is assumed to take
357 * 1 queue resource. Use GNUNET_TESTBED_operation_queue_insert2_() if it
358 * requires more than 1
359 *
360 * @param queue queue to add the operation to
361 * @param operation operation to add to the queue
362 */
363void
364GNUNET_TESTBED_operation_queue_insert_ (struct OperationQueue *queue,
365 struct GNUNET_TESTBED_Operation
366 *operation)
367{
368 return GNUNET_TESTBED_operation_queue_insert2_ (queue, operation, 1);
326} 369}
327 370
328 371
@@ -366,6 +409,7 @@ GNUNET_TESTBED_operation_queue_remove_ (struct OperationQueue *queue,
366 if (entry->op == operation) 409 if (entry->op == operation)
367 break; 410 break;
368 GNUNET_assert (NULL != entry); 411 GNUNET_assert (NULL != entry);
412 GNUNET_assert (0 < entry->nres);
369 switch (operation->state) 413 switch (operation->state)
370 { 414 {
371 case OP_STATE_INIT: 415 case OP_STATE_INIT:
@@ -374,7 +418,8 @@ GNUNET_TESTBED_operation_queue_remove_ (struct OperationQueue *queue,
374 case OP_STATE_READY: 418 case OP_STATE_READY:
375 case OP_STATE_STARTED: 419 case OP_STATE_STARTED:
376 GNUNET_assert (0 != queue->active); 420 GNUNET_assert (0 != queue->active);
377 queue->active--; 421 GNUNET_assert (queue->active >= entry->nres);
422 queue->active -= entry->nres;
378 break; 423 break;
379 } 424 }
380 entry2 = entry->next; 425 entry2 = entry->next;
@@ -408,6 +453,7 @@ GNUNET_TESTBED_operation_release_ (struct GNUNET_TESTBED_Operation *operation)
408 for (i = 0; i < operation->nqueues; i++) 453 for (i = 0; i < operation->nqueues; i++)
409 GNUNET_TESTBED_operation_queue_remove_ (operation->queues[i], operation); 454 GNUNET_TESTBED_operation_queue_remove_ (operation->queues[i], operation);
410 GNUNET_free (operation->queues); 455 GNUNET_free (operation->queues);
456 GNUNET_free (operation->nres);
411 if (NULL != operation->release) 457 if (NULL != operation->release)
412 operation->release (operation->cb_cls); 458 operation->release (operation->cb_cls);
413 GNUNET_free (operation); 459 GNUNET_free (operation);