Bugzilla bug #51743: removed the unnecessary pthread_mutex_trylock call
authorwtc%netscape.com
Tue, 19 Dec 2000 03:04:55 +0000
changeset 1636 7f7dbb71b5fa33ff65ba0b4f57d43f7262ded995
parent 1635 283e60a637832a616c922fe06c857b87f16bfdf9
child 1641 ce293309b3fabbf6ecd389142f6c1afa8e223065
push idunknown
push userunknown
push dateunknown
bugs51743
Bugzilla bug #51743: removed the unnecessary pthread_mutex_trylock call from PR_EnterMonitor. Thanks to Vinay Badami <badami@netscape.com> for the fix.
pr/src/pthreads/ptsynch.c
--- a/pr/src/pthreads/ptsynch.c
+++ b/pr/src/pthreads/ptsynch.c
@@ -481,47 +481,31 @@ PR_IMPLEMENT(PRInt32) PR_GetMonitorEntry
     pthread_t self = pthread_self();
     if (pthread_equal(mon->owner, self))
         return mon->entryCount;
     return 0;
 }
 
 PR_IMPLEMENT(void) PR_EnterMonitor(PRMonitor *mon)
 {
-    int rv;
     pthread_t self = pthread_self();
 
     PR_ASSERT(mon != NULL);
-    rv = pthread_mutex_trylock(&mon->lock.mutex);
-#ifdef _PR_DCETHREADS
-    if (1 == rv)
-#else
-    if (0 == rv)
-#endif
+    /*
+     * This is safe only if mon->owner (a pthread_t) can be
+     * read in one instruction.  Perhaps mon->owner should be
+     * a "PRThread *"?
+     */
+    if (!pthread_equal(mon->owner, self))
     {
-        /* I now have the lock - I can play in the sandbox */
-        /* could/should/would not have gotten lock if entries != 0 */
+        PR_Lock(&mon->lock);
+        /* and now I have the lock */
         PR_ASSERT(0 == mon->entryCount);
-        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);
-            _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);