aboutsummaryrefslogtreecommitdiff
path: root/src/testbed/testbed_api_operations.c
diff options
context:
space:
mode:
authorSree Harsha Totakura <totakura@in.tum.de>2012-11-16 11:20:38 +0000
committerSree Harsha Totakura <totakura@in.tum.de>2012-11-16 11:20:38 +0000
commit57dc1a4ec314043cfdbf6e5a0bcf3c4ca103ddec (patch)
tree33553c2e36c8db66de2df88ed144e5d46bda5b70 /src/testbed/testbed_api_operations.c
parent27520ef39b732562a6c4ffa8640b44250ad72a4a (diff)
downloadgnunet-57dc1a4ec314043cfdbf6e5a0bcf3c4ca103ddec.tar.gz
gnunet-57dc1a4ec314043cfdbf6e5a0bcf3c4ca103ddec.zip
dynamically adjustable operation queues
Diffstat (limited to 'src/testbed/testbed_api_operations.c')
-rw-r--r--src/testbed/testbed_api_operations.c54
1 files changed, 42 insertions, 12 deletions
diff --git a/src/testbed/testbed_api_operations.c b/src/testbed/testbed_api_operations.c
index f609b1770..e657c8354 100644
--- a/src/testbed/testbed_api_operations.c
+++ b/src/testbed/testbed_api_operations.c
@@ -66,10 +66,15 @@ struct OperationQueue
66 struct QueueEntry *tail; 66 struct QueueEntry *tail;
67 67
68 /** 68 /**
69 * Number of operations that can be concurrently 69 * Number of operations that are currently active in this queue.
70 * active in this queue.
71 */ 70 */
72 unsigned int active; 71 unsigned int active;
72
73 /**
74 * Max number of operations which can be active at any time in this queue
75 */
76 unsigned int max_active;
77
73}; 78};
74 79
75 80
@@ -158,9 +163,7 @@ call_start (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
158 op->start_task_id = GNUNET_SCHEDULER_NO_TASK; 163 op->start_task_id = GNUNET_SCHEDULER_NO_TASK;
159 op->state = OP_STATE_STARTED; 164 op->state = OP_STATE_STARTED;
160 if (NULL != op->start) 165 if (NULL != op->start)
161 {
162 op->start (op->cb_cls); 166 op->start (op->cb_cls);
163 }
164} 167}
165 168
166 169
@@ -176,14 +179,10 @@ check_readiness (struct GNUNET_TESTBED_Operation *op)
176 179
177 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == op->start_task_id); 180 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == op->start_task_id);
178 for (i = 0; i < op->nqueues; i++) 181 for (i = 0; i < op->nqueues; i++)
179 { 182 if (op->queues[i]->active >= op->queues[i]->max_active)
180 if (0 == op->queues[i]->active)
181 return; 183 return;
182 }
183 for (i = 0; i < op->nqueues; i++) 184 for (i = 0; i < op->nqueues; i++)
184 { 185 op->queues[i]->active++;
185 op->queues[i]->active--;
186 }
187 op->state = OP_STATE_READY; 186 op->state = OP_STATE_READY;
188 op->start_task_id = GNUNET_SCHEDULER_add_now (&call_start, op); 187 op->start_task_id = GNUNET_SCHEDULER_add_now (&call_start, op);
189} 188}
@@ -226,7 +225,7 @@ GNUNET_TESTBED_operation_queue_create_ (unsigned int max_active)
226 struct OperationQueue *queue; 225 struct OperationQueue *queue;
227 226
228 queue = GNUNET_malloc (sizeof (struct OperationQueue)); 227 queue = GNUNET_malloc (sizeof (struct OperationQueue));
229 queue->active = max_active; 228 queue->max_active = max_active;
230 return queue; 229 return queue;
231} 230}
232 231
@@ -247,6 +246,34 @@ GNUNET_TESTBED_operation_queue_destroy_ (struct OperationQueue *queue)
247 246
248 247
249/** 248/**
249 * Function to reset the maximum number of operations in the given queue. If
250 * max_active is lesser than the number of currently active operations, the
251 * active operations are not stopped immediately.
252 *
253 * @param queue the operation queue which has to be modified
254 * @param max_active the new maximum number of active operations
255 */
256void
257GNUNET_TESTBED_operation_queue_reset_max_active_ (struct OperationQueue *queue,
258 unsigned int max_active)
259{
260 struct QueueEntry *entry;
261
262 queue->max_active = max_active;
263 if (queue->active >= queue->max_active)
264 return;
265 entry = queue->head;
266 while ( (NULL != entry) &&
267 (queue->active < queue->max_active) )
268 {
269 if (OP_STATE_WAITING == entry->op->state)
270 check_readiness (entry->op);
271 entry = entry->next;
272 }
273}
274
275
276/**
250 * Add an operation to a queue. An operation can be in multiple queues at 277 * Add an operation to a queue. An operation can be in multiple queues at
251 * once. Once the operation is inserted into all the queues 278 * once. Once the operation is inserted into all the queues
252 * GNUNET_TESTBED_operation_begin_wait_() has to be called to actually start 279 * GNUNET_TESTBED_operation_begin_wait_() has to be called to actually start
@@ -314,7 +341,10 @@ GNUNET_TESTBED_operation_queue_remove_ (struct OperationQueue *queue,
314 break; 341 break;
315 GNUNET_assert (NULL != entry); 342 GNUNET_assert (NULL != entry);
316 if (OP_STATE_STARTED == operation->state) 343 if (OP_STATE_STARTED == operation->state)
317 queue->active++; 344 {
345 GNUNET_assert (0 != queue->active);
346 queue->active--;
347 }
318 entry2 = entry->next; 348 entry2 = entry->next;
319 GNUNET_CONTAINER_DLL_remove (queue->head, queue->tail, entry); 349 GNUNET_CONTAINER_DLL_remove (queue->head, queue->tail, entry);
320 GNUNET_free (entry); 350 GNUNET_free (entry);