diff options
author | marha <marha@users.sourceforge.net> | 2013-02-13 10:41:10 +0100 |
---|---|---|
committer | marha <marha@users.sourceforge.net> | 2013-02-13 10:41:10 +0100 |
commit | b41f74438672dd682bc01ae818cb3da654f22c1e (patch) | |
tree | 07674ef1368a5427a75080528d8cee74234f6b28 /pthreads/create.c | |
parent | aaf21968deb85b635cb6aa6544df233ea5981346 (diff) | |
download | vcxsrv-b41f74438672dd682bc01ae818cb3da654f22c1e.tar.gz vcxsrv-b41f74438672dd682bc01ae818cb3da654f22c1e.tar.bz2 vcxsrv-b41f74438672dd682bc01ae818cb3da654f22c1e.zip |
Updated to latest CVS version of pthreads
Diffstat (limited to 'pthreads/create.c')
-rw-r--r-- | pthreads/create.c | 102 |
1 files changed, 55 insertions, 47 deletions
diff --git a/pthreads/create.c b/pthreads/create.c index e15418588..f63ca0a92 100644 --- a/pthreads/create.c +++ b/pthreads/create.c @@ -9,32 +9,37 @@ * * Pthreads-win32 - POSIX Threads Library for Win32 * Copyright(C) 1998 John E. Bossom - * Copyright(C) 1999,2005 Pthreads-win32 contributors - * - * Contact Email: rpj@callisto.canberra.edu.au - * + * Copyright(C) 1999,2012 Pthreads-win32 contributors + * + * Homepage1: http://sourceware.org/pthreads-win32/ + * Homepage2: http://sourceforge.net/projects/pthreads4w/ + * * The current list of contributors is contained * in the file CONTRIBUTORS included with the source * code distribution. The list can also be seen at the * following World Wide Web location: * http://sources.redhat.com/pthreads-win32/contributors.html - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * + * * You should have received a copy of the GNU Lesser General Public * License along with this library in the file COPYING.LIB; * if not, write to the Free Software Foundation, Inc., * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ +#ifdef HAVE_CONFIG_H +# include <config.h> +#endif + #include "pthread.h" #include "implement.h" #if ! defined(_UWIN) && ! defined(WINCE) @@ -44,7 +49,7 @@ int pthread_create (pthread_t * tid, const pthread_attr_t * attr, - void *(*start) (void *), void *arg) + void *(PTW32_CDECL *start) (void *), void *arg) /* * ------------------------------------------------------ * DOCPUBLIC @@ -85,6 +90,7 @@ pthread_create (pthread_t * tid, { pthread_t thread; ptw32_thread_t * tp; + ptw32_thread_t * sp; register pthread_attr_t a; HANDLE threadH = 0; int result = EAGAIN; @@ -92,7 +98,6 @@ pthread_create (pthread_t * tid, ThreadParms *parms = NULL; unsigned int stackSize; int priority; - pthread_t self; /* * Before doing anything, check that tid can be stored through @@ -102,6 +107,11 @@ pthread_create (pthread_t * tid, */ tid->x = 0; + if (NULL == (sp = (ptw32_thread_t *)pthread_self().p)) + { + goto FAIL0; + } + if (attr != NULL) { a = *attr; @@ -129,16 +139,13 @@ pthread_create (pthread_t * tid, parms->start = start; parms->arg = arg; -#if defined(HAVE_SIGSET_T) - /* - * Threads inherit their initial sigmask from their creator thread. + * Threads inherit their initial sigmask and CPU affinity from their creator thread. */ - self = pthread_self(); - tp->sigmask = ((ptw32_thread_t *)self.p)->sigmask; - -#endif /* HAVE_SIGSET_T */ - +#if defined(HAVE_SIGSET_T) + tp->sigmask = sp->sigmask; +#endif + tp->cpuset = sp->cpuset; if (a != NULL) { @@ -164,17 +171,14 @@ pthread_create (pthread_t * tid, * PTHREAD_EXPLICIT_SCHED and priority THREAD_PRIORITY_NORMAL. */ if (PTHREAD_INHERIT_SCHED == a->inheritsched) - { - /* - * If the thread that called pthread_create() is a Win32 thread - * then the inherited priority could be the result of a temporary - * system adjustment. This is not the case for POSIX threads. - */ -#if ! defined(HAVE_SIGSET_T) - self = pthread_self (); -#endif - priority = ((ptw32_thread_t *) self.p)->sched_priority; - } + { + /* + * If the thread that called pthread_create() is a Win32 thread + * then the inherited priority could be the result of a temporary + * system adjustment. This is not the case for POSIX threads. + */ + priority = sp->sched_priority; + } #endif @@ -200,7 +204,7 @@ pthread_create (pthread_t * tid, * finished with it here. */ -#if ! (defined (__MINGW64__) || defined(__MINGW32__)) || defined (__MSVCRT__) || defined (__DMC__) +#if ! defined (PTW32_CONFIG_MINGW) || defined (__MSVCRT__) || defined (__DMC__) tp->threadH = threadH = @@ -215,14 +219,16 @@ pthread_create (pthread_t * tid, if (threadH != 0) { if (a != NULL) - { - (void) ptw32_setthreadpriority (thread, SCHED_OTHER, priority); - } + { + (void) ptw32_setthreadpriority (thread, SCHED_OTHER, priority); + } + + SetThreadAffinityMask(tp->threadH, tp->cpuset); if (run) - { - ResumeThread (threadH); - } + { + ResumeThread (threadH); + } } #else @@ -251,19 +257,21 @@ pthread_create (pthread_t * tid, else { if (!run) - { - /* - * beginthread does not allow for create flags, so we do it now. - * Note that beginthread itself creates the thread in SUSPENDED - * mode, and then calls ResumeThread to start it. - */ - SuspendThread (threadH); - } - + { + /* + * beginthread does not allow for create flags, so we do it now. + * Note that beginthread itself creates the thread in SUSPENDED + * mode, and then calls ResumeThread to start it. + */ + SuspendThread (threadH); + } + if (a != NULL) - { - (void) ptw32_setthreadpriority (thread, SCHED_OTHER, priority); - } + { + (void) ptw32_setthreadpriority (thread, SCHED_OTHER, priority); + } + + SetThreadAffinityMask(tp->threadH, tp->cpuset); } ptw32_mcs_lock_release (&stateLock); |