1*1208bc7eSAndroid Build Coastguard Worker #include "test/jemalloc_test.h"
2*1208bc7eSAndroid Build Coastguard Worker
3*1208bc7eSAndroid Build Coastguard Worker #ifdef _WIN32
4*1208bc7eSAndroid Build Coastguard Worker void
thd_create(thd_t * thd,void * (* proc)(void *),void * arg)5*1208bc7eSAndroid Build Coastguard Worker thd_create(thd_t *thd, void *(*proc)(void *), void *arg) {
6*1208bc7eSAndroid Build Coastguard Worker LPTHREAD_START_ROUTINE routine = (LPTHREAD_START_ROUTINE)proc;
7*1208bc7eSAndroid Build Coastguard Worker *thd = CreateThread(NULL, 0, routine, arg, 0, NULL);
8*1208bc7eSAndroid Build Coastguard Worker if (*thd == NULL) {
9*1208bc7eSAndroid Build Coastguard Worker test_fail("Error in CreateThread()\n");
10*1208bc7eSAndroid Build Coastguard Worker }
11*1208bc7eSAndroid Build Coastguard Worker }
12*1208bc7eSAndroid Build Coastguard Worker
13*1208bc7eSAndroid Build Coastguard Worker void
thd_join(thd_t thd,void ** ret)14*1208bc7eSAndroid Build Coastguard Worker thd_join(thd_t thd, void **ret) {
15*1208bc7eSAndroid Build Coastguard Worker if (WaitForSingleObject(thd, INFINITE) == WAIT_OBJECT_0 && ret) {
16*1208bc7eSAndroid Build Coastguard Worker DWORD exit_code;
17*1208bc7eSAndroid Build Coastguard Worker GetExitCodeThread(thd, (LPDWORD) &exit_code);
18*1208bc7eSAndroid Build Coastguard Worker *ret = (void *)(uintptr_t)exit_code;
19*1208bc7eSAndroid Build Coastguard Worker }
20*1208bc7eSAndroid Build Coastguard Worker }
21*1208bc7eSAndroid Build Coastguard Worker
22*1208bc7eSAndroid Build Coastguard Worker #else
23*1208bc7eSAndroid Build Coastguard Worker void
thd_create(thd_t * thd,void * (* proc)(void *),void * arg)24*1208bc7eSAndroid Build Coastguard Worker thd_create(thd_t *thd, void *(*proc)(void *), void *arg) {
25*1208bc7eSAndroid Build Coastguard Worker if (pthread_create(thd, NULL, proc, arg) != 0) {
26*1208bc7eSAndroid Build Coastguard Worker test_fail("Error in pthread_create()\n");
27*1208bc7eSAndroid Build Coastguard Worker }
28*1208bc7eSAndroid Build Coastguard Worker }
29*1208bc7eSAndroid Build Coastguard Worker
30*1208bc7eSAndroid Build Coastguard Worker void
thd_join(thd_t thd,void ** ret)31*1208bc7eSAndroid Build Coastguard Worker thd_join(thd_t thd, void **ret) {
32*1208bc7eSAndroid Build Coastguard Worker pthread_join(thd, ret);
33*1208bc7eSAndroid Build Coastguard Worker }
34*1208bc7eSAndroid Build Coastguard Worker #endif
35