summaryrefslogtreecommitdiff
path: root/private.c
diff options
context:
space:
mode:
authorrpj <rpj>1998-07-23 14:55:59 +0000
committerrpj <rpj>1998-07-23 14:55:59 +0000
commita7d20a157ab17cd479c2a4af62e67ac4f6349cb0 (patch)
tree008060c61e40cd31cd49619cc2cd168a983b1118 /private.c
parent55d4602d22dc7d8fb274df3abeb19b2d16230ff1 (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
Diffstat (limited to 'private.c')
-rw-r--r--private.c65
1 files changed, 31 insertions, 34 deletions
diff --git a/private.c b/private.c
index 77f0334..4e5f9ed 100644
--- a/private.c
+++ b/private.c
@@ -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 */
}
-