diff options
author | rpj <rpj> | 2000-01-04 10:19:28 +0000 |
---|---|---|
committer | rpj <rpj> | 2000-01-04 10:19:28 +0000 |
commit | a378d97dc9d9eadaef00a9f01816948db5f3a796 (patch) | |
tree | 654435cc0a85156c2a9b4793ab7d8e0da8424e32 /misc.c | |
parent | 27d833666dfd72cc6e74c3900d3e8e66321bea3a (diff) |
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
Diffstat (limited to 'misc.c')
-rw-r--r-- | misc.c | 44 |
1 files changed, 39 insertions, 5 deletions
@@ -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; |