diff options
-rw-r--r-- | ChangeLog | 13 | ||||
-rw-r--r-- | create.c | 29 | ||||
-rw-r--r-- | global.c | 2 | ||||
-rw-r--r-- | implement.h | 2 | ||||
-rw-r--r-- | sync.c | 12 |
5 files changed, 44 insertions, 14 deletions
@@ -1,5 +1,18 @@ Sun Jul 26 00:09:59 1998 Ross Johnson <rpj@ixobrychus.canberra.edu.au> + * sync.c: Rename all instances of _pthread_count_mutex to + _pthread_table_mutex. + + * implement.h: Rename _pthread_count_mutex to + _pthread_table_mutex. + + * global.c: Rename _pthread_count_mutex to + _pthread_table_mutex. + + * create.c (pthread_create): Add critical sections. + (_pthread_start_call): Rename _pthread_count_mutex to + _pthread_table_mutex. + * cancel.c (pthread_setcancelstate): Fix indirection bug and rename "this" to "us". @@ -52,7 +52,7 @@ _pthread_start_call(void * us_arg) was called and there are no waiting joins. */ /* CRITICAL SECTION */ - pthread_mutex_lock(&_pthread_count_mutex); + pthread_mutex_lock(&_pthread_table_mutex); if (us->detach == TRUE && us->join_count == 0) @@ -60,7 +60,7 @@ _pthread_start_call(void * us_arg) _pthread_delete_thread_entry(us); } - pthread_mutex_lock(&_pthread_count_mutex); + pthread_mutex_lock(&_pthread_table_mutex); /* END CRITICAL SECTION */ } else @@ -73,7 +73,7 @@ _pthread_start_call(void * us_arg) was called and there are no waiting joins. */ /* CRITICAL SECTION */ - pthread_mutex_lock(&_pthread_count_mutex); + pthread_mutex_lock(&_pthread_table_mutex); if (us->detach == TRUE && us->join_count == 0) @@ -81,7 +81,7 @@ _pthread_start_call(void * us_arg) _pthread_delete_thread_entry(us); } - pthread_mutex_lock(&_pthread_count_mutex); + pthread_mutex_lock(&_pthread_table_mutex); /* END CRITICAL SECTION */ ret = 0; @@ -105,9 +105,17 @@ pthread_create(pthread_t *thread, pthread_attr_t * attr_copy; _pthread_threads_thread_t * us; /* Success unless otherwise set. */ - int ret = 0; + int ret; - if (_pthread_new_thread_entry((pthread_t) handle, us) == 0) + /* CRITICAL SECTION */ + pthread_mutex_lock(&_pthread_table_mutex); + + ret = _pthread_new_thread_entry((pthread_t) handle, us); + + pthread_mutex_lock(&_pthread_table_mutex); + /* END CRITICAL SECTION */ + + if (ret == 0) { attr_copy = &(us->attr); @@ -154,9 +162,18 @@ pthread_create(pthread_t *thread, } else { + /* CRITICAL SECTION */ + pthread_mutex_lock(&_pthread_table_mutex); + /* Remove the failed thread entry. */ _pthread_delete_thread_entry(us); + + pthread_mutex_lock(&_pthread_table_mutex); + /* END CRITICAL SECTION */ } return ret; } + + + @@ -34,7 +34,7 @@ const int _pthread_cancel_asynchronous = 0; const int _pthread_cancel_deferred = 1; -pthread_mutex_t _pthread_count_mutex = PTHREAD_MUTEX_INITIALIZER; +pthread_mutex_t _pthread_table_mutex = PTHREAD_MUTEX_INITIALIZER; DWORD _pthread_threads_count = 0; diff --git a/implement.h b/implement.h index 7c6c6d2..cde8a33 100644 --- a/implement.h +++ b/implement.h @@ -116,7 +116,7 @@ void _pthread_vacuum(void); /* Global data declared in global.c */ -extern pthread_mutex_t _pthread_count_mutex; +extern pthread_mutex_t _pthread_table_mutex; extern DWORD _pthread_threads_count; @@ -76,7 +76,7 @@ pthread_join(pthread_t thread, void ** valueptr) target_thread_mutex = _PTHREAD_THREAD_MUTEX(target); /* CRITICAL SECTION */ - pthread_mutex_lock(&_pthread_count_mutex); + pthread_mutex_lock(&_pthread_table_mutex); /* If the thread is in DETACHED state, then join will return immediately. */ @@ -89,7 +89,7 @@ pthread_join(pthread_t thread, void ** valueptr) target->join_count++; - pthread_mutex_lock(&_pthread_count_mutex); + pthread_mutex_lock(&_pthread_table_mutex); /* END CRITICAL SECTION */ /* CANCELATION POINT */ @@ -116,7 +116,7 @@ pthread_join(pthread_t thread, void ** valueptr) following critical section. */ /* CRITICAL SECTION */ - pthread_mutex_lock(&_pthread_count_mutex); + pthread_mutex_lock(&_pthread_table_mutex); /* Collect the value pointer passed to pthread_exit(). If another thread detaches our target thread while we're @@ -144,7 +144,7 @@ pthread_join(pthread_t thread, void ** valueptr) _pthread_delete_thread_entry(target); } - pthread_mutex_lock(&_pthread_count_mutex); + pthread_mutex_lock(&_pthread_table_mutex); /* END CRITICAL SECTION */ return ret; @@ -163,7 +163,7 @@ pthread_detach(pthread_t thread) pthread_mutex_t * target_thread_mutex; /* CRITICAL SECTION */ - pthread_mutex_lock(&_pthread_count_mutex); + pthread_mutex_lock(&_pthread_table_mutex); target = _pthread_find_thread_entry(thread); @@ -195,7 +195,7 @@ pthread_detach(pthread_t thread) } } - pthread_mutex_unlock(&_pthread_count_mutex); + pthread_mutex_unlock(&_pthread_table_mutex); /* END CRITICAL SECTION */ return ret; |