diff --git a/test/allocated.c b/test/allocated.c index 81cd4ca9..00039ed8 100644 --- a/test/allocated.c +++ b/test/allocated.c @@ -2,7 +2,6 @@ #include #include #include -#include #include #include #include @@ -11,7 +10,7 @@ #include "jemalloc_test.h" void * -thread_start(void *arg) +je_thread_start(void *arg) { int err; void *p; @@ -106,33 +105,22 @@ int main(void) { int ret = 0; - pthread_t thread; + je_thread_t thread; malloc_printf("Test begin\n"); - thread_start(NULL); + je_thread_start(NULL); - if (pthread_create(&thread, NULL, thread_start, NULL) - != 0) { - malloc_printf("%s(): Error in pthread_create()\n", __func__); - ret = 1; - goto label_return; - } - pthread_join(thread, (void *)&ret); + je_thread_create(&thread, je_thread_start, NULL); + je_thread_join(thread, (void *)&ret); - thread_start(NULL); + je_thread_start(NULL); - if (pthread_create(&thread, NULL, thread_start, NULL) - != 0) { - malloc_printf("%s(): Error in pthread_create()\n", __func__); - ret = 1; - goto label_return; - } - pthread_join(thread, (void *)&ret); + je_thread_create(&thread, je_thread_start, NULL); + je_thread_join(thread, (void *)&ret); - thread_start(NULL); + je_thread_start(NULL); -label_return: malloc_printf("Test end\n"); return (ret); } diff --git a/test/jemalloc_test.h.in b/test/jemalloc_test.h.in index 58fa08e4..8833a03e 100644 --- a/test/jemalloc_test.h.in +++ b/test/jemalloc_test.h.in @@ -5,3 +5,25 @@ */ #include "jemalloc/jemalloc@install_suffix@.h" #include "jemalloc/internal/jemalloc_internal.h" + +/* Abstraction layer for threading in tests */ +#include + +typedef pthread_t je_thread_t; + +void +je_thread_create(je_thread_t *thread, void *(*proc)(void *), void *arg) +{ + + if (pthread_create(thread, NULL, proc, arg) != 0) { + malloc_printf("Error in pthread_create()\n"); + exit(1); + } +} + +void +je_thread_join(je_thread_t thread, void **ret) +{ + + pthread_join(thread, ret); +} diff --git a/test/thread_arena.c b/test/thread_arena.c index e443b712..98354282 100644 --- a/test/thread_arena.c +++ b/test/thread_arena.c @@ -1,6 +1,5 @@ #include #include -#include #include #include @@ -10,7 +9,7 @@ #define NTHREADS 10 void * -thread_start(void *arg) +je_thread_start(void *arg) { unsigned main_arena_ind = *(unsigned *)arg; void *p; @@ -52,7 +51,7 @@ main(void) unsigned arena_ind; size_t size; int err; - pthread_t threads[NTHREADS]; + je_thread_t threads[NTHREADS]; unsigned i; malloc_printf("Test begin\n"); @@ -72,18 +71,11 @@ main(void) goto label_return; } - for (i = 0; i < NTHREADS; i++) { - if (pthread_create(&threads[i], NULL, thread_start, - (void *)&arena_ind) != 0) { - malloc_printf("%s(): Error in pthread_create()\n", - __func__); - ret = 1; - goto label_return; - } - } + for (i = 0; i < NTHREADS; i++) + je_thread_create(&threads[i], je_thread_start, (void *)&arena_ind); for (i = 0; i < NTHREADS; i++) - pthread_join(threads[i], (void *)&ret); + je_thread_join(threads[i], (void *)&ret); label_return: malloc_printf("Test end\n"); diff --git a/test/thread_tcache_enabled.c b/test/thread_tcache_enabled.c index 59b76a27..9f765841 100644 --- a/test/thread_tcache_enabled.c +++ b/test/thread_tcache_enabled.c @@ -1,7 +1,6 @@ #include #include #include -#include #include #include @@ -9,7 +8,7 @@ #include "jemalloc_test.h" void * -thread_start(void *arg) +je_thread_start(void *arg) { int err; size_t sz; @@ -77,33 +76,22 @@ int main(void) { int ret = 0; - pthread_t thread; + je_thread_t thread; malloc_printf("Test begin\n"); - thread_start(NULL); + je_thread_start(NULL); - if (pthread_create(&thread, NULL, thread_start, NULL) - != 0) { - malloc_printf("%s(): Error in pthread_create()\n", __func__); - ret = 1; - goto label_return; - } - pthread_join(thread, (void *)&ret); + je_thread_create(&thread, je_thread_start, NULL); + je_thread_join(thread, (void *)&ret); - thread_start(NULL); + je_thread_start(NULL); - if (pthread_create(&thread, NULL, thread_start, NULL) - != 0) { - malloc_printf("%s(): Error in pthread_create()\n", __func__); - ret = 1; - goto label_return; - } - pthread_join(thread, (void *)&ret); + je_thread_create(&thread, je_thread_start, NULL); + je_thread_join(thread, (void *)&ret); - thread_start(NULL); + je_thread_start(NULL); -label_return: malloc_printf("Test end\n"); return (ret); }