Merged with HEAD from 8/18 or so. unlabeled-3.7.24
authorcls%seawood.org
Fri, 20 Aug 1999 16:21:48 +0000
branchunlabeled-3.7.24
changeset 782 40aa91be6f99
parent 577 9167bdf865c9
push idunknown
push userunknown
push dateunknown
Merged with HEAD from 8/18 or so.
pr/src/pthreads/ptsynch.c
--- a/pr/src/pthreads/ptsynch.c
+++ b/pr/src/pthreads/ptsynch.c
@@ -47,20 +47,20 @@ static pthread_t pt_zero_tid;  /* a null
 /**************************************************************/
 /*****************************LOCKS****************************/
 /**************************************************************/
 /**************************************************************/
 
 void _PR_InitLocks(void)
 {
     int rv;
-    rv = PTHREAD_MUTEXATTR_INIT(&_pt_mattr); 
+    rv = _PT_PTHREAD_MUTEXATTR_INIT(&_pt_mattr); 
     PR_ASSERT(0 == rv);
 
-    rv = PTHREAD_CONDATTR_INIT(&_pt_cvar_attr);
+    rv = _PT_PTHREAD_CONDATTR_INIT(&_pt_cvar_attr);
     PR_ASSERT(0 == rv);
 }
 
 static void pt_PostNotifies(PRLock *lock, PRBool unlock)
 {
     PRIntn index, rv;
     _PT_Notified post;
     _PT_Notified *notified, *prev = NULL;
@@ -130,30 +130,30 @@ PR_IMPLEMENT(PRLock*) PR_NewLock(void)
     PRIntn rv;
     PRLock *lock;
 
     if (!_pr_initialized) _PR_ImplicitInitialization();
 
     lock = PR_NEWZAP(PRLock);
     if (lock != NULL)
     {
-        rv = PTHREAD_MUTEX_INIT(lock->mutex, _pt_mattr); 
+        rv = _PT_PTHREAD_MUTEX_INIT(lock->mutex, _pt_mattr); 
         PR_ASSERT(0 == rv);
     }
 #if defined(DEBUG)
     pt_debug.locks_created += 1;
 #endif
     return lock;
 }  /* PR_NewLock */
 
 PR_IMPLEMENT(void) PR_DestroyLock(PRLock *lock)
 {
     PRIntn rv;
     PR_ASSERT(NULL != lock);
-    PR_ASSERT(PTHREAD_THR_HANDLE_IS_ZERO(lock->owner));
+    PR_ASSERT(_PT_PTHREAD_THR_HANDLE_IS_ZERO(lock->owner));
     PR_ASSERT(0 == lock->notified.length);
     PR_ASSERT(NULL == lock->notified.link);
     rv = pthread_mutex_destroy(&lock->mutex);
     PR_ASSERT(0 == rv);
 #if defined(DEBUG)
     memset(lock, 0xaf, sizeof(PRLock));
     pt_debug.locks_destroyed += 1;
 #endif
@@ -163,35 +163,35 @@ PR_IMPLEMENT(void) PR_DestroyLock(PRLock
 PR_IMPLEMENT(void) PR_Lock(PRLock *lock)
 {
     PRIntn rv;
     PR_ASSERT(lock != NULL);
     rv = pthread_mutex_lock(&lock->mutex);
     PR_ASSERT(0 == rv);
     PR_ASSERT(0 == lock->notified.length);
     PR_ASSERT(NULL == lock->notified.link);
-    PR_ASSERT(PTHREAD_THR_HANDLE_IS_ZERO(lock->owner));
-    PTHREAD_COPY_THR_HANDLE(pthread_self(), lock->owner);
+    PR_ASSERT(_PT_PTHREAD_THR_HANDLE_IS_ZERO(lock->owner));
+    _PT_PTHREAD_COPY_THR_HANDLE(pthread_self(), lock->owner);
 #if defined(DEBUG)
     pt_debug.locks_acquired += 1;
 #endif
 }  /* PR_Lock */
 
 PR_IMPLEMENT(PRStatus) PR_Unlock(PRLock *lock)
 {
     PRIntn rv;
 
     PR_ASSERT(lock != NULL);
-    PR_ASSERT(PTHREAD_MUTEX_IS_LOCKED(lock->mutex));
+    PR_ASSERT(_PT_PTHREAD_MUTEX_IS_LOCKED(lock->mutex));
     PR_ASSERT(pthread_equal(lock->owner, pthread_self()));
 
     if (!pthread_equal(lock->owner, pthread_self()))
         return PR_FAILURE;
 
-    PTHREAD_ZERO_THR_HANDLE(lock->owner);
+    _PT_PTHREAD_ZERO_THR_HANDLE(lock->owner);
     if (0 == lock->notified.length)  /* shortcut */
     {
         rv = pthread_mutex_unlock(&lock->mutex);
         PR_ASSERT(0 == rv);
     }
     else pt_PostNotifies(lock, PR_TRUE);
 
 #if defined(DEBUG)
@@ -253,17 +253,17 @@ static PRIntn pt_TimedWait(
  * MP systems don't contend for a lock that they can't have.
  */
 static void pt_PostNotifyToCvar(PRCondVar *cvar, PRBool broadcast)
 {
     PRIntn index = 0;
     _PT_Notified *notified = &cvar->lock->notified;
 
     PR_ASSERT(pthread_equal(cvar->lock->owner, pthread_self()));
-    PR_ASSERT(PTHREAD_MUTEX_IS_LOCKED(cvar->lock->mutex));
+    PR_ASSERT(_PT_PTHREAD_MUTEX_IS_LOCKED(cvar->lock->mutex));
 
     while (1)
     {
         for (index = 0; index < notified->length; ++index)
         {
             if (notified->cv[index].cv == cvar)
             {
                 if (broadcast)
@@ -293,17 +293,17 @@ finished:
 }  /* pt_PostNotifyToCvar */
 
 PR_IMPLEMENT(PRCondVar*) PR_NewCondVar(PRLock *lock)
 {
     PRCondVar *cv = PR_NEW(PRCondVar);
     PR_ASSERT(lock != NULL);
     if (cv != NULL)
     {
-        int rv = PTHREAD_COND_INIT(cv->cv, _pt_cvar_attr); 
+        int rv = _PT_PTHREAD_COND_INIT(cv->cv, _pt_cvar_attr); 
         PR_ASSERT(0 == rv);
         cv->lock = lock;
         cv->notify_pending = 0;
 #if defined(DEBUG)
         pt_debug.cvars_created += 1;
 #endif
     }
     return cv;
@@ -324,17 +324,17 @@ PR_IMPLEMENT(void) PR_DestroyCondVar(PRC
 
 PR_IMPLEMENT(PRStatus) PR_WaitCondVar(PRCondVar *cvar, PRIntervalTime timeout)
 {
     PRIntn rv;
     PRThread *thred = PR_CurrentThread();
 
     PR_ASSERT(cvar != NULL);
     /* We'd better be locked */
-    PR_ASSERT(PTHREAD_MUTEX_IS_LOCKED(cvar->lock->mutex));
+    PR_ASSERT(_PT_PTHREAD_MUTEX_IS_LOCKED(cvar->lock->mutex));
     /* and it better be by us */
     PR_ASSERT(pthread_equal(cvar->lock->owner, pthread_self()));
 
     if (thred->state & PT_THREAD_ABORTED) goto aborted;
 
     /*
      * The thread waiting is used for PR_Interrupt
      */
@@ -349,26 +349,26 @@ PR_IMPLEMENT(PRStatus) PR_WaitCondVar(PR
      * hold until we actually wait.
      */
     if (0 != cvar->lock->notified.length)
         pt_PostNotifies(cvar->lock, PR_FALSE);
 
     /*
      * We're surrendering the lock, so clear out the owner field.
      */
-    PTHREAD_ZERO_THR_HANDLE(cvar->lock->owner);
+    _PT_PTHREAD_ZERO_THR_HANDLE(cvar->lock->owner);
 
     if (timeout == PR_INTERVAL_NO_TIMEOUT)
         rv = pthread_cond_wait(&cvar->cv, &cvar->lock->mutex);
     else
         rv = pt_TimedWait(&cvar->cv, &cvar->lock->mutex, timeout);
 
     /* We just got the lock back - this better be empty */
-    PR_ASSERT(PTHREAD_THR_HANDLE_IS_ZERO(cvar->lock->owner));
-    PTHREAD_COPY_THR_HANDLE(pthread_self(), cvar->lock->owner);
+    PR_ASSERT(_PT_PTHREAD_THR_HANDLE_IS_ZERO(cvar->lock->owner));
+    _PT_PTHREAD_COPY_THR_HANDLE(pthread_self(), cvar->lock->owner);
 
     PR_ASSERT(0 == cvar->lock->notified.length);
     thred->waiting = NULL;  /* and now we're not */
     if (thred->state & PT_THREAD_ABORTED) goto aborted;
     return (rv == 0) ? PR_SUCCESS : PR_FAILURE;
 
 aborted:
     PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
@@ -408,21 +408,21 @@ PR_IMPLEMENT(PRMonitor*) PR_NewMonitor(v
     {
         PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0);
         return NULL;
     }
     mon = PR_NEWZAP(PRMonitor);
     if (mon != NULL)
     {
         int rv;
-        rv = PTHREAD_MUTEX_INIT(mon->lock.mutex, _pt_mattr); 
+        rv = _PT_PTHREAD_MUTEX_INIT(mon->lock.mutex, _pt_mattr); 
         PR_ASSERT(0 == rv);
 
         mon->cvar = cvar;
-        rv = PTHREAD_COND_INIT(mon->cvar->cv, _pt_cvar_attr); 
+        rv = _PT_PTHREAD_COND_INIT(mon->cvar->cv, _pt_cvar_attr); 
         PR_ASSERT(0 == rv);
         mon->entryCount = 0;
         mon->cvar->lock = &mon->lock;
         if (0 != rv)
         {
             PR_DELETE(mon);
             PR_DELETE(cvar);
             mon = NULL;
@@ -473,109 +473,109 @@ PR_IMPLEMENT(void) PR_EnterMonitor(PRMon
     if (1 == rv)
 #else
     if (0 == rv)
 #endif
     {
         /* I now have the lock - I can play in the sandbox */
         /* could/should/would not have gotten lock if entries != 0 */
         PR_ASSERT(0 == mon->entryCount);
-        PR_ASSERT(PTHREAD_THR_HANDLE_IS_ZERO(mon->lock.owner));
-        PTHREAD_COPY_THR_HANDLE(pthread_self(), mon->lock.owner);
-        PTHREAD_COPY_THR_HANDLE(self, mon->owner);
+        PR_ASSERT(_PT_PTHREAD_THR_HANDLE_IS_ZERO(mon->lock.owner));
+        _PT_PTHREAD_COPY_THR_HANDLE(pthread_self(), mon->lock.owner);
+        _PT_PTHREAD_COPY_THR_HANDLE(self, mon->owner);
     }
     else
     {
         PR_ASSERT(PT_TRYLOCK_BUSY == rv);  /* and if it isn't? */
         /* somebody has it locked - is it me? */
         if (!pthread_equal(mon->owner, self))
         {
             /* it's not me - this should block */
             PR_Lock(&mon->lock);
             /* and now I have the lock */
             PR_ASSERT(0 == mon->entryCount);
-            PTHREAD_COPY_THR_HANDLE(self, mon->owner);
+            _PT_PTHREAD_COPY_THR_HANDLE(self, mon->owner);
         }
     }
     mon->entryCount += 1;
 }  /* PR_EnterMonitor */
 
 PR_IMPLEMENT(PRStatus) PR_ExitMonitor(PRMonitor *mon)
 {
     pthread_t self = pthread_self();
 
     PR_ASSERT(mon != NULL);
     /* The lock better be that - locked */
-    PR_ASSERT(PTHREAD_MUTEX_IS_LOCKED(mon->lock.mutex));
+    PR_ASSERT(_PT_PTHREAD_MUTEX_IS_LOCKED(mon->lock.mutex));
     /* we'd better be the owner */
     PR_ASSERT(pthread_equal(mon->owner, self));
     if (!pthread_equal(mon->owner, self))
         return PR_FAILURE;
 
     /* if it's locked and we have it, then the entries should be > 0 */
     PR_ASSERT(mon->entryCount > 0);
     mon->entryCount -= 1;  /* reduce by one */
     if (mon->entryCount == 0)
     {
         /* and if it transitioned to zero - unlock */
-        PTHREAD_ZERO_THR_HANDLE(mon->owner);  /* make the owner unknown */
+        _PT_PTHREAD_ZERO_THR_HANDLE(mon->owner);  /* make the owner unknown */
         PR_Unlock(&mon->lock);
     }
     return PR_SUCCESS;
 }  /* PR_ExitMonitor */
 
 PR_IMPLEMENT(PRStatus) PR_Wait(PRMonitor *mon, PRIntervalTime timeout)
 {
     PRStatus rv;
     PRInt16 saved_entries;
     pthread_t saved_owner;
 
     PR_ASSERT(mon != NULL);
     /* we'd better be locked */
-    PR_ASSERT(PTHREAD_MUTEX_IS_LOCKED(mon->lock.mutex));
+    PR_ASSERT(_PT_PTHREAD_MUTEX_IS_LOCKED(mon->lock.mutex));
     /* and the entries better be positive */
     PR_ASSERT(mon->entryCount > 0);
     /* and it better be by us */
     PR_ASSERT(pthread_equal(mon->owner, pthread_self()));
 
     /* tuck these away 'till later */
     saved_entries = mon->entryCount; 
     mon->entryCount = 0;
-    PTHREAD_COPY_THR_HANDLE(mon->owner, saved_owner);
-    PTHREAD_ZERO_THR_HANDLE(mon->owner);
+    _PT_PTHREAD_COPY_THR_HANDLE(mon->owner, saved_owner);
+    _PT_PTHREAD_ZERO_THR_HANDLE(mon->owner);
     
     rv = PR_WaitCondVar(mon->cvar, timeout);
 
     /* reinstate the intresting information */
     mon->entryCount = saved_entries;
-    PTHREAD_COPY_THR_HANDLE(saved_owner, mon->owner);
+    _PT_PTHREAD_COPY_THR_HANDLE(saved_owner, mon->owner);
 
     return rv;
 }  /* PR_Wait */
 
 PR_IMPLEMENT(PRStatus) PR_Notify(PRMonitor *mon)
 {
     PR_ASSERT(NULL != mon);
     /* we'd better be locked */
-    PR_ASSERT(PTHREAD_MUTEX_IS_LOCKED(mon->lock.mutex));
+    PR_ASSERT(_PT_PTHREAD_MUTEX_IS_LOCKED(mon->lock.mutex));
     /* and the entries better be positive */
     PR_ASSERT(mon->entryCount > 0);
     /* and it better be by us */
     PR_ASSERT(pthread_equal(mon->owner, pthread_self()));
 
     pt_PostNotifyToCvar(mon->cvar, PR_FALSE);
 
     return PR_SUCCESS;
 }  /* PR_Notify */
 
 PR_IMPLEMENT(PRStatus) PR_NotifyAll(PRMonitor *mon)
 {
     PR_ASSERT(mon != NULL);
     /* we'd better be locked */
-    PR_ASSERT(PTHREAD_MUTEX_IS_LOCKED(mon->lock.mutex));
+    PR_ASSERT(_PT_PTHREAD_MUTEX_IS_LOCKED(mon->lock.mutex));
     /* and the entries better be positive */
     PR_ASSERT(mon->entryCount > 0);
     /* and it better be by us */
     PR_ASSERT(pthread_equal(mon->owner, pthread_self()));
 
     pt_PostNotifyToCvar(mon->cvar, PR_TRUE);
 
     return PR_SUCCESS;
@@ -657,36 +657,36 @@ PR_IMPLEMENT(PRSemaphore*) PR_NewSem(PRU
 
 #include "prpdce.h"
 
 PR_IMPLEMENT(PRStatus) PRP_TryLock(PRLock *lock)
 {
     PRIntn rv = pthread_mutex_trylock(&lock->mutex);
     if (rv == PT_TRYLOCK_SUCCESS)
     {
-        PR_ASSERT(PTHREAD_THR_HANDLE_IS_ZERO(lock->owner));
-        PTHREAD_COPY_THR_HANDLE(pthread_self(), lock->owner); 
+        PR_ASSERT(_PT_PTHREAD_THR_HANDLE_IS_ZERO(lock->owner));
+        _PT_PTHREAD_COPY_THR_HANDLE(pthread_self(), lock->owner); 
     }
     else
-        PR_ASSERT(!PTHREAD_THR_HANDLE_IS_ZERO(lock->owner));
+        PR_ASSERT(!_PT_PTHREAD_THR_HANDLE_IS_ZERO(lock->owner));
     /* XXX set error code? */
     return (PT_TRYLOCK_SUCCESS == rv) ? PR_SUCCESS : PR_FAILURE;
 }  /* PRP_TryLock */
 
 PR_IMPLEMENT(PRCondVar*) PRP_NewNakedCondVar()
 {
     PRCondVar *cv;
 
     if (!_pr_initialized) _PR_ImplicitInitialization();
 
     cv = PR_NEW(PRCondVar);
     if (cv != NULL)
     {
         int rv;
-        rv = PTHREAD_COND_INIT(cv->cv, _pt_cvar_attr); 
+        rv = _PT_PTHREAD_COND_INIT(cv->cv, _pt_cvar_attr); 
         PR_ASSERT(0 == rv);
         cv->lock = _PR_NAKED_CV_LOCK;
     }
     return cv;
 }  /* PRP_NewNakedCondVar */
 
 PR_IMPLEMENT(void) PRP_DestroyNakedCondVar(PRCondVar *cvar)
 {
@@ -699,17 +699,17 @@ PR_IMPLEMENT(void) PRP_DestroyNakedCondV
 }  /* PRP_DestroyNakedCondVar */
 
 PR_IMPLEMENT(PRStatus) PRP_NakedWait(
     PRCondVar *cvar, PRLock *ml, PRIntervalTime timeout)
 {
     PRIntn rv;
     PR_ASSERT(cvar != NULL);
     /* XXX do we really want to assert this in a naked wait? */
-    PR_ASSERT(PTHREAD_MUTEX_IS_LOCKED(ml->mutex));
+    PR_ASSERT(_PT_PTHREAD_MUTEX_IS_LOCKED(ml->mutex));
     if (timeout == PR_INTERVAL_NO_TIMEOUT)
         rv = pthread_cond_wait(&cvar->cv, &ml->mutex);
     else
         rv = pt_TimedWait(&cvar->cv, &ml->mutex, timeout);
     return (rv == 0) ? PR_SUCCESS : PR_FAILURE;
 }  /* PRP_NakedWait */
 
 PR_IMPLEMENT(PRStatus) PRP_NakedNotify(PRCondVar *cvar)