summaryrefslogtreecommitdiff
path: root/create.c
diff options
context:
space:
mode:
authorrpj <rpj>2011-03-24 23:33:14 +0000
committerrpj <rpj>2011-03-24 23:33:14 +0000
commitdb171f2f9435b98f05f33fcbc0dcf0c5cc1cb917 (patch)
tree9d617a20a9e0ad1fcf415e353057c53e6d77d0f3 /create.c
parente5229a33f8724a90cbb0b56c3ecc1d6691bf54d7 (diff)
First pass of robust mutexes
Diffstat (limited to 'create.c')
-rw-r--r--create.c79
1 files changed, 41 insertions, 38 deletions
diff --git a/create.c b/create.c
index dfc6967..a67d227 100644
--- a/create.c
+++ b/create.c
@@ -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;