diff options
author | Ivan Maidanski <ivmai@mail.ru> | 2022-04-02 17:01:47 +0300 |
---|---|---|
committer | Ivan Maidanski <ivmai@mail.ru> | 2022-04-02 17:01:47 +0300 |
commit | afbe4cd61adc2537ade075db5d579af2fec707c2 (patch) | |
tree | e3c1e38a4d07afac2be4080c09611f30343f56b7 /tests/weakmap.c | |
parent | f31336075531ee9d7093447d41182e51386509fc (diff) | |
download | bdwgc-afbe4cd61adc2537ade075db5d579af2fec707c2.tar.gz |
Allow to compile tests with custom NTHREADS set to zero
Also, reduce NTHREADS default value in weakmap to match that in gctest
and disclaim.
* tests/disclaim.c [GC_PTHREADS && !NTHREADS] (NTHREADS): Change value
from 6 to 5; add comment.
* tests/disclaim.c [!GC_PTHREADS] (NTHREADS): Change value from 1 to 0.
* tests/weakmap.c [!GC_PTHREADS] (NTHREADS): Likewise.
* tests/disclaim.c (MUTATE_CNT): Change NTHREADS to NTHREADS+1.
* tests/weakmap.c (MUTATE_CNT): Likewise.
* tests/disclaim.c (main): Change NTHREADS>1 to NTHREADS>0.
* tests/disclaim.c (main): Call test(NULL) before calling
pthread_join() first time.
* tests/weakmap.c (main): Likewise.
* tests/weakmap.c [GC_PTHREADS && !NTHREADS] (NTHREADS): Change value
from 8 to 5; add comment.
* tests/weakmap.c (main): Change defined(GC_PTHREADS) to NTHREADS>0.
Diffstat (limited to 'tests/weakmap.c')
-rw-r--r-- | tests/weakmap.c | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/tests/weakmap.c b/tests/weakmap.c index a13e3da8..2c379d79 100644 --- a/tests/weakmap.c +++ b/tests/weakmap.c @@ -38,19 +38,19 @@ #ifdef GC_PTHREADS # ifndef NTHREADS -# define NTHREADS 8 +# define NTHREADS 5 /* Excludes main thread, which also runs a test. */ # endif # include <errno.h> /* for EAGAIN, EBUSY */ # include <pthread.h> # include "private/gc_atomic_ops.h" /* for AO_t and AO_fetch_and_add1 */ #else # undef NTHREADS -# define NTHREADS 1 +# define NTHREADS 0 # define AO_t GC_word #endif #define POP_SIZE 200 -#define MUTATE_CNT (700000 / NTHREADS) +#define MUTATE_CNT (700000 / (NTHREADS+1)) #define GROW_LIMIT (MUTATE_CNT / 10) #define WEAKMAP_CAPACITY 256 @@ -412,7 +412,7 @@ void *test(void *data) int main(void) { unsigned weakobj_kind; -# ifdef GC_PTHREADS +# if NTHREADS > 0 int i, n; pthread_t th[NTHREADS]; # endif @@ -435,7 +435,7 @@ int main(void) pair_hcset = weakmap_new(WEAKMAP_CAPACITY, sizeof(struct pair_key), sizeof(struct pair), weakobj_kind); -# ifdef GC_PTHREADS +# if NTHREADS > 0 for (i = 0; i < NTHREADS; ++i) { int err = pthread_create(&th[i], NULL, test, NULL); if (err != 0) { @@ -446,6 +446,9 @@ int main(void) } } n = i; +# endif + (void)test(NULL); +# if NTHREADS > 0 for (i = 0; i < n; ++i) { int err = pthread_join(th[i], NULL); if (err != 0) { @@ -453,8 +456,6 @@ int main(void) exit(69); } } -# else - (void)test(NULL); # endif weakmap_destroy(pair_hcset); printf("%u added, %u found; %u removed, %u locked, %u marked; %u remains\n", |