summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorIvan Maidanski <ivmai@mail.ru>2011-08-31 17:01:42 +0200
committerIvan Maidanski <ivmai@mail.ru>2011-09-12 12:23:56 +0200
commit005792c614d9932735290e9314a3db0d5e757fda (patch)
tree65a9ac50a509917f9cb9f5a05fd51745c40a0e6b /tests
parent650921e4ae058968f3c720d16716bb1bced4d16b (diff)
FIX: MinGW/MingwCE: Use CreateThread in initsecondarythread test and
thread_leak_test. * tests/initsecondarythread.c: Include windows.h instead of pthread.h unless GC_PTHREADS. * tests/thread_leak_test.c: Likewise. * tests/initsecondarythread.c (thread): Use WINAPI and set return type to DWORD unless GC_PTHREADS. * tests/thread_leak_test.c (test): Likewise. * tests/initsecondarythread.c (main): Use HANDLE, CreateThread and WaitForSingleObject instead of pthread_t, pthread_create and pthread_join, respectively, unless GC_PTHREADS. * tests/thread_leak_test.c (main): Likewise.
Diffstat (limited to 'tests')
-rw-r--r--tests/initsecondarythread.c57
-rw-r--r--tests/thread_leak_test.c54
2 files changed, 90 insertions, 21 deletions
diff --git a/tests/initsecondarythread.c b/tests/initsecondarythread.c
index 054d672..f6a8117 100644
--- a/tests/initsecondarythread.c
+++ b/tests/initsecondarythread.c
@@ -24,25 +24,42 @@
#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)) \
@@ -53,13 +70,27 @@ int main(void)
/* 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;
}
diff --git a/tests/thread_leak_test.c b/tests/thread_leak_test.c
index df363a5..3c3fc1e 100644
--- a/tests/thread_leak_test.c
+++ b/tests/thread_leak_test.c
@@ -1,11 +1,24 @@
+
#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) {
@@ -15,28 +28,53 @@ void * test(void * arg) {
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();