summaryrefslogtreecommitdiff
path: root/win32_threads.c
diff options
context:
space:
mode:
authorivmai <ivmai>2009-11-01 10:44:56 +0100
committerIvan Maidanski <ivmai@mail.ru>2011-07-26 19:06:51 +0200
commit2c5ab1802c1d530829670037a111a786c5e9193e (patch)
tree0383c754b964a29de2c0c33801d6d184a578e5c5 /win32_threads.c
parent457a7d5ba48508cecb17228fe84c5c757a5ae1c0 (diff)
2009-11-01 Ivan Maidanski <ivmai@mail.ru>
* alloc.c (min_bytes_allocd): Use GC_stackbottom value to compute stack_size even if THREADS. * doc/README.macros (DEBUG_THREADS): Document. * pthread_support.c (DEBUG_THREADS): Remove the commented out definition. * win32_threads.c (DEBUG_WIN32_THREADS): Remove duplicate definition. * win32_threads.c: Include errno.h (except for WinCE). * win32_threads.c (GC_win32_start_inner): Copy "start" and "param" to local variables, and free "arg" parameter before "start" invocation. * win32_threads.c (GC_beginthreadex): Set errno to EAGAIN on error (instead of calling SetLastError(ERROR_NOT_ENOUGH_MEMORY)). * win32_threads.c (GC_beginthreadex): Return 0 on error (instead of -1).
Diffstat (limited to 'win32_threads.c')
-rw-r--r--win32_threads.c25
1 files changed, 13 insertions, 12 deletions
diff --git a/win32_threads.c b/win32_threads.c
index 6fe4feb..1f771cb 100644
--- a/win32_threads.c
+++ b/win32_threads.c
@@ -64,12 +64,6 @@
#else
-# ifdef DEBUG_THREADS
-# define DEBUG_WIN32_THREADS 1
-# else
-# define DEBUG_WIN32_THREADS 0
-# endif
-
# undef CreateThread
# undef ExitThread
# undef _beginthreadex
@@ -89,6 +83,7 @@
# endif
# else
# include <process.h> /* For _beginthreadex, _endthreadex */
+# include <errno.h> /* for errno, EAGAIN */
# endif
#endif
@@ -1939,7 +1934,8 @@ GC_INNER void GC_get_next_stack(char *start, char *limit,
void *arg)
{
void * ret;
- thread_args *args = (thread_args *)arg;
+ LPTHREAD_START_ROUTINE start = ((thread_args *)arg)->start;
+ LPVOID param = ((thread_args *)arg)->param;
GC_register_my_thread(sb); /* This waits for an in-progress GC. */
@@ -1947,6 +1943,8 @@ GC_INNER void GC_get_next_stack(char *start, char *limit,
GC_printf("thread 0x%x starting...\n", (unsigned)GetCurrentThreadId());
# endif
+ GC_free(arg);
+
/* Clear the thread entry even if we exit with an exception. */
/* This is probably pointless, since an uncaught exception is */
/* supposed to result in the process being killed. */
@@ -1954,14 +1952,13 @@ GC_INNER void GC_get_next_stack(char *start, char *limit,
__try
# endif
{
- ret = (void *)(word)args->start(args->param);
+ ret = (void *)(word)(*start)(param);
}
# ifndef __GNUC__
__finally
# endif
{
GC_unregister_my_thread();
- GC_free(args);
}
# if DEBUG_WIN32_THREADS
@@ -2047,10 +2044,14 @@ GC_INNER void GC_get_next_stack(char *start, char *limit,
arglist, initflag, thrdaddr);
} else {
args = GC_malloc_uncollectable(sizeof(thread_args));
- /* Handed off to and deallocated by child thread. */
+ /* Handed off to and deallocated by child thread. */
if (0 == args) {
- SetLastError(ERROR_NOT_ENOUGH_MEMORY);
- return (GC_uintptr_t)(-1L);
+ /* MSDN docs say _beginthreadex() returns 0 on error and sets */
+ /* errno to either EAGAIN (too many threads) or EINVAL (the */
+ /* argument is invalid or the stack size is incorrect), so we */
+ /* set errno to EAGAIN on "not enough memory". */
+ errno = EAGAIN;
+ return 0;
}
/* set up thread arguments */