diff options
| author | rpj <rpj> | 2011-03-24 23:33:14 +0000 | 
|---|---|---|
| committer | rpj <rpj> | 2011-03-24 23:33:14 +0000 | 
| commit | db171f2f9435b98f05f33fcbc0dcf0c5cc1cb917 (patch) | |
| tree | 9d617a20a9e0ad1fcf415e353057c53e6d77d0f3 /create.c | |
| parent | e5229a33f8724a90cbb0b56c3ecc1d6691bf54d7 (diff) | |
First pass of robust mutexes
Diffstat (limited to 'create.c')
| -rw-r--r-- | create.c | 79 | 
1 files changed, 41 insertions, 38 deletions
| @@ -227,44 +227,47 @@ pthread_create (pthread_t * tid,  #else -  /* -   * This lock will force pthread_threadStart() to wait until we have -   * the thread handle and have set the priority. -   */ -  (void) pthread_mutex_lock (&tp->cancelLock); - -  tp->threadH = -    threadH = -    (HANDLE) _beginthread (ptw32_threadStart, (unsigned) stackSize,	/* default stack size   */ -			   parms); - -  /* -   * Make the return code match _beginthreadex's. -   */ -  if (threadH == (HANDLE) - 1L) -    { -      tp->threadH = threadH = 0; -    } -  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); -	} - -      if (a != NULL) -	{ -	  (void) ptw32_setthreadpriority (thread, SCHED_OTHER, priority); -	} -    } - -  (void) pthread_mutex_unlock (&tp->cancelLock); - +  { +    ptw32_mcs_local_node_t stateLock; + +    /* +     * This lock will force pthread_threadStart() to wait until we have +     * the thread handle and have set the priority. +     */ +    ptw32_mcs_lock_acquire(&tp->stateLock, &stateLock); + +    tp->threadH = +      threadH = +      (HANDLE) _beginthread (ptw32_threadStart, (unsigned) stackSize,	/* default stack size   */ +			     parms); + +    /* +     * Make the return code match _beginthreadex's. +     */ +    if (threadH == (HANDLE) - 1L) +      { +        tp->threadH = threadH = 0; +      } +    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); +	  } +   +        if (a != NULL) +	  { +	    (void) ptw32_setthreadpriority (thread, SCHED_OTHER, priority); +	  } +      } + +    ptw32_mcs_lock_release (&stateLock); +  }  #endif    result = (threadH != 0) ? 0 : EAGAIN; | 
