]>
Commit | Line | Data |
---|---|---|
a78e148b | 1 | /* |
2 | * This header should be included by tests, rather than directly including | |
3 | * jemalloc/jemalloc.h, because --with-install-suffix may cause the header to | |
4 | * have a different name. | |
5 | */ | |
6 | #include "jemalloc/jemalloc@install_suffix@.h" | |
ad4c0b41 | 7 | #include "jemalloc/internal/jemalloc_internal.h" |
8 | ||
9 | /* Abstraction layer for threading in tests */ | |
10 | #ifdef _WIN32 | |
11 | #include <windows.h> | |
12 | ||
13 | typedef HANDLE je_thread_t; | |
14 | ||
15 | void | |
16 | je_thread_create(je_thread_t *thread, void *(*proc)(void *), void *arg) | |
17 | { | |
18 | LPTHREAD_START_ROUTINE routine = (LPTHREAD_START_ROUTINE)proc; | |
19 | *thread = CreateThread(NULL, 0, routine, arg, 0, NULL); | |
20 | if (*thread == NULL) { | |
21 | malloc_printf("Error in CreateThread()\n"); | |
22 | exit(1); | |
23 | } | |
24 | } | |
25 | ||
26 | void | |
27 | je_thread_join(je_thread_t thread, void **ret) | |
28 | { | |
29 | WaitForSingleObject(thread, INFINITE); | |
30 | } | |
31 | ||
32 | #else | |
33 | #include <pthread.h> | |
34 | ||
35 | typedef pthread_t je_thread_t; | |
36 | ||
37 | void | |
38 | je_thread_create(je_thread_t *thread, void *(*proc)(void *), void *arg) | |
39 | { | |
40 | ||
41 | if (pthread_create(thread, NULL, proc, arg) != 0) { | |
42 | malloc_printf("Error in pthread_create()\n"); | |
43 | exit(1); | |
44 | } | |
45 | } | |
46 | ||
47 | void | |
48 | je_thread_join(je_thread_t thread, void **ret) | |
49 | { | |
50 | ||
51 | pthread_join(thread, ret); | |
52 | } | |
53 | #endif |