summaryrefslogtreecommitdiff
path: root/ptw32_new.c
diff options
context:
space:
mode:
Diffstat (limited to 'ptw32_new.c')
-rw-r--r--ptw32_new.c49
1 files changed, 30 insertions, 19 deletions
diff --git a/ptw32_new.c b/ptw32_new.c
index c2da5d5..21d08ce 100644
--- a/ptw32_new.c
+++ b/ptw32_new.c
@@ -42,37 +42,48 @@ pthread_t
ptw32_new (void)
{
pthread_t t;
+ pthread_t nil = {NULL, 0};
+ ptw32_thread_t * tp;
/*
* If there's a reusable pthread_t then use it.
*/
t = ptw32_threadReusePop ();
- if (NULL == t)
+ if (NULL != t.p)
{
- t = (pthread_t) calloc (1, sizeof (*t));
+ tp = (ptw32_thread_t *) t.p;
}
-
- if (t != NULL)
+ else
{
- t->sched_priority = THREAD_PRIORITY_NORMAL;
- t->detachState = PTHREAD_CREATE_JOINABLE;
- t->cancelState = PTHREAD_CANCEL_ENABLE;
- t->cancelType = PTHREAD_CANCEL_DEFERRED;
- t->cancelLock = PTHREAD_MUTEX_INITIALIZER;
- t->threadLock = PTHREAD_MUTEX_INITIALIZER;
- t->cancelEvent = CreateEvent (0, (int) PTW32_TRUE, /* manualReset */
- (int) PTW32_FALSE, /* setSignaled */
- NULL);
+ /* No reuse threads available */
+ tp = (ptw32_thread_t *) calloc (1, sizeof(ptw32_thread_t));
- if (t->cancelEvent == NULL)
+ if (tp == NULL)
{
- /*
- * Thread ID structs are never freed.
- */
- ptw32_threadReusePush (t);
- t = NULL;
+ return nil;
}
+
+ /* ptHandle.p needs to point to it's parent ptw32_thread_t. */
+ t.p = tp->ptHandle.p = tp;
+ t.x = tp->ptHandle.x = 0;
+ }
+
+ /* Set default state. */
+ tp->sched_priority = THREAD_PRIORITY_NORMAL;
+ tp->detachState = PTHREAD_CREATE_JOINABLE;
+ tp->cancelState = PTHREAD_CANCEL_ENABLE;
+ tp->cancelType = PTHREAD_CANCEL_DEFERRED;
+ tp->cancelLock = PTHREAD_MUTEX_INITIALIZER;
+ tp->threadLock = PTHREAD_MUTEX_INITIALIZER;
+ tp->cancelEvent = CreateEvent (0, (int) PTW32_TRUE, /* manualReset */
+ (int) PTW32_FALSE, /* setSignaled */
+ NULL);
+
+ if (tp->cancelEvent == NULL)
+ {
+ ptw32_threadReusePush (tp->ptHandle);
+ return nil;
}
return t;