PR_ASSERT(lock->owner == me);  if (!_PR_IS_NATIVE_THREAD(me)) _PR_FAST_INTSON(is);
PR_IMPLEMENT(void) PR_Lock(PRLock *lock){    PRThread *me = _PR_MD_CURRENT_THREAD();    PRIntn is;    PRThread *t;    PRCList *q;    PR_ASSERT(me != suspendAllThread); #if !defined(XP_MAC)    PR_ASSERT(!(me->flags & _PR_IDLE_THREAD));#endif#ifdef _PR_GLOBAL_THREADS_ONLY     PR_ASSERT(lock->owner != me);    _PR_MD_LOCK(&lock->ilock);    lock->owner = me;    return;#else  /* _PR_GLOBAL_THREADS_ONLY */	if (_native_threads_only) {		PR_ASSERT(lock->owner != me);		_PR_MD_LOCK(&lock->ilock);		lock->owner = me;		return;	}    if (!_PR_IS_NATIVE_THREAD(me))    	_PR_INTSOFF(is);    PR_ASSERT(_PR_IS_NATIVE_THREAD(me) || _PR_MD_GET_INTSOFF() != 0);    _PR_LOCK_LOCK(lock);    if (lock->owner == 0) {        /* Just got the lock */        lock->owner = me;        lock->priority = me->priority;		/* Add the granted lock to this owning thread's lock list */        PR_APPEND_LINK(&lock->links, &me->lockList);        _PR_LOCK_UNLOCK(lock);    	if (!_PR_IS_NATIVE_THREAD(me))        	_PR_FAST_INTSON(is);        return;    }    /* If this thread already owns this lock, then it is a deadlock */    PR_ASSERT(lock->owner != me);    PR_ASSERT(_PR_IS_NATIVE_THREAD(me) || _PR_MD_GET_INTSOFF() != 0);#if 0    if (me->priority > lock->owner->priority) {        /*        ** Give the lock owner a priority boost until we get the        ** lock. Record the priority we boosted it to.        */        lock->boostPriority = me->priority;        _PR_SetThreadPriority(lock->owner, me->priority);    }#endif    /*     Add this thread to the asked for lock's list of waiting threads.  We    add this thread thread in the right priority order so when the unlock    occurs, the thread with the higher priority will get the lock.    */    q = lock->waitQ.next;    if (q == &lock->waitQ || _PR_THREAD_CONDQ_PTR(q)->priority ==      	_PR_THREAD_CONDQ_PTR(lock->waitQ.prev)->priority) {		/*		 * If all the threads in the lock waitQ have the same priority,		 * then avoid scanning the list:  insert the element at the end.		 */		q = &lock->waitQ;    } else {		/* Sort thread into lock's waitQ at appropriate point */		/* Now scan the list for where to insert this entry */		while (q != &lock->waitQ) {			t = _PR_THREAD_CONDQ_PTR(lock->waitQ.next);			if (me->priority > t->priority) {				/* Found a lower priority thread to insert in front of */				break;			}			q = q->next;		}	}    PR_INSERT_BEFORE(&me->waitQLinks, q);	/* 	Now grab the threadLock since we are about to change the state.  We have	to do this since a PR_Suspend or PR_SetThreadPriority type call that takes	a PRThread* as an argument could be changing the state of this thread from	a thread running on a different cpu.	*/    _PR_THREAD_LOCK(me);    me->state = _PR_LOCK_WAIT;    me->wait.lock = lock;    _PR_THREAD_UNLOCK(me);    _PR_LOCK_UNLOCK(lock);    _PR_MD_WAIT(me, PR_INTERVAL_NO_TIMEOUT);	/* When we are here after the context switch, we better own the lock */    PR_ASSERT(lock->owner == me);    if (!_PR_IS_NATIVE_THREAD(me))    	_PR_FAST_INTSON(is);#endif  /* _PR_GLOBAL_THREADS_ONLY */}