From 95aa0a376d93ee021a6c085c71418e9f16513e0a Mon Sep 17 00:00:00 2001 From: rpj Date: Tue, 22 Dec 1998 15:59:24 +0000 Subject: Sun Dec 20 14:51:58 1998 Ross Johnson * misc.c (pthreadCancelableWait): New function by John Bossom. Non-stand ard but provides a hook that can be used to implement cancellation points in applications that use this library. * pthread.h (pthread_cleanup_pop): C++ (non-WIN32) version uses try/catch to emulate John Bossom's WIN32 __try/__finally behaviour. In the WIN32 version __finally block, add a test for AbnormalTermination otherwise cleanup is only run if the cleanup_pop execute arg is non-zero. Cancella tion should cause the cleanup to run irrespective of the execute arg. * condvar.c (pthread_condattr_init): Replaced by John Bossom's version. (pthread_condattr_destroy): Replaced by John Bossom's version. (pthread_condattr_getpshared): Replaced by John Bossom's version. (pthread_condattr_setpshared): Replaced by John Bossom's version. (pthread_cond_init): Replaced by John Bossom's version. Fix comment (refered to mutex rather than condition variable). (pthread_cond_destroy): Replaced by John Bossom's version. (pthread_cond_wait): Replaced by John Bossom's version. (pthread_cond_timedwait): Replaced by John Bossom's version. (pthread_cond_signal): Replaced by John Bossom's version. (pthread_cond_broadcast): Replaced by John Bossom's version. Thu Dec 17 19:10:46 1998 Ross Johnson * tsd.c (pthread_key_create): Replaced by John Bossom's version. (pthread_key_delete): Replaced by John Bossom's version. (pthread_setspecific): Replaced by John Bossom's version. (pthread_getspecific): Replaced by John Bossom's version. Mon Dec 7 09:44:40 1998 Ross Johnson * cancel.c (pthread_setcancelstate): Replaced by John Bossom's version. (pthread_setcanceltype): Replaced by John Bossom's version. (pthread_testcancel): Replaced by John Bossom's version. (pthread_cancel): Replaced by John Bossom's version. * exit.c (pthread_exit): Replaced by John Bossom's version. * misc.c (pthread_self): Replaced by John Bossom's version. (pthread_equal): Replaced by John Bossom's version. * sync.c (pthread_detach): Replaced by John Bossom's version. (pthread_join): Replaced by John Bossom's version. * create.c (pthread_create): Replaced by John Bossom's version. * private.c (_pthread_processInitialize): New by John Bossom. (_pthread_processTerminate): Non-public function by John Bossom. (_pthread_threadStart): Non-public function by John Bossom. (_pthread_threadDestroy): Non-public function by John Bossom. (_pthread_cleanupStack): Non-public function by John Bossom. (_pthread_tkAssocCreate): Non-public function by John Bossom. (_pthread_tkAssocDestroy): Non-public function by John Bossom. (_pthread_callUserDestroyRoutines): Non-public function by John Bossom. * implement.h: Added John Bossom's non-API structures and declarations. * dll.c (PthreadsEntryPoint): Cast return value of GetProcAddress to resolve compile warning from MSVC. * dll.c (DLLmain): Replaced by John Bossom's version. * dll.c (PthreadsEntryPoint): Re-applied Anders Norlander's patch:- Initialize _pthread_try_enter_critical_section at startup and release kernel32 handle when DLL is being unloaded. --- sync.c | 121 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 121 insertions(+) (limited to 'sync.c') diff --git a/sync.c b/sync.c index 069d10a..3d64df9 100644 --- a/sync.c +++ b/sync.c @@ -6,6 +6,125 @@ * synchronisation. */ +/* + * Code contributed by John E. Bossom . + */ + +int +pthread_detach (pthread_t tid) + /* + * ------------------------------------------------------ + * DOCPUBLIC + * This function detaches the given thread. + * + * PARAMETERS + * thread + * an instance of a pthread_t + * + * + * DESCRIPTION + * This function detaches the given thread. You may + * detach the main thread or to detach a joinable thread + * (You should have used pthread_attr_t to create the + * thread as detached!) + * NOTE: detached threads cannot be joined nor canceled; + * storage is freed immediately on termination. + * + * RESULTS + * 0 successfully detached the thread, + * EINVAL thread is not a joinable thread, + * ENOSPC a required resource has been exhausted, + * ESRCH no thread could be found for 'thread', + * + * ------------------------------------------------------ + */ +{ + int result; + + if (tid == NULL || + tid->detachState == PTHREAD_CREATE_DETACHED) + { + + result = EINVAL; + + } + else + { + result = 0; + tid->detachState = PTHREAD_CREATE_DETACHED; + } + + return (result); + +} /* pthread_detach */ + +int +pthread_join (pthread_t thread, void **value_ptr) + /* + * ------------------------------------------------------ + * DOCPUBLIC + * This function waits for 'thread' to terminate and + * returns the thread's exit value if 'value_ptr' is not + * NULL. This also detaches the thread on successful + * completion. + * + * PARAMETERS + * sem + * pointer to an instance of sem_t + * + * + * DESCRIPTION + * This function waits for 'thread' to terminate and + * returns the thread's exit value if 'value_ptr' is not + * NULL. This also detaches the thread on successful + * completion. + * NOTE: detached threads cannot be joined or canceled + * + * RESULTS + * 0 'thread' has completed + * EINVAL thread is not a joinable thread, + * ESRCH no thread could be found with ID 'thread', + * EDEADLK attempt to join thread with self + * + * ------------------------------------------------------ + */ +{ + int result = 0; + pthread_t self; + + self = pthread_self (); + + if (pthread_equal (self, thread) == 0) + { + result = EDEADLK; + + } + else + { + DWORD stat; + + stat = WaitForSingleObject (thread->threadH, INFINITE); + + if (stat != WAIT_OBJECT_0 && + !GetExitCodeThread (thread->threadH, (LPDWORD) value_ptr)) + { + result = ESRCH; + } + else + { + threadDestroy (thread); + } + } + + return (result); + +} /* pthread_join */ + +/* */ + + +#if 0 /* Pre Bossom */ + #include /* POSIX STANDARD: A thread may pass a value pointer to some data via @@ -186,3 +305,5 @@ pthread_detach(pthread_t thread) return ret; } + +#endif /* Pre Bossom */ -- cgit v1.2.3