diff options
author | rpj <rpj> | 1998-07-23 14:55:59 +0000 |
---|---|---|
committer | rpj <rpj> | 1998-07-23 14:55:59 +0000 |
commit | a7d20a157ab17cd479c2a4af62e67ac4f6349cb0 (patch) | |
tree | 008060c61e40cd31cd49619cc2cd168a983b1118 | |
parent | 55d4602d22dc7d8fb274df3abeb19b2d16230ff1 (diff) |
Fri Jul 24 00:21:21 1998 Ross Johnson <rpj@ixobrychus.canberra.edu.au>
* create.c (pthread_create): Arg to _pthread_new_thread_entry()
changed. See next entry. Move mutex locks out. Changes made yesterday
and today allow us to start the new thread running rather than
temporarily suspended.
* private.c (_pthread_new_thread_entry): _pthread_thread_table
was changed back to a table of thread structures rather than pointers.
As such we're trading storage for increaded speed. This routine
was modified to work with the new table. Mutex lock put in around
global data accesses.
(_pthread_find_thread_entry): Ditto
(_pthread_delete_thread_entry): Ditto
-rw-r--r-- | ChangeLog | 15 | ||||
-rw-r--r-- | create.c | 45 | ||||
-rw-r--r-- | private.c | 65 |
3 files changed, 61 insertions, 64 deletions
@@ -1,3 +1,18 @@ +Fri Jul 24 00:21:21 1998 Ross Johnson <rpj@ixobrychus.canberra.edu.au> + + * create.c (pthread_create): Arg to _pthread_new_thread_entry() + changed. See next entry. Move mutex locks out. Changes made yesterday + and today allow us to start the new thread running rather than + temporarily suspended. + + * private.c (_pthread_new_thread_entry): _pthread_thread_table + was changed back to a table of thread structures rather than pointers. + As such we're trading storage for increaded speed. This routine + was modified to work with the new table. Mutex lock put in around + global data accesses. + (_pthread_find_thread_entry): Ditto + (_pthread_delete_thread_entry): Ditto + Thu Jul 23 23:25:30 1998 Ross Johnson <rpj@ixobrychus.canberra.edu.au> * global.c: New. Global data objects declared here. These moved from @@ -12,15 +12,20 @@ #include "implement.h" unsigned -_pthread_start_call(void *this) +_pthread_start_call(void * call) { /* We're now in a running thread. Any local variables here are on this threads private stack so we're safe to leave data in them until we leave. */ - unsigned (*func)(void *) = this->call.routine; - void * arg = this->call.arg; + _pthread_call_t * this; + unsigned (*func)(void *); + void * arg; unsigned ret; + this = (_pthread_call_t *) call; + func = call->routine; + arg = call->arg; + ret = (*func)(arg); /* If we get to here then we're returning naturally and haven't @@ -40,30 +45,19 @@ pthread_create(pthread_t *thread, HANDLE handle = NULL; unsigned flags; void * security = NULL; - - /* FIXME: This needs to be moved into process space. - Perhaps into a structure that contains all - per thread info that is Win32 thread specific but - not visible from the pthreads API, and - accessible through HANDLE (or pthread_t). - */ - SECURITY_ATTRIBUTES security_attr; DWORD threadID; - /* Success unless otherwise set. */ - int ret = 0; pthread_attr_t * attr_copy; _pthread_threads_thread_t * this; + /* Success unless otherwise set. */ + int ret = 0; - /* CRITICAL SECTION */ - pthread_mutex_lock(&_pthread_count_mutex); - - if (_pthread_new_thread_entry((pthread_t) handle, &this) == 0) + if (_pthread_new_thread_entry((pthread_t) handle, this) == 0) { attr_copy = &(this->attr); if (attr != NULL) { - /* Map attributes */ + /* Map attributes. */ if (attr_copy->stacksize == 0) { attr_copy->stacksize = PTHREAD_STACK_MIN; @@ -72,15 +66,13 @@ pthread_create(pthread_t *thread, attr_copy->cancelability = attr->cancelability; } - /* Start suspended and resume at the last moment to avoid - race conditions, ie. where a thread may enquire it's - attributes before we finish storing them away. */ - flags = 1; + /* Start running, not suspended. */ + flags = 0; handle = (HANDLE) _beginthreadex(security, attr_copy->stacksize, _pthread_start_call, - (void *) this, + (void *) &(this->call), flags, &threadID); @@ -94,17 +86,10 @@ pthread_create(pthread_t *thread, ret = EAGAIN; } - /* Let others in as soon as possible. */ - pthread_mutex_unlock(&_pthread_count_mutex); - /* END CRITICAL SECTION */ - if (ret == 0) { /* Let the caller know the thread handle. */ *thread = (pthread_t) handle; - - /* POSIX threads are always running after creation. */ - ResumeThread(handle); } else { @@ -25,10 +25,12 @@ */ int -_pthread_new_thread_entry(pthread_t thread, - _pthread_threads_thread_t ** entry) +_pthread_new_thread_entry(pthread_t thread, _pthread_threads_thread_t * entry) { - _pthread_threads_thread_t ** this; + _pthread_threads_thread_t * this; + + /* CRITICAL SECTION */ + pthread_mutex_lock(&_pthread_count_mutex); if (_pthread_threads_count >= PTHREAD_THREADS_MAX) { @@ -37,7 +39,7 @@ _pthread_new_thread_entry(pthread_t thread, this = &_pthread_threads_table[_PTHREAD_HASH_INDEX(thread)]; - while ((*this)->thread != NULL) + while (this->thread != NULL) { this++; @@ -48,45 +50,40 @@ _pthread_new_thread_entry(pthread_t thread, } } - if ((*this)->thread != NULL) + if (this->thread != NULL) { /* INTERNAL ERROR: There should be at least one slot left. */ return ESRCH; } else { - new = (_pthread_threads_thread_t *) malloc(sizeof(_pthread_threads_thread_t)); - - if (new == NULL) - { - return ENOMEM; - } - - new->thread = thread; - pthread_attr_init(&(new->attr)); - new->cleanupstack = NULL; - new->destructorstack = NULL; - new->forkpreparestack = NULL; - new->forkparentstack = NULL; - new->forkchildstack = NULL; - *this = new; + this->thread = thread; + pthread_attr_init(&(this->attr)); + this->cleanupstack = NULL; + this->destructorstack = NULL; + this->forkpreparestack = NULL; + this->forkparentstack = NULL; + this->forkchildstack = NULL; } _pthread_threads_count++; entry = this; + pthread_mutex_unlock(&_pthread_count_mutex); + /* END CRITICAL SECTION */ + return 0; } -_pthread_threads_thread ** +_pthread_threads_thread * _pthread_find_thread_entry(pthread_t thread) { - _pthread_threads_thread_t ** this; - _pthread_threads_thread_t ** start; + _pthread_threads_thread_t * this; + _pthread_threads_thread_t * start; start = this = &_pthread_threads_table[_PTHREAD_HASH_INDEX(thread)]; - while ((*this)->thread != thread) + while (this->thread != thread) { this++; @@ -96,7 +93,7 @@ _pthread_find_thread_entry(pthread_t thread) this = _pthread_threads_table; } - if ((*this)->thread == NULL || this == start) + if (this->thread == NULL || this == start) { /* Failed to find the thread. */ return -1; @@ -107,12 +104,12 @@ _pthread_find_thread_entry(pthread_t thread) } void -_pthread_delete_thread_entry(_pthread_threads_thread_t ** this) +_pthread_delete_thread_entry(_pthread_threads_thread_t * this) { /* We don't check that the thread has been properly cleaned up, so it had better be done already. */ - _pthread_threads_thread ** this; - _pthread_threads_thread ** entry; + _pthread_threads_thread_t * this; + _pthread_threads_thread_t * entry; /* CRITICAL SECTION */ pthread_mutex_lock(&_pthread_count_mutex); @@ -125,12 +122,9 @@ _pthread_delete_thread_entry(_pthread_threads_thread_t ** this) this = _PTHREAD_THIS; } - if (this != NULL) + if (this->thread != NULL) { - entry = this; - /* Do this first to avoid contention and then free the storage. */ - this = NULL; - free(*entry); + this->thread = NULL; if (_pthread_threads_count > 0) { @@ -141,8 +135,11 @@ _pthread_delete_thread_entry(_pthread_threads_thread_t ** this) /* FIXME: INTERNAL ERROR: This should not happen. */ } } + else + { + /* FIXME: INTERNAL ERROR: This should not happen. */ + } pthread_mutex_unlock(&_pthread_count_mutex); /* END CRITICAL SECTION */ } - |