diff options
Diffstat (limited to 'pr/src/threads/combined/prulock.c')
-rw-r--r-- | pr/src/threads/combined/prulock.c | 183 |
1 files changed, 97 insertions, 86 deletions
diff --git a/pr/src/threads/combined/prulock.c b/pr/src/threads/combined/prulock.c index 3d459dd5..69c27d14 100644 --- a/pr/src/threads/combined/prulock.c +++ b/pr/src/threads/combined/prulock.c @@ -18,7 +18,7 @@ void _PR_InitLocks(void) { - _PR_MD_INIT_LOCKS(); + _PR_MD_INIT_LOCKS(); } /* @@ -33,7 +33,7 @@ void _PR_IntsOn(_PRCPU *cpu) PR_ASSERT(cpu); /* Global threads don't have CPUs */ PR_ASSERT(_PR_MD_GET_INTSOFF() > 0); - me = _PR_MD_CURRENT_THREAD(); + me = _PR_MD_CURRENT_THREAD(); PR_ASSERT(!(me->flags & _PR_IDLE_THREAD)); /* @@ -69,15 +69,15 @@ void _PR_IntsOn(_PRCPU *cpu) if (cpu->u.missed[3] != 0) { _PRCPU *cpu; - _PR_THREAD_LOCK(me); + _PR_THREAD_LOCK(me); me->state = _PR_RUNNABLE; pri = me->priority; cpu = me->cpu; - _PR_RUNQ_LOCK(cpu); + _PR_RUNQ_LOCK(cpu); _PR_ADD_RUNQ(me, cpu, pri); - _PR_RUNQ_UNLOCK(cpu); - _PR_THREAD_UNLOCK(me); + _PR_RUNQ_UNLOCK(cpu); + _PR_THREAD_UNLOCK(me); _PR_MD_SWITCH_CONTEXT(me); } } @@ -99,11 +99,11 @@ void _PR_UnblockLockWaiter(PRLock *lock) /* Unblock first waiter */ t = _PR_THREAD_CONDQ_PTR(q); - /* - ** We are about to change the thread's state to runnable and for local - ** threads, we are going to assign a cpu to it. So, protect thread's - ** data structure. - */ + /* + ** We are about to change the thread's state to runnable and for local + ** threads, we are going to assign a cpu to it. So, protect thread's + ** data structure. + */ _PR_THREAD_LOCK(t); if (t->flags & _PR_SUSPENDING) { @@ -113,23 +113,23 @@ void _PR_UnblockLockWaiter(PRLock *lock) } /* Found a runnable thread */ - PR_ASSERT(t->state == _PR_LOCK_WAIT); - PR_ASSERT(t->wait.lock == lock); + PR_ASSERT(t->state == _PR_LOCK_WAIT); + PR_ASSERT(t->wait.lock == lock); t->wait.lock = 0; PR_REMOVE_LINK(&t->waitQLinks); /* take it off lock's waitQ */ - /* - ** If this is a native thread, nothing else to do except to wake it - ** up by calling the machine dependent wakeup routine. - ** - ** If this is a local thread, we need to assign it a cpu and - ** put the thread on that cpu's run queue. There are two cases to - ** take care of. If the currently running thread is also a local - ** thread, we just assign our own cpu to that thread and put it on - ** the cpu's run queue. If the the currently running thread is a - ** native thread, we assign the primordial cpu to it (on NT, - ** MD_WAKEUP handles the cpu assignment). - */ + /* + ** If this is a native thread, nothing else to do except to wake it + ** up by calling the machine dependent wakeup routine. + ** + ** If this is a local thread, we need to assign it a cpu and + ** put the thread on that cpu's run queue. There are two cases to + ** take care of. If the currently running thread is also a local + ** thread, we just assign our own cpu to that thread and put it on + ** the cpu's run queue. If the the currently running thread is a + ** native thread, we assign the primordial cpu to it (on NT, + ** MD_WAKEUP handles the cpu assignment). + */ if ( !_PR_IS_NATIVE_THREAD(t) ) { @@ -156,7 +156,9 @@ PR_IMPLEMENT(PRLock*) PR_NewLock(void) { PRLock *lock; - if (!_pr_initialized) _PR_ImplicitInitialization(); + if (!_pr_initialized) { + _PR_ImplicitInitialization(); + } lock = PR_NEWZAP(PRLock); if (lock) { @@ -216,15 +218,16 @@ PR_IMPLEMENT(void) PR_Lock(PRLock *lock) return; #else /* _PR_GLOBAL_THREADS_ONLY */ - if (_native_threads_only) { - _PR_MD_LOCK(&lock->ilock); - PR_ASSERT(lock->owner == 0); - lock->owner = me; - return; - } + if (_native_threads_only) { + _PR_MD_LOCK(&lock->ilock); + PR_ASSERT(lock->owner == 0); + lock->owner = me; + return; + } - if (!_PR_IS_NATIVE_THREAD(me)) - _PR_INTSOFF(is); + if (!_PR_IS_NATIVE_THREAD(me)) { + _PR_INTSOFF(is); + } PR_ASSERT(_PR_IS_NATIVE_THREAD(me) || _PR_MD_GET_INTSOFF() != 0); @@ -234,11 +237,12 @@ retry: /* Just got the lock */ lock->owner = me; lock->priority = me->priority; - /* Add the granted lock to this owning thread's lock list */ + /* 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); + if (!_PR_IS_NATIVE_THREAD(me)) { + _PR_FAST_INTSON(is); + } return; } @@ -265,32 +269,32 @@ retry: */ 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; + _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; - } - } + /* 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. - */ + /* + 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; @@ -300,7 +304,7 @@ retry: _PR_LOCK_UNLOCK(lock); _PR_MD_WAIT(me, PR_INTERVAL_NO_TIMEOUT); - goto retry; + goto retry; #endif /* _PR_GLOBAL_THREADS_ONLY */ } @@ -329,17 +333,18 @@ PR_IMPLEMENT(PRStatus) PR_Unlock(PRLock *lock) return PR_SUCCESS; #else /* _PR_GLOBAL_THREADS_ONLY */ - if (_native_threads_only) { - lock->owner = 0; - _PR_MD_UNLOCK(&lock->ilock); - return PR_SUCCESS; - } + if (_native_threads_only) { + lock->owner = 0; + _PR_MD_UNLOCK(&lock->ilock); + return PR_SUCCESS; + } - if (!_PR_IS_NATIVE_THREAD(me)) - _PR_INTSOFF(is); + if (!_PR_IS_NATIVE_THREAD(me)) { + _PR_INTSOFF(is); + } _PR_LOCK_LOCK(lock); - /* Remove the lock from the owning thread's lock list */ + /* Remove the lock from the owning thread's lock list */ PR_REMOVE_LINK(&lock->links); pri = lock->priority; boost = lock->boostPriority; @@ -365,13 +370,15 @@ PR_IMPLEMENT(PRStatus) PR_Unlock(PRLock *lock) /* Unblock the first waiting thread */ q = lock->waitQ.next; - if (q != &lock->waitQ) + if (q != &lock->waitQ) { _PR_UnblockLockWaiter(lock); + } lock->boostPriority = PR_PRIORITY_LOW; lock->owner = 0; _PR_LOCK_UNLOCK(lock); - if (!_PR_IS_NATIVE_THREAD(me)) - _PR_INTSON(is); + if (!_PR_IS_NATIVE_THREAD(me)) { + _PR_INTSON(is); + } return PR_SUCCESS; #endif /* _PR_GLOBAL_THREADS_ONLY */ } @@ -407,32 +414,34 @@ PR_IMPLEMENT(PRBool) PR_TestAndLock(PRLock *lock) #else /* _PR_GLOBAL_THREADS_ONLY */ #ifndef _PR_LOCAL_THREADS_ONLY - if (_native_threads_only) { - is = _PR_MD_TEST_AND_LOCK(&lock->ilock); - if (is == 0) { - lock->owner = me; - return PR_TRUE; - } - return PR_FALSE; - } + if (_native_threads_only) { + is = _PR_MD_TEST_AND_LOCK(&lock->ilock); + if (is == 0) { + lock->owner = me; + return PR_TRUE; + } + return PR_FALSE; + } #endif - if (!_PR_IS_NATIVE_THREAD(me)) - _PR_INTSOFF(is); + if (!_PR_IS_NATIVE_THREAD(me)) { + _PR_INTSOFF(is); + } _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 */ + /* Add the granted lock to this owning thread's lock list */ PR_APPEND_LINK(&lock->links, &me->lockList); rv = PR_TRUE; } _PR_LOCK_UNLOCK(lock); - if (!_PR_IS_NATIVE_THREAD(me)) - _PR_INTSON(is); + if (!_PR_IS_NATIVE_THREAD(me)) { + _PR_INTSON(is); + } return rv; #endif /* _PR_GLOBAL_THREADS_ONLY */ } @@ -443,4 +452,6 @@ PR_IMPLEMENT(PRBool) PR_TestAndLock(PRLock *lock) /************************************************************************/ /************************************************************************/ PR_IMPLEMENT(PRStatus) PRP_TryLock(PRLock *lock) - { return (PR_TestAndLock(lock)) ? PR_SUCCESS : PR_FAILURE; } +{ + return (PR_TestAndLock(lock)) ? PR_SUCCESS : PR_FAILURE; +} |