summaryrefslogtreecommitdiff
path: root/create.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 /create.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 'create.c')
-rw-r--r--create.c45
1 files changed, 15 insertions, 30 deletions
diff --git a/create.c b/create.c
index 37ce88f..b4a6c99 100644
--- a/create.c
+++ b/create.c
@@ -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
{