/* Creating and controlling threads.
- Copyright (C) 2005-2008 Free Software Foundation, Inc.
+ Copyright (C) 2005-2011 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
#if USE_WIN32_THREADS
+#include <process.h>
+
/* -------------------------- gl_thread_t datatype -------------------------- */
/* The Thread-Local Storage (TLS) key that allows to access each thread's
/* GetCurrentThread() returns a pseudo-handle, i.e. only a symbolic
identifier, not a real handle. */
if (!DuplicateHandle (GetCurrentProcess (), GetCurrentThread (),
- GetCurrentProcess (), &this_handle,
- 0, FALSE, DUPLICATE_SAME_ACCESS))
+ GetCurrentProcess (), &this_handle,
+ 0, FALSE, DUPLICATE_SAME_ACCESS))
abort ();
return this_handle;
}
if (thread == NULL)
{
/* This happens only in threads that have not been created through
- glthread_create(), such as the main thread. */
+ glthread_create(), such as the main thread. */
for (;;)
- {
- thread =
- (struct gl_thread_struct *)
- malloc (sizeof (struct gl_thread_struct));
- if (thread != NULL)
- break;
- /* Memory allocation failed. There is not much we can do. Have to
- busy-loop, waiting for the availability of memory. */
- Sleep (1);
- }
+ {
+ thread =
+ (struct gl_thread_struct *)
+ malloc (sizeof (struct gl_thread_struct));
+ if (thread != NULL)
+ break;
+ /* Memory allocation failed. There is not much we can do. Have to
+ busy-loop, waiting for the availability of memory. */
+ Sleep (1);
+ }
thread->handle = get_current_thread_handle ();
InitializeCriticalSection (&thread->handle_lock);
/* The main function of a freshly creating thread. It's a wrapper around
the FUNC and ARG arguments passed to glthread_create_func. */
-static DWORD WINAPI
+static unsigned int WINAPI
wrapper_func (void *varg)
{
struct gl_thread_struct *thread = (struct gl_thread_struct *)varg;
thread->arg = arg;
{
- DWORD thread_id;
+ unsigned int thread_id;
HANDLE thread_handle;
- thread_handle =
- CreateThread (NULL, 100000, wrapper_func, thread, 0, &thread_id);
+ thread_handle = (HANDLE)
+ _beginthreadex (NULL, 100000, wrapper_func, thread, 0, &thread_id);
+ /* calls CreateThread with the same arguments */
if (thread_handle == NULL)
{
- DeleteCriticalSection (&thread->handle_lock);
- free (thread);
- return EAGAIN;
+ DeleteCriticalSection (&thread->handle_lock);
+ free (thread);
+ return EAGAIN;
}
EnterCriticalSection (&thread->handle_lock);
{
gl_thread_t thread = gl_thread_self ();
thread->result = retval;
- ExitThread (0);
+ _endthreadex (0); /* calls ExitThread (0) */
+ abort ();
}
#endif