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