[prev in list] [next in list] [prev in thread] [next in thread] 

List:       mozilla-patches
Subject:    NSPR monitor code
From:       Joe Keane <jgk () jgk ! org>
Date:       1998-10-19 17:57:24
[Download RAW message or body]

Here are some minor improvements to NSPR monitor functions.  The first
part is very simple, it removes a duplicate call to `pthread_self' in
`PR_EnterMonitor'.  The second part hoists some code from `PR_Unlock'
into `PR_ExitMonitor'.  This is arguably some code duplication, but i
like it better and i want to make this code slick.  Some tests are
cleaned up and it also removes some calls to `pthread_self' and
`pthread_equal' since the result was ignored anyway.

*** ptsynch.c.old	Thu Oct  8 13:25:39 1998
--- ptsynch.c.new	Sat Oct 17 02:52:36 1998
***************
*** 485,491 ****
          /* 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);
      }
      else
--- 485,491 ----
          /* 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(self, mon->lock.owner);
          PTHREAD_COPY_THR_HANDLE(self, mon->owner);
      }
      else
***************
*** 522,529 ****
      if (mon->entryCount == 0)
      {
          /* and if it transitioned to zero - unlock */
          PTHREAD_ZERO_THR_HANDLE(mon->owner);  /* make the owner unknown */
!         PR_Unlock(&mon->lock);
      }
      return PR_SUCCESS;
  }  /* PR_ExitMonitor */
--- 522,541 ----
      if (mon->entryCount == 0)
      {
          /* and if it transitioned to zero - unlock */
+         PR_ASSERT(pthread_equal(mon->lock.owner, self));
          PTHREAD_ZERO_THR_HANDLE(mon->owner);  /* make the owner unknown */
! 
!         /* begin code inlined from `PR_Unlock' */
!         PTHREAD_ZERO_THR_HANDLE(mon->lock.owner);
!         if (0 == mon->lock.notified.length)  /* shortcut */
!         {
!             PRIntn rv;
! 
!             rv = pthread_mutex_unlock(&mon->lock.mutex);
!             PR_ASSERT(0 == rv);
!         }
!         else pt_PostNotifies(&mon->lock, PR_TRUE);
!         /* end code inlined from `PR_Unlock' */
      }
      return PR_SUCCESS;
  }  /* PR_ExitMonitor */

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic