From e58e6a7ff78981fb4d592587a30e0a94b873a912 Mon Sep 17 00:00:00 2001 From: Sree Harsha Totakura Date: Wed, 24 Oct 2012 20:34:03 +0000 Subject: multiple operation queues for an operation --- src/testbed/gnunet-service-testbed.c | 4 +-- src/testbed/test_testbed_api_operations.c | 2 ++ src/testbed/testbed_api.c | 2 ++ src/testbed/testbed_api_operations.c | 60 ++++++++++++++++++++++--------- src/testbed/testbed_api_operations.h | 25 +++++++++---- src/testbed/testbed_api_peers.c | 6 ++++ src/testbed/testbed_api_services.c | 1 + src/testbed/testbed_api_topology.c | 1 + src/testbed/x64_misc.supp | 10 ++++++ 9 files changed, 85 insertions(+), 26 deletions(-) diff --git a/src/testbed/gnunet-service-testbed.c b/src/testbed/gnunet-service-testbed.c index 1c6bfe013..81cf29c5f 100644 --- a/src/testbed/gnunet-service-testbed.c +++ b/src/testbed/gnunet-service-testbed.c @@ -3265,8 +3265,8 @@ handle_overlay_connect (void *cls, struct GNUNET_SERVER_Client *client, /* rhc is now set to the existing one from the hash map by reghost_match_iterator() */ /* if queue is empty then ignore creating focc and proceed with - normal forwarding */ - if (NULL == rhc->focc_dll_head) + normal forwarding */ + if (RHC_OL_CONNECT == rhc->state) skip_focc = GNUNET_YES; } if (GNUNET_NO == skip_focc) diff --git a/src/testbed/test_testbed_api_operations.c b/src/testbed/test_testbed_api_operations.c index af59cdaf5..45f2db103 100644 --- a/src/testbed/test_testbed_api_operations.c +++ b/src/testbed/test_testbed_api_operations.c @@ -194,8 +194,10 @@ run (void *cls, char *const *args, const char *cfgfile, op2 = GNUNET_TESTBED_operation_create_ (&op2, start_cb, release_cb); GNUNET_TESTBED_operation_queue_insert_ (q1, op1); GNUNET_TESTBED_operation_queue_insert_ (q2, op1); + GNUNET_TESTBED_operation_begin_wait_ (op1); GNUNET_TESTBED_operation_queue_insert_ (q1, op2); GNUNET_TESTBED_operation_queue_insert_ (q2, op2); + GNUNET_TESTBED_operation_begin_wait_ (op2); result = TEST_INIT; } diff --git a/src/testbed/testbed_api.c b/src/testbed/testbed_api.c index 3d2d44897..c55e7373a 100644 --- a/src/testbed/testbed_api.c +++ b/src/testbed/testbed_api.c @@ -1884,6 +1884,7 @@ GNUNET_TESTBED_controller_link_2_ (void *op_cls, &oprelease_link_controllers); GNUNET_TESTBED_operation_queue_insert_ (master->opq_parallel_operations, opc->op); + GNUNET_TESTBED_operation_begin_wait_ (opc->op); return opc->op; } @@ -2103,6 +2104,7 @@ GNUNET_TESTBED_get_slave_config_ (void *op_cls, &oprelease_get_slave_config); GNUNET_TESTBED_operation_queue_insert_ (master->opq_parallel_operations, opc->op); + GNUNET_TESTBED_operation_begin_wait_ (opc->op); return opc->op; } diff --git a/src/testbed/testbed_api_operations.c b/src/testbed/testbed_api_operations.c index b897cb453..f609b1770 100644 --- a/src/testbed/testbed_api_operations.c +++ b/src/testbed/testbed_api_operations.c @@ -78,14 +78,24 @@ struct OperationQueue */ enum OperationState { - /** - * The operation is currently waiting for resources - */ + /** + * The operation is just created and is in initial state + */ + OP_STATE_INIT, + + /** + * The operation is currently waiting for resources + */ OP_STATE_WAITING, - - /** - * The operation has started - */ + + /** + * The operation is ready to be started + */ + OP_STATE_READY, + + /** + * The operation has started + */ OP_STATE_STARTED }; @@ -164,8 +174,7 @@ check_readiness (struct GNUNET_TESTBED_Operation *op) { unsigned int i; - if (GNUNET_SCHEDULER_NO_TASK != op->start_task_id) - return; + GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == op->start_task_id); for (i = 0; i < op->nqueues; i++) { if (0 == op->queues[i]->active) @@ -175,6 +184,7 @@ check_readiness (struct GNUNET_TESTBED_Operation *op) { op->queues[i]->active--; } + op->state = OP_STATE_READY; op->start_task_id = GNUNET_SCHEDULER_add_now (&call_start, op); } @@ -195,6 +205,7 @@ GNUNET_TESTBED_operation_create_ (void *cls, OperationStart start, op = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_Operation)); op->start = start; + op->state = OP_STATE_INIT; op->release = release; op->cb_cls = cls; op->start_task_id = GNUNET_SCHEDULER_NO_TASK; @@ -236,13 +247,10 @@ GNUNET_TESTBED_operation_queue_destroy_ (struct OperationQueue *queue) /** - * Add an operation to a queue. An operation can be in multiple - * queues at once. Once all queues permit the operation to become - * active, the operation will be activated. The actual activation - * will occur in a separate task (thus allowing multiple queue - * insertions to be made without having the first one instantly - * trigger the operation if the first queue has sufficient - * resources). + * Add an operation to a queue. An operation can be in multiple queues at + * once. Once the operation is inserted into all the queues + * GNUNET_TESTBED_operation_begin_wait_() has to be called to actually start + * waiting for the operation to become active. * * @param queue queue to add the operation to * @param operation operation to add to the queue @@ -262,6 +270,24 @@ GNUNET_TESTBED_operation_queue_insert_ (struct OperationQueue *queue, sizeof (struct OperationQueue *) * (++operation->nqueues)); operation->queues[operation->nqueues - 1] = queue; +} + + +/** + * Marks the given operation as waiting on the queues. Once all queues permit + * the operation to become active, the operation will be activated. The actual + * activation will occur in a separate task (thus allowing multiple queue + * insertions to be made without having the first one instantly trigger the + * operation if the first queue has sufficient resources). + * + * @param operation the operation to marks as waiting + */ +void +GNUNET_TESTBED_operation_begin_wait_ (struct GNUNET_TESTBED_Operation + *operation) +{ + GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == operation->start_task_id); + operation->state = OP_STATE_WAITING; check_readiness (operation); } @@ -293,7 +319,7 @@ GNUNET_TESTBED_operation_queue_remove_ (struct OperationQueue *queue, GNUNET_CONTAINER_DLL_remove (queue->head, queue->tail, entry); GNUNET_free (entry); for (; NULL != entry2; entry2 = entry2->next) - if (OP_STATE_STARTED != entry2->op->state) + if (OP_STATE_WAITING == entry2->op->state) break; if (NULL == entry2) return; diff --git a/src/testbed/testbed_api_operations.h b/src/testbed/testbed_api_operations.h index 519c68139..e78ed0fcc 100644 --- a/src/testbed/testbed_api_operations.h +++ b/src/testbed/testbed_api_operations.h @@ -59,13 +59,10 @@ GNUNET_TESTBED_operation_queue_destroy_ (struct OperationQueue *queue); /** - * Add an operation to a queue. An operation can be in multiple - * queues at once. Once all queues permit the operation to become - * active, the operation will be activated. The actual activation - * will occur in a separate task (thus allowing multiple queue - * insertions to be made without having the first one instantly - * trigger the operation if the first queue has sufficient - * resources). + * Add an operation to a queue. An operation can be in multiple queues at + * once. Once the operation is inserted into all the queues + * GNUNET_TESTBED_operation_begin_wait_() has to be called to actually start + * waiting for the operation to become active. * * @param queue queue to add the operation to * @param operation operation to add to the queue @@ -76,6 +73,20 @@ GNUNET_TESTBED_operation_queue_insert_ (struct OperationQueue *queue, *operation); +/** + * Marks the given operation as waiting on the queues. Once all queues permit + * the operation to become active, the operation will be activated. The actual + * activation will occur in a separate task (thus allowing multiple queue + * insertions to be made without having the first one instantly trigger the + * operation if the first queue has sufficient resources). + * + * @param operation the operation to marks as waiting + */ +void +GNUNET_TESTBED_operation_begin_wait_ (struct GNUNET_TESTBED_Operation + *operation); + + /** * Remove an operation from a queue. This can be because the * oeration was active and has completed (and the resources have diff --git a/src/testbed/testbed_api_peers.c b/src/testbed/testbed_api_peers.c index 527b0f70a..b509df40b 100644 --- a/src/testbed/testbed_api_peers.c +++ b/src/testbed/testbed_api_peers.c @@ -452,6 +452,7 @@ GNUNET_TESTBED_peer_create_with_id_ (uint32_t unique_id, &oprelease_peer_create); GNUNET_TESTBED_operation_queue_insert_ (controller->opq_parallel_operations, opc->op); + GNUNET_TESTBED_operation_begin_wait_ (opc->op); return opc->op; } @@ -532,6 +533,7 @@ GNUNET_TESTBED_peer_start (void *op_cls, &oprelease_peer_start); GNUNET_TESTBED_operation_queue_insert_ (opc->c->opq_parallel_operations, opc->op); + GNUNET_TESTBED_operation_begin_wait_ (opc->op); return opc->op; } @@ -568,6 +570,7 @@ GNUNET_TESTBED_peer_stop (struct GNUNET_TESTBED_Peer *peer, &oprelease_peer_stop); GNUNET_TESTBED_operation_queue_insert_ (opc->c->opq_parallel_operations, opc->op); + GNUNET_TESTBED_operation_begin_wait_ (opc->op); return opc->op; } @@ -611,6 +614,7 @@ GNUNET_TESTBED_peer_get_information (struct GNUNET_TESTBED_Peer *peer, &oprelease_peer_getinfo); GNUNET_TESTBED_operation_queue_insert_ (opc->c->opq_parallel_operations, opc->op); + GNUNET_TESTBED_operation_begin_wait_ (opc->op); return opc->op; } @@ -658,6 +662,7 @@ GNUNET_TESTBED_peer_destroy (struct GNUNET_TESTBED_Peer *peer) &oprelease_peer_destroy); GNUNET_TESTBED_operation_queue_insert_ (opc->c->opq_parallel_operations, opc->op); + GNUNET_TESTBED_operation_begin_wait_ (opc->op); return opc->op; } @@ -730,6 +735,7 @@ GNUNET_TESTBED_overlay_connect (void *op_cls, /* opc->op); */ GNUNET_TESTBED_operation_queue_insert_ (opc->c->opq_parallel_overlay_connect_operations, opc->op); + GNUNET_TESTBED_operation_begin_wait_ (opc->op); return opc->op; } diff --git a/src/testbed/testbed_api_services.c b/src/testbed/testbed_api_services.c index 16ea06077..c755a13a5 100644 --- a/src/testbed/testbed_api_services.c +++ b/src/testbed/testbed_api_services.c @@ -282,6 +282,7 @@ GNUNET_TESTBED_service_connect (void *op_cls, GNUNET_TESTBED_operation_queue_insert_ (peer-> controller->opq_parallel_operations, data->operation); + GNUNET_TESTBED_operation_begin_wait_ (data->operation); return data->operation; } diff --git a/src/testbed/testbed_api_topology.c b/src/testbed/testbed_api_topology.c index 4279299eb..84202ec8c 100644 --- a/src/testbed/testbed_api_topology.c +++ b/src/testbed/testbed_api_topology.c @@ -349,6 +349,7 @@ GNUNET_TESTBED_overlay_configure_topology_va (void *op_cls, &oprelease_overlay_configure_topology); GNUNET_TESTBED_operation_queue_insert_ (c->opq_parallel_topology_config_operations, op); + GNUNET_TESTBED_operation_begin_wait_ (op); return op; } diff --git a/src/testbed/x64_misc.supp b/src/testbed/x64_misc.supp index 7998f068d..e6a19c33e 100644 --- a/src/testbed/x64_misc.supp +++ b/src/testbed/x64_misc.supp @@ -22,3 +22,13 @@ obj:/home/harsha/repos/gnunet/src/util/.libs/libgnunetutil.so.8.0.0 } +{ + + Memcheck:Leak + fun:malloc + ... + fun:gcry_control + fun:GNUNET_CRYPTO_random_init + obj:/home/totakura/gnunet/src/util/.libs/libgnunetutil.so.8.0.0 + obj:/home/totakura/gnunet/src/util/.libs/libgnunetutil.so.8.0.0 +} -- cgit v1.2.3