From a378d97dc9d9eadaef00a9f01816948db5f3a796 Mon Sep 17 00:00:00 2001 From: rpj Date: Tue, 4 Jan 2000 10:19:28 +0000 Subject: Main changes (see ChangeLog diff for details and attributions):- - asynchronous cancellation added - attempt to hide internal exceptions from applications - kernel32 load/free problem fixed - new tests - changes only to comments in some tests --- misc.c | 44 +++++++++++++++++++++++++++++++++++++++----- 1 file changed, 39 insertions(+), 5 deletions(-) (limited to 'misc.c') diff --git a/misc.c b/misc.c index 84dc6eb..6087a6b 100644 --- a/misc.c +++ b/misc.c @@ -154,17 +154,30 @@ pthread_self (void) * Need to create an implicit 'self' for the currently * executing thread. */ - self = (pthread_t) calloc (1, sizeof (*self)); + self = _pthread_new(); if (self != NULL) { + /* + * This is a non-POSIX thread which has chosen to call + * a POSIX threads function for some reason. We assume that + * it isn't joinable, but we do assume that it's + * (deferred) cancelable. + */ self->implicit = 1; self->detachState = PTHREAD_CREATE_DETACHED; - self->thread = GetCurrentThreadId (); #ifdef NEED_DUPLICATEHANDLE - /* DuplicateHandle does not exist on WinCE */ + /* + * DuplicateHandle does not exist on WinCE. + * + * NOTE: + * GetCurrentThread only returns a pseudo-handle + * which is only valid in the current thread context. + * Therefore, you should not use pass the handle to + * other threads for whatever purpose. + */ self->threadH = GetCurrentThread(); #else if( !DuplicateHandle( @@ -366,9 +379,30 @@ pthreadCancelableTimedWait (HANDLE waitHandle, DWORD timeout) return (CancelableWait(waitHandle, timeout)); } + +pthread_t +_pthread_new (void) +{ + pthread_t new; + + new = (pthread_t) calloc (1, sizeof (*new)); + + if (new != NULL) + { + new->detachState = PTHREAD_CREATE_JOINABLE; + new->cancelState = PTHREAD_CANCEL_ENABLE; + new->cancelType = PTHREAD_CANCEL_DEFERRED; + new->cancelLock = PTHREAD_MUTEX_INITIALIZER; + } + + return new; + +} + + #ifdef NEED_CALLOC -void -*_pthread_calloc(size_t n, size_t s) { +void * +_pthread_calloc(size_t n, size_t s) { unsigned int m = n*s; void *p; -- cgit v1.2.3