From: Klas Lindfors Date: Thu, 20 Sep 2012 08:35:05 +0000 (+0200) Subject: make the thread test work on windows X-Git-Tag: v1.8.0~27 X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=208f46d8bf8feb9f677ed3e4f1e4169dbaa270e1;p=yubikey-personalization make the thread test work on windows --- diff --git a/tests/test_threaded_calls.c b/tests/test_threaded_calls.c index 0ed1c74..5e11568 100644 --- a/tests/test_threaded_calls.c +++ b/tests/test_threaded_calls.c @@ -30,10 +30,23 @@ #include #include -#include #include #include +#ifdef _WIN32 +#include +#include +#define ALLOC_THREADS(size) HANDLE *threads = malloc(sizeof(HANDLE) * times) +#define spawn_thread(thread, attr, start_routine, arg) thread = CreateThread(attr, 0, start_routine, arg, 0, NULL) +#define join_thread(thread, retval) WaitForSingleObject(thread, INFINITE) +#else +#include +#define ALLOC_THREADS(size) pthread_t *threads = malloc(sizeof(pthread_t) * times) +#define spawn_thread(thread, attr, start_routine, arg) pthread_create(&thread, attr, start_routine, arg) +#define join_thread(thread, retval) pthread_join(thread, retval) +#endif +#define FREE_THREADS free(threads) + #include void *start_thread(void *arg) @@ -61,14 +74,14 @@ void _test_threaded_calls() { int times = 5; int i; - pthread_t *threads = malloc(sizeof(pthread_t) * times); + ALLOC_THREADS(times); for(i = 0; i < times; i++) { - pthread_create(&threads[i], NULL, start_thread, NULL); - pthread_join(threads[i], NULL); + spawn_thread(threads[i], NULL, start_thread, NULL); + join_thread(threads[i], NULL); } - free(threads); + FREE_THREADS; } int main(void)