// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
-# ifdef __CYGWIN__
+#ifdef __CYGWIN__
#error "don't use the cygwin compiler to build native Windows programs; use MinGW instead"
-#else
-// Exclude the following code from Cygwin builds.
-// Cygwin doesn't implement process.h nor does it support _beginthread.
+#endif
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
-#include <process.h>
#include <stdio.h>
#include <stdlib.h>
-#include <errno.h>
#include "libcgo.h"
#include "libcgo_windows.h"
}
void
-x_cgo_sys_thread_create(void (*func)(void*), void* arg) {
+x_cgo_sys_thread_create(unsigned long (__stdcall *func)(void*), void* arg) {
_cgo_beginthread(func, arg);
}
return ret;
}
-void _cgo_beginthread(void (*func)(void*), void* arg) {
+void _cgo_beginthread(unsigned long (__stdcall *func)(void*), void* arg) {
int tries;
- uintptr_t thandle;
+ HANDLE thandle;
for (tries = 0; tries < 20; tries++) {
- thandle = _beginthread(func, 0, arg);
- if (thandle == -1 && errno == EACCES) {
+ thandle = CreateThread(NULL, 0, func, arg, 0, NULL);
+ if (thandle == 0 && GetLastError() == ERROR_NOT_ENOUGH_MEMORY) {
// "Insufficient resources", try again in a bit.
//
// Note that the first Sleep(0) is a yield.
Sleep(tries); // milliseconds
continue;
- } else if (thandle == -1) {
+ } else if (thandle == 0) {
break;
}
+ CloseHandle(thandle);
return; // Success!
}
- fprintf(stderr, "runtime: failed to create new OS thread (%d)\n", errno);
+ fprintf(stderr, "runtime: failed to create new OS thread (%lu)\n", GetLastError());
abort();
}
-
-#endif // __CYGWIN__
\ No newline at end of file
#include "libcgo.h"
#include "libcgo_windows.h"
-static void threadentry(void*);
+static unsigned long __stdcall threadentry(void*);
static void (*setg_gcc)(void*);
static DWORD *tls_g;
}
extern void crosscall1(void (*fn)(void), void (*setg_gcc)(void*), void *g);
-static void
+static unsigned long
+__stdcall
threadentry(void *v)
{
ThreadStart ts;
);
crosscall1(ts.fn, setg_gcc, ts.g);
+ return 0;
}
#include "libcgo.h"
#include "libcgo_windows.h"
-static void threadentry(void*);
+static unsigned long __stdcall threadentry(void*);
static void (*setg_gcc)(void*);
static DWORD *tls_g;
}
extern void crosscall1(void (*fn)(void), void (*setg_gcc)(void*), void *g);
-static void
+static unsigned long
+__stdcall
threadentry(void *v)
{
ThreadStart ts;
);
crosscall1(ts.fn, setg_gcc, (void*)ts.g);
+ return 0;
}
#include "libcgo.h"
#include "libcgo_windows.h"
-static void threadentry(void*);
+static unsigned long __stdcall threadentry(void*);
static void (*setg_gcc)(void*);
void
extern void crosscall1(void (*fn)(void), void (*setg_gcc)(void*), void *g);
-static void
+static unsigned long
+__stdcall
threadentry(void *v)
{
ThreadStart ts;
free(v);
crosscall1(ts.fn, setg_gcc, (void *)ts.g);
+ return 0;
}