diff options
author | rpj <rpj> | 1998-07-25 14:26:49 +0000 |
---|---|---|
committer | rpj <rpj> | 1998-07-25 14:26:49 +0000 |
commit | ee95385721e0dbd4ba637e78b30101f1c9d24e75 (patch) | |
tree | 679e77e5555d60e74d3b748be295a67c3b13e9d6 /sync.c | |
parent | 74c0f91a6baa41a437cf2b45a209d5041820c131 (diff) |
Sun Jul 26 00:09:59 1998 Ross Johnson <rpj@ixobrychus.canberra.edu.au>
* private.c (_pthread_delete_thread_entry): Mutex locks removed.
Mutexes must be applied at the caller level.
(_pthread_new_thread_entry): Ditto.
(_pthread_new_thread_entry): Init cancelstate, canceltype, and
cancel_pending to default values.
(_pthread_new_thread_entry): Rename "this" to "new".
(_pthread_find_thread_entry): Rename "this" to "entry".
(_pthread_delete_thread_entry): Rename "thread_entry" to "entry".
* create.c (_pthread_start_call): Mutexes changed to
_pthread_count_mutex. All access to the threads table entries is
under the one mutex. Otherwise chaos reigns.
Sat Jul 25 23:16:51 1998 Ross Johnson <rpj@ixobrychus.canberra.edu.au>
* implement.h (_pthread_threads_thread): Move cancelstate and
canceltype members out of pthread_attr_t into here.
Diffstat (limited to 'sync.c')
-rw-r--r-- | sync.c | 56 |
1 files changed, 40 insertions, 16 deletions
@@ -76,21 +76,25 @@ pthread_join(pthread_t thread, void ** valueptr) target_thread_mutex = _PTHREAD_THREAD_MUTEX(target); /* CRITICAL SECTION */ - pthread_mutex_lock(target_thread_mutex); + pthread_mutex_lock(&_pthread_count_mutex); /* If the thread is in DETACHED state, then join will return immediately. */ - if (target->detach == TRUE) + if (pthread_attr_getdetachedstate(&(target->attr), &detachstate) != 0 + || detachstate == PTHREAD_CREATE_DETACHED) { return EINVAL; } target->join_count++; - pthread_mutex_lock(target_thread_mutex); + pthread_mutex_lock(&_pthread_count_mutex); /* END CRITICAL SECTION */ + /* CANCELATION POINT */ + pthread_testcancel(); + /* Wait on the kernel thread object. */ switch (WaitForSingleObject(thread, INFINITE)) { @@ -152,26 +156,46 @@ pthread_join(pthread_t thread, void ** valueptr) int pthread_detach(pthread_t thread) { - _pthread_threads_thread_t * this; + _pthread_threads_thread_t * target; int detachstate; + int ret; + pthread_mutex_t * target_thread_mutex; - this = _pthread_find_thread_entry(thread); + /* CRITICAL SECTION */ + pthread_mutex_lock(&_pthread_count_mutex); - if (this == NULL) + target = _pthread_find_thread_entry(thread); + + if (target == NULL) { - return ESRCH; + ret = ESRCH; } - - /* Check that we can detach this thread. */ - if (pthread_attr_getdetachedstate(&(this->attr), &detachstate) != 0 - || detachstate == PTHREAD_CREATE_DETACHED) + else { - return EINVAL; + + target_thread_mutex = _PTHREAD_THREAD_MUTEX(target); + + /* Check that we can detach this thread. */ + if (pthread_attr_getdetachedstate(&(target->attr), &detachstate) != 0 + || detachstate == PTHREAD_CREATE_DETACHED) + { + ret = EINVAL; + } + else + { + + /* This is all we do here - the rest is done either when the + thread exits or when pthread_join() exits. Once this is + set it will never be unset. */ + pthread_attr_setdetachedstate(&(this->attr), + PTHREAD_CREATE_DETACHED); + + ret = 0; + } } - /* This is all we do here - the rest is done either when the thread - exits or when pthread_join() exits. */ - this->detach = TRUE; + pthread_mutex_unlock(&_pthread_count_mutex); + /* END CRITICAL SECTION */ - return 0; + return ret; } |