Add an abstraction layer for threading in tests
This commit is contained in:
parent
188da7c3f5
commit
e38e45743f
@ -2,7 +2,6 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <pthread.h>
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
@ -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);
|
||||
}
|
||||
|
@ -5,3 +5,25 @@
|
||||
*/
|
||||
#include "jemalloc/jemalloc@install_suffix@.h"
|
||||
#include "jemalloc/internal/jemalloc_internal.h"
|
||||
|
||||
/* Abstraction layer for threading in tests */
|
||||
#include <pthread.h>
|
||||
|
||||
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);
|
||||
}
|
||||
|
@ -1,6 +1,5 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <pthread.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
|
||||
@ -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");
|
||||
|
@ -1,7 +1,6 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
#include <pthread.h>
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user