diff options
| -rw-r--r-- | ChangeLog | 18 | ||||
| -rw-r--r-- | condvar.c | 3 | ||||
| -rw-r--r-- | create.c | 14 | ||||
| -rw-r--r-- | exit.c | 10 | ||||
| -rw-r--r-- | implement.h | 2 | ||||
| -rw-r--r-- | sync.c | 7 | 
6 files changed, 36 insertions, 18 deletions
| @@ -1,5 +1,23 @@  Sun Jul 26 00:09:59 1998  Ross Johnson  <rpj@ixobrychus.canberra.edu.au> +	* condvar.c (cond_wait): Add cancelation point. This applies the +	point to both pthread_cond_wait() and pthread_cond_timedwait(). + +	* exit.c (pthread_exit): Rename "this" to "us". + +	* implement.h: Add comment. + +	* sync.c (pthread_join): I've satisfied myself that pthread_detach() +	does set the detached attribute in the thread entry attributes +	to PTHREAD_CREATE_DETACHED. "if" conditions were changed to test +	that attribute instead of a separate flag. + +	* create.c (pthread_create): Rename "this" to "us". +	(pthread_create): cancelstate and canceltype are not attributes +	so the copy to thread entry attribute storage was removed. +	Only the thread itself can change it's cancelstate or canceltype, +	ie. the thread must exist already. +  	* private.c (_pthread_delete_thread_entry): Mutex locks removed.  	Mutexes must be applied at the caller level.  	(_pthread_new_thread_entry): Ditto. @@ -78,6 +78,9 @@ cond_wait(pthread_cond_t *cv, pthread_mutex_t *mutex, DWORD abstime)        return EINVAL;      } +  /* CANCELATION POINT */ +  pthread_testcancel(); +    /* Avoid race conditions. */    EnterCriticalSection (&cv->waiters_count_lock);    cv->waiters_count_++; @@ -103,13 +103,13 @@ pthread_create(pthread_t *thread,    void *   security = NULL;    DWORD  threadID;    pthread_attr_t * attr_copy; -  _pthread_threads_thread_t * this; +  _pthread_threads_thread_t * us;    /* Success unless otherwise set. */    int ret = 0; -  if (_pthread_new_thread_entry((pthread_t) handle, this) == 0) +  if (_pthread_new_thread_entry((pthread_t) handle, us) == 0)      { -      attr_copy = &(this->attr); +      attr_copy = &(us->attr);        /* Map given attributes otherwise just use default values. */        if (attr != NULL)  @@ -119,8 +119,6 @@ pthread_create(pthread_t *thread,  	      attr_copy->stacksize = PTHREAD_STACK_MIN;  	    } -	  attr_copy->cancelstate = attr->cancelstate; -	  attr_copy->canceltype = attr->canceltype;  	  attr_copy->detachedstate = attr->detachedstate;  	  attr_copy->priority = attr->priority; @@ -129,15 +127,13 @@ pthread_create(pthread_t *thread,  #endif /* HAVE_SIGSET_T */  	} -      this->detach = (attr->detachedstate == PTHREAD_CREATE_DETACHED); -        /* Start running, not suspended. */        flags = 0;        handle = (HANDLE) _beginthreadex(security,  				       attr_copy->stacksize,  				       _pthread_start_call, -				       (void *) this, +				       (void *) us,  				       flags,  				       &threadID); @@ -159,7 +155,7 @@ pthread_create(pthread_t *thread,    else      {        /* Remove the failed thread entry. */ -      _pthread_delete_thread_entry(this); +      _pthread_delete_thread_entry(us);      }    return ret; @@ -33,17 +33,15 @@ _pthread_vacuum(void)  void  pthread_exit(void * value)  { -  _pthread_threads_thread_t * this; - -  this = _PTHREAD_THIS; +  _pthread_threads_thread_t * us = _PTHREAD_THIS;    /* Copy value into the thread entry so it can be given       to any joining threads. */ -  if (this->joinvalueptr != NULL) +  if (us->joinvalueptr != NULL)      { -      this->joinvalueptr = value; +      us->joinvalueptr = value;      }    /* Teleport back to _pthread_start_call() to cleanup and exit. */ -  longjmp(this->call.env, 1); +  longjmp(us->call.env, 1);  } diff --git a/implement.h b/implement.h index 3216573..7c6c6d2 100644 --- a/implement.h +++ b/implement.h @@ -70,6 +70,8 @@ struct _pthread_threads_thread {  						   PTHREAD_CANCEL_DEFERRED */    void **                     joinvalueptr;    int                         join_count; + +  /* These must be kept in this order and together. */    _pthread_handler_node_t *   cleanupstack;    _pthread_handler_node_t *   destructorstack;    _pthread_handler_node_t *   forkpreparestack; @@ -116,7 +116,7 @@ pthread_join(pthread_t thread, void ** valueptr)  	 following critical section. */        /* CRITICAL SECTION */ -      pthread_mutex_lock(target_thread_mutex); +      pthread_mutex_lock(&_pthread_count_mutex);        /* Collect the value pointer passed to pthread_exit().  If  	 another thread detaches our target thread while we're @@ -124,7 +124,8 @@ pthread_join(pthread_t thread, void ** valueptr)  	 pointed to by target->joinvalueptr has been freed or  	 otherwise no longer valid. */ -      if (target->detach == TRUE) +      if (pthread_attr_getdetachedstate(&(target->attr), &detachstate) != 0  +	  || detachstate == PTHREAD_CREATE_DETACHED)  	{  	  ret = EDEADLK;  	} @@ -143,7 +144,7 @@ pthread_join(pthread_t thread, void ** valueptr)  	  _pthread_delete_thread_entry(target);  	} -      pthread_mutex_lock(target_thread_mutex); +      pthread_mutex_lock(&_pthread_count_mutex);        /* END CRITICAL SECTION */        return ret; | 
