diff options
author | Sree Harsha Totakura <totakura@in.tum.de> | 2014-07-04 21:38:45 +0000 |
---|---|---|
committer | Sree Harsha Totakura <totakura@in.tum.de> | 2014-07-04 21:38:45 +0000 |
commit | 71e6e22762968ad0ac527058424bbbcd347181ed (patch) | |
tree | d9c272ee933db0e079e32661d21fd05ce01e5f7d /src/testbed | |
parent | eb6fe78cd76489da8ae226ca4bcfaec644dbdde5 (diff) | |
download | gnunet-71e6e22762968ad0ac527058424bbbcd347181ed.tar.gz gnunet-71e6e22762968ad0ac527058424bbbcd347181ed.zip |
Do not cleanup operation queues if they are not empty. Instead, mark them as expired and clean them in destructor.
--This line, and those
below, will be ignored--
M testbed/testbed_api_operations.c
Diffstat (limited to 'src/testbed')
-rw-r--r-- | src/testbed/testbed_api_operations.c | 75 |
1 files changed, 67 insertions, 8 deletions
diff --git a/src/testbed/testbed_api_operations.c b/src/testbed/testbed_api_operations.c index e1dc33f49..8bc38747c 100644 --- a/src/testbed/testbed_api_operations.c +++ b/src/testbed/testbed_api_operations.c | |||
@@ -236,6 +236,11 @@ struct OperationQueue | |||
236 | * #OPERATION_QUEUE_TYPE_ADAPTIVE | 236 | * #OPERATION_QUEUE_TYPE_ADAPTIVE |
237 | */ | 237 | */ |
238 | unsigned int overload; | 238 | unsigned int overload; |
239 | |||
240 | /** | ||
241 | * Is this queue marked for expiry? | ||
242 | */ | ||
243 | unsigned int expired; | ||
239 | }; | 244 | }; |
240 | 245 | ||
241 | 246 | ||
@@ -375,12 +380,22 @@ struct GNUNET_TESTBED_Operation | |||
375 | /** | 380 | /** |
376 | * DLL head for the ready queue | 381 | * DLL head for the ready queue |
377 | */ | 382 | */ |
378 | struct ReadyQueueEntry *rq_head; | 383 | static struct ReadyQueueEntry *rq_head; |
379 | 384 | ||
380 | /** | 385 | /** |
381 | * DLL tail for the ready queue | 386 | * DLL tail for the ready queue |
382 | */ | 387 | */ |
383 | struct ReadyQueueEntry *rq_tail; | 388 | static struct ReadyQueueEntry *rq_tail; |
389 | |||
390 | /** | ||
391 | * Array of operation queues which are to be destroyed | ||
392 | */ | ||
393 | static struct OperationQueue **expired_opqs; | ||
394 | |||
395 | /** | ||
396 | * Number of expired operation queues in the above array | ||
397 | */ | ||
398 | static unsigned int n_expired_opqs; | ||
384 | 399 | ||
385 | /** | 400 | /** |
386 | * The id of the task to process the ready queue | 401 | * The id of the task to process the ready queue |
@@ -1052,17 +1067,15 @@ GNUNET_TESTBED_operation_queue_create_ (enum OperationQueueType type, | |||
1052 | 1067 | ||
1053 | 1068 | ||
1054 | /** | 1069 | /** |
1055 | * Destroy an operation queue. The queue MUST be empty | 1070 | * Cleanup the given operation queue. |
1056 | * at this time. | ||
1057 | * | 1071 | * |
1058 | * @param queue queue to destroy | 1072 | * @param queue the operation queue to destroy |
1059 | */ | 1073 | */ |
1060 | void | 1074 | static void |
1061 | GNUNET_TESTBED_operation_queue_destroy_ (struct OperationQueue *queue) | 1075 | queue_destroy (struct OperationQueue *queue) |
1062 | { | 1076 | { |
1063 | struct FeedbackCtx *fctx; | 1077 | struct FeedbackCtx *fctx; |
1064 | 1078 | ||
1065 | GNUNET_break (GNUNET_YES == is_queue_empty (queue)); | ||
1066 | if (OPERATION_QUEUE_TYPE_ADAPTIVE == queue->type) | 1079 | if (OPERATION_QUEUE_TYPE_ADAPTIVE == queue->type) |
1067 | { | 1080 | { |
1068 | cleanup_tslots (queue); | 1081 | cleanup_tslots (queue); |
@@ -1075,6 +1088,27 @@ GNUNET_TESTBED_operation_queue_destroy_ (struct OperationQueue *queue) | |||
1075 | 1088 | ||
1076 | 1089 | ||
1077 | /** | 1090 | /** |
1091 | * Destroys an operation queue. If the queue is still in use by operations it | ||
1092 | * is marked as expired and its resources are released in the destructor | ||
1093 | * GNUNET_TESTBED_operations_fini(). | ||
1094 | * | ||
1095 | * @param queue queue to destroy | ||
1096 | */ | ||
1097 | void | ||
1098 | GNUNET_TESTBED_operation_queue_destroy_ (struct OperationQueue *queue) | ||
1099 | { | ||
1100 | if (GNUNET_YES != is_queue_empty (queue)) | ||
1101 | { | ||
1102 | GNUNET_assert (0 == queue->expired); /* Are you calling twice on same queue? */ | ||
1103 | queue->expired = 1; | ||
1104 | GNUNET_array_append (expired_opqs, n_expired_opqs, queue); | ||
1105 | return; | ||
1106 | } | ||
1107 | queue_destroy (queue); | ||
1108 | } | ||
1109 | |||
1110 | |||
1111 | /** | ||
1078 | * Destroys the operation queue if it is empty. If not empty return GNUNET_NO. | 1112 | * Destroys the operation queue if it is empty. If not empty return GNUNET_NO. |
1079 | * | 1113 | * |
1080 | * @param queue the queue to destroy if empty | 1114 | * @param queue the queue to destroy if empty |
@@ -1317,4 +1351,29 @@ GNUNET_TESTBED_operation_mark_failed (struct GNUNET_TESTBED_Operation *op) | |||
1317 | } | 1351 | } |
1318 | 1352 | ||
1319 | 1353 | ||
1354 | /** | ||
1355 | * Cleanup expired operation queues. While doing so, also check for any | ||
1356 | * operations which are not completed and warn about them. | ||
1357 | */ | ||
1358 | void __attribute__ ((destructor)) | ||
1359 | GNUNET_TESTBED_operations_fini () | ||
1360 | { | ||
1361 | struct OperationQueue *queue; | ||
1362 | unsigned int i; | ||
1363 | int warn = 0; | ||
1364 | |||
1365 | for (i=0; i < n_expired_opqs; i++) | ||
1366 | { | ||
1367 | queue = expired_opqs[i]; | ||
1368 | if (GNUNET_NO == is_queue_empty (queue)) | ||
1369 | warn = 1; | ||
1370 | queue_destroy (queue); | ||
1371 | } | ||
1372 | GNUNET_free_non_null (expired_opqs); | ||
1373 | n_expired_opqs = 0; | ||
1374 | if (warn) | ||
1375 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
1376 | "Be disciplined. Some operations were not marked as done.\n"); | ||
1377 | |||
1378 | } | ||
1320 | /* end of testbed_api_operations.c */ | 1379 | /* end of testbed_api_operations.c */ |