#include "gc.h"
-#include <pthread.h>
+#ifdef GC_PTHREADS
+# include <pthread.h>
+#else
+# include <windows.h>
+#endif
#include <stdlib.h>
#include <stdio.h>
-static void *thread(void *arg)
+#ifdef GC_PTHREADS
+ static void *thread(void *arg)
+#else
+ static DWORD WINAPI thread(LPVOID arg)
+#endif
{
GC_INIT();
(void)GC_MALLOC(123);
(void)GC_MALLOC(12345);
- return arg;
+# ifdef GC_PTHREADS
+ return arg;
+# else
+ return (DWORD)(GC_word)arg;
+# endif
}
#include "private/gcconfig.h"
int main(void)
{
- int code;
- pthread_t t;
+# ifdef GC_PTHREADS
+ int code;
+ pthread_t t;
+# else
+ HANDLE t;
+ DWORD thread_id;
+# endif
# if !(defined(BEOS) || defined(MSWIN32) || defined(MSWINCE) \
|| defined(CYGWIN32) || defined(GC_OPENBSD_THREADS) \
|| (defined(DARWIN) && !defined(NO_PTHREAD_GET_STACKADDR_NP)) \
/* GC_INIT() must be called from main thread only. */
GC_INIT();
# endif
- if ((code = pthread_create (&t, NULL, thread, NULL)) != 0) {
- printf("Thread creation failed %d\n", code);
- return 1;
- }
- if ((code = pthread_join (t, NULL)) != 0) {
- printf("Thread join failed %d\n", code);
- return 1;
- }
+# ifdef GC_PTHREADS
+ if ((code = pthread_create (&t, NULL, thread, NULL)) != 0) {
+ printf("Thread creation failed %d\n", code);
+ return 1;
+ }
+ if ((code = pthread_join (t, NULL)) != 0) {
+ printf("Thread join failed %d\n", code);
+ return 1;
+ }
+# else
+ t = CreateThread(NULL, 0, thread, 0, 0, &thread_id);
+ if (t == NULL) {
+ printf("Thread creation failed %d\n", (int)GetLastError());
+ return 1;
+ }
+ if (WaitForSingleObject(t, INFINITE) != WAIT_OBJECT_0) {
+ printf("Thread join failed %d\n", (int)GetLastError());
+ CloseHandle(t);
+ return 1;
+ }
+ CloseHandle(t);
+# endif
return 0;
}
+
#ifndef GC_THREADS
-# define GC_THREADS
-#endif /* GC_THREADS */
+# define GC_THREADS
+#endif
+
#include "leak_detector.h"
-#include <pthread.h>
+
+#ifdef GC_PTHREADS
+# include <pthread.h>
+#else
+# include <windows.h>
+#endif
+
#include <stdio.h>
-void * test(void * arg) {
+#ifdef GC_PTHREADS
+ void * test(void * arg)
+#else
+ DWORD WINAPI test(LPVOID arg)
+#endif
+{
int *p[10];
int i;
for (i = 0; i < 10; ++i) {
for (i = 1; i < 10; ++i) {
free(p[i]);
}
- return 0;
+# ifdef GC_PTHREADS
+ return arg;
+# else
+ return (DWORD)(GC_word)arg;
+# endif
}
#define NTHREADS 5
int main(void) {
int i;
- pthread_t t[NTHREADS];
+# ifdef GC_PTHREADS
+ pthread_t t[NTHREADS];
+# else
+ HANDLE t[NTHREADS];
+ DWORD thread_id;
+# endif
int code;
+
GC_set_find_leak(1); /* for new collect versions not compiled */
/* with -DFIND_LEAK. */
GC_INIT();
+
for (i = 0; i < NTHREADS; ++i) {
- if ((code = pthread_create(t + i, 0, test, 0)) != 0) {
+# ifdef GC_PTHREADS
+ code = pthread_create(t + i, 0, test, 0);
+# else
+ t[i] = CreateThread(NULL, 0, test, 0, 0, &thread_id);
+ code = t[i] != NULL ? 0 : (int)GetLastError();
+# endif
+ if (code != 0) {
printf("Thread creation failed %d\n", code);
}
}
+
for (i = 0; i < NTHREADS; ++i) {
- if ((code = pthread_join(t[i], 0)) != 0) {
+# ifdef GC_PTHREADS
+ code = pthread_join(t[i], 0);
+# else
+ code = WaitForSingleObject(t[i], INFINITE) == WAIT_OBJECT_0 ? 0 :
+ (int)GetLastError();
+# endif
+ if (code != 0) {
printf("Thread join failed %d\n", code);
}
}
+
CHECK_LEAKS();
CHECK_LEAKS();
CHECK_LEAKS();