Add mq (message queue) to test infrastructure.

Add mtx (mutex) to test infrastructure, in order to avoid bootstrapping
complications that would result from directly using malloc_mutex.

Rename test infrastructure's thread abstraction from je_thread to thd.

Fix some header ordering issues.
This commit is contained in:
Jason Evans
2013-12-12 14:41:02 -08:00
parent 19609724f9
commit 0f4f1efd94
21 changed files with 441 additions and 131 deletions

View File

@@ -3,7 +3,7 @@
#define NTHREADS 10
void *
je_thread_start(void *arg)
thd_start(void *arg)
{
unsigned thread_ind = (unsigned)(uintptr_t)arg;
unsigned arena_ind;
@@ -36,16 +36,16 @@ je_thread_start(void *arg)
TEST_BEGIN(test_ALLOCM_ARENA)
{
je_thread_t threads[NTHREADS];
thd_t thds[NTHREADS];
unsigned i;
for (i = 0; i < NTHREADS; i++) {
je_thread_create(&threads[i], je_thread_start,
thd_create(&thds[i], thd_start,
(void *)(uintptr_t)i);
}
for (i = 0; i < NTHREADS; i++)
je_thread_join(threads[i], NULL);
thd_join(thds[i], NULL);
}
TEST_END

View File

@@ -9,7 +9,7 @@ static const bool config_stats =
;
void *
je_thread_start(void *arg)
thd_start(void *arg)
{
int err;
void *p;
@@ -98,16 +98,16 @@ label_ENOENT:
TEST_BEGIN(test_main_thread)
{
je_thread_start(NULL);
thd_start(NULL);
}
TEST_END
TEST_BEGIN(test_subthread)
{
je_thread_t thread;
thd_t thd;
je_thread_create(&thread, je_thread_start, NULL);
je_thread_join(thread, NULL);
thd_create(&thd, thd_start, NULL);
thd_join(thd, NULL);
}
TEST_END

View File

@@ -1,50 +0,0 @@
/*
* This header should be included by tests, rather than directly including
* jemalloc/jemalloc.h, because --with-install-suffix may cause the header to
* have a different name.
*/
#include "jemalloc/jemalloc@install_suffix@.h"
#include "jemalloc/internal/jemalloc_internal.h"
/* Abstraction layer for threading in tests. */
#ifdef _WIN32
#include <windows.h>
typedef HANDLE je_thread_t;
void
je_thread_create(je_thread_t *thread, void *(*proc)(void *), void *arg)
{
LPTHREAD_START_ROUTINE routine = (LPTHREAD_START_ROUTINE)proc;
*thread = CreateThread(NULL, 0, routine, arg, 0, NULL);
if (*thread == NULL)
test_fail("Error in CreateThread()\n");
}
void
je_thread_join(je_thread_t thread, void **ret)
{
WaitForSingleObject(thread, INFINITE);
}
#else
#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)
test_fail("Error in pthread_create()\n");
}
void
je_thread_join(je_thread_t thread, void **ret)
{
pthread_join(thread, ret);
}
#endif

View File

@@ -3,7 +3,7 @@
#define NTHREADS 10
void *
je_thread_start(void *arg)
thd_start(void *arg)
{
unsigned main_arena_ind = *(unsigned *)arg;
void *p;
@@ -43,7 +43,7 @@ TEST_BEGIN(test_thread_arena)
unsigned arena_ind;
size_t size;
int err;
je_thread_t threads[NTHREADS];
thd_t thds[NTHREADS];
unsigned i;
p = malloc(1);
@@ -58,13 +58,13 @@ TEST_BEGIN(test_thread_arena)
}
for (i = 0; i < NTHREADS; i++) {
je_thread_create(&threads[i], je_thread_start,
thd_create(&thds[i], thd_start,
(void *)&arena_ind);
}
for (i = 0; i < NTHREADS; i++) {
intptr_t join_ret;
je_thread_join(threads[i], (void *)&join_ret);
thd_join(thds[i], (void *)&join_ret);
assert_zd_eq(join_ret, 0, "Unexpected thread join error");
}
}

View File

@@ -9,7 +9,7 @@ static const bool config_tcache =
;
void *
je_thread_start(void *arg)
thd_start(void *arg)
{
int err;
size_t sz;
@@ -86,16 +86,16 @@ label_ENOENT:
TEST_BEGIN(test_main_thread)
{
je_thread_start(NULL);
thd_start(NULL);
}
TEST_END
TEST_BEGIN(test_subthread)
{
je_thread_t thread;
thd_t thd;
je_thread_create(&thread, je_thread_start, NULL);
je_thread_join(thread, NULL);
thd_create(&thd, thd_start, NULL);
thd_join(thd, NULL);
}
TEST_END