diff options
author | rpj <rpj> | 2004-11-03 01:08:41 +0000 |
---|---|---|
committer | rpj <rpj> | 2004-11-03 01:08:41 +0000 |
commit | ec8290acdaea21b16d98f1ef5d4ae8a28ab2109a (patch) | |
tree | 0bd3750ec1cc12594b6cfe69473e393da6ec101b /ptw32_new.c | |
parent | cccaf0c2c82e78a72d69a4a50c872f308bed2f65 (diff) |
Mutex, semaphore, thread ID, test suite changes - see ChangeLogs
Diffstat (limited to 'ptw32_new.c')
-rw-r--r-- | ptw32_new.c | 49 |
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; |