[rtems-libbsd commit] test/epoch01: Simplify
Sebastian Huber
sebh at rtems.org
Tue Jul 9 12:52:35 UTC 2019
Module: rtems-libbsd
Branch: 5-freebsd-12
Commit: 9ed693d72363bd7ee71e050b32b8b7e1ba8e019f
Changeset: http://git.rtems.org/rtems-libbsd/commit/?id=9ed693d72363bd7ee71e050b32b8b7e1ba8e019f
Author: Sebastian Huber <sebastian.huber at embedded-brains.de>
Date: Tue Jul 9 13:17:43 2019 +0200
test/epoch01: Simplify
---
testsuite/epoch01/test_main.c | 84 +++++++++++++++++++------------------------
1 file changed, 36 insertions(+), 48 deletions(-)
diff --git a/testsuite/epoch01/test_main.c b/testsuite/epoch01/test_main.c
index 7f90fc5..7088a12 100644
--- a/testsuite/epoch01/test_main.c
+++ b/testsuite/epoch01/test_main.c
@@ -202,6 +202,38 @@ test_list_callback(epoch_context_t ec)
}
}
+static test_item *
+test_remove_item(test_context *ctx, uint32_t item_counter[CPU_COUNT],
+ uint32_t *removals, size_t worker_index)
+{
+ test_item *prev;
+ test_item *item;
+ test_item *tmp;
+ test_item *rm;
+
+ prev = NULL;
+ rm = NULL;
+ CK_SLIST_FOREACH_SAFE(item, &ctx->item_list, link, tmp) {
+ ++item_counter[item->index];
+
+ if (item->worker_index == worker_index) {
+ ++(*removals);
+ rm = item;
+
+ if (prev != NULL) {
+ CK_SLIST_REMOVE_AFTER(prev, link);
+ } else {
+ CK_SLIST_REMOVE_HEAD(&ctx->item_list,
+ link);
+ }
+ }
+
+ prev = item;
+ }
+
+ return rm;
+}
+
static void
test_enter_list_op_exit_body(rtems_test_parallel_context *base, void *arg,
size_t active_workers, size_t worker_index)
@@ -219,34 +251,12 @@ test_enter_list_op_exit_body(rtems_test_parallel_context *base, void *arg,
memset(item_counter, 0, sizeof(item_counter));
while (!rtems_test_parallel_stop_job(&ctx->base)) {
- test_item *prev;
- test_item *item;
- test_item *tmp;
test_item *rm;
epoch_enter(e);
++counter;
-
- prev = NULL;
- rm = NULL;
- CK_SLIST_FOREACH_SAFE(item, &ctx->item_list, link, tmp) {
- ++item_counter[item->index];
-
- if (item->worker_index == worker_index) {
- ++removals;
- rm = item;
-
- if (prev != NULL) {
- CK_SLIST_REMOVE_AFTER(prev, link);
- } else {
- CK_SLIST_REMOVE_HEAD(&ctx->item_list,
- link);
- }
- }
-
- prev = item;
- }
-
+ rm = test_remove_item(ctx, item_counter, &removals,
+ worker_index);
epoch_exit(e);
if (rm != NULL) {
@@ -318,34 +328,12 @@ test_enter_list_op_exit_preempt_body(rtems_test_parallel_context *base,
while (!rtems_test_parallel_stop_job(&ctx->base)) {
struct epoch_tracker et;
- test_item *prev;
- test_item *item;
- test_item *tmp;
test_item *rm;
epoch_enter_preempt(e, &et);
++counter;
-
- prev = NULL;
- rm = NULL;
- CK_SLIST_FOREACH_SAFE(item, &ctx->item_list, link, tmp) {
- ++item_counter[item->index];
-
- if (item->worker_index == worker_index) {
- ++removals;
- rm = item;
-
- if (prev != NULL) {
- CK_SLIST_REMOVE_AFTER(prev, link);
- } else {
- CK_SLIST_REMOVE_HEAD(&ctx->item_list,
- link);
- }
- }
-
- prev = item;
- }
-
+ rm = test_remove_item(ctx, item_counter, &removals,
+ worker_index);
epoch_exit_preempt(e, &et);
if (rm != NULL) {
More information about the vc
mailing list