From a43c0e67c7df3917cb57567ddec0e8ccc98c7bf4 Mon Sep 17 00:00:00 2001 From: Ivan Maidanski Date: Tue, 12 Dec 2017 19:04:17 +0300 Subject: [PATCH] Use same macro (NTHREADS) across all tests to specify number of threads (code refactoring) * tests/disclaim_test.c [GC_PTHREADS] (THREAD_CNT): Rename to NTHREADS; do not define if already defined. * tests/disclaim_test.c [!GC_PTHREADS] (THREAD_CNT): Rename to NTHREADS; undefine it first. * tests/disclaim_test.c (MUTATE_CNT, main): Rename THREAD_CNT to NTHREADS. * tests/subthread_create.c [!NTHREADS] (INITIAL_THREAD_COUNT): Rename to NTHREADS; add comment. * tests/subthread_create.c (main): Rename INITIAL_THREAD_COUNT to NTHREADS. * tests/threadkey_test.c (LIMIT, main): Rename LIMIT to NTHREADS. --- tests/disclaim_test.c | 31 +++++++++++++++++-------------- tests/subthread_create.c | 13 ++++++++----- tests/threadkey_test.c | 6 +++--- 3 files changed, 28 insertions(+), 22 deletions(-) diff --git a/tests/disclaim_test.c b/tests/disclaim_test.c index a84eff9..62c9a61 100644 --- a/tests/disclaim_test.c +++ b/tests/disclaim_test.c @@ -164,17 +164,20 @@ pair_check_rec(pair_t p) } #ifdef GC_PTHREADS -# define THREAD_CNT 6 -# include +# ifndef NTHREADS +# define NTHREADS 6 +# endif +# include #else -# define THREAD_CNT 1 +# undef NTHREADS +# define NTHREADS 1 #endif #define POP_SIZE 1000 -#if THREAD_CNT > 1 -# define MUTATE_CNT 2000000/THREAD_CNT +#if NTHREADS > 1 +# define MUTATE_CNT (2000000/NTHREADS) #else -# define MUTATE_CNT 10000000 +# define MUTATE_CNT 10000000 #endif #define GROW_LIMIT (MUTATE_CNT/10) @@ -207,10 +210,10 @@ void *test(void *data) int main(void) { -#if THREAD_CNT > 1 - pthread_t th[THREAD_CNT]; +# if NTHREADS > 1 + pthread_t th[NTHREADS]; int i; -#endif +# endif GC_set_all_interior_pointers(0); /* for a stricter test */ GC_INIT(); @@ -221,9 +224,9 @@ int main(void) test_misc_sizes(); -#if THREAD_CNT > 1 +# if NTHREADS > 1 printf("Threaded disclaim test.\n"); - for (i = 0; i < THREAD_CNT; ++i) { + for (i = 0; i < NTHREADS; ++i) { int err = pthread_create(&th[i], NULL, test, NULL); if (err) { fprintf(stderr, "Failed to create thread # %d: %s\n", i, @@ -231,7 +234,7 @@ int main(void) exit(1); } } - for (i = 0; i < THREAD_CNT; ++i) { + for (i = 0; i < NTHREADS; ++i) { int err = pthread_join(th[i], NULL); if (err) { fprintf(stderr, "Failed to join thread # %d: %s\n", i, @@ -239,9 +242,9 @@ int main(void) exit(69); } } -#else +# else printf("Unthreaded disclaim test.\n"); test(NULL); -#endif +# endif return 0; } diff --git a/tests/subthread_create.c b/tests/subthread_create.c index 059c47a..f78a3eb 100644 --- a/tests/subthread_create.c +++ b/tests/subthread_create.c @@ -27,8 +27,11 @@ #include #include +#ifndef NTHREADS +# define NTHREADS 31 /* number of initial threads */ +#endif + #ifndef MAX_SUBTHREAD_DEPTH -# define INITIAL_THREAD_COUNT 31 # define MAX_ALIVE_THREAD_COUNT 55 # define MAX_SUBTHREAD_DEPTH 7 # define MAX_SUBTHREAD_COUNT 200 @@ -95,13 +98,13 @@ int main(void) int i; # ifdef GC_PTHREADS int err; - pthread_t th[INITIAL_THREAD_COUNT]; + pthread_t th[NTHREADS]; # else - HANDLE th[INITIAL_THREAD_COUNT]; + HANDLE th[NTHREADS]; # endif GC_INIT(); - for (i = 0; i < INITIAL_THREAD_COUNT; ++i) { + for (i = 0; i < NTHREADS; ++i) { # ifdef GC_PTHREADS err = pthread_create(&th[i], NULL, entry, 0); if (err) { @@ -119,7 +122,7 @@ int main(void) # endif } - for (i = 0; i < INITIAL_THREAD_COUNT; ++i) { + for (i = 0; i < NTHREADS; ++i) { # ifdef GC_PTHREADS void *res; err = pthread_join(th[i], &res); diff --git a/tests/threadkey_test.c b/tests/threadkey_test.c index b08a0a9..e348d72 100644 --- a/tests/threadkey_test.c +++ b/tests/threadkey_test.c @@ -80,8 +80,8 @@ void make_key (void) pthread_key_create (&key, on_thread_exit); } -#ifndef LIMIT -# define LIMIT 30 +#ifndef NTHREADS +# define NTHREADS 30 /* number of initial threads */ #endif int main (void) @@ -94,7 +94,7 @@ int main (void) # else pthread_once (&key_once, make_key); # endif - for (i = 0; i < LIMIT; i++) { + for (i = 0; i < NTHREADS; i++) { pthread_t t; if (GC_pthread_create(&t, NULL, entry, NULL) == 0) { -- 2.7.4