/* Creating and controlling threads.
- Copyright (C) 2005-2008 Free Software Foundation, Inc.
+ Copyright (C) 2005-2012 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
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software Foundation,
- Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
+ along with this program; if not, see <http://www.gnu.org/licenses/>. */
/* Written by Bruno Haible <bruno@clisp.org>, 2005.
Based on GCC's gthr-posix.h, gthr-posix95.h, gthr-solaris.h,
/* ========================================================================= */
-#if USE_WIN32_THREADS
+#if USE_POSIX_THREADS
+
+#include <pthread.h>
+
+#ifdef PTW32_VERSION
+
+const gl_thread_t gl_null_thread /* = { .p = NULL } */;
+
+#endif
+
+#endif
+
+/* ========================================================================= */
+
+#if USE_WINDOWS_THREADS
#include <process.h>
/* 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);
/* 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);