Now uses the cache stack trick for a cheaper check_lock() version as suggested by stippi.

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@21863 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler 2007-08-08 22:43:52 +00:00
parent 69bee56c3b
commit eaad52e8d7
2 changed files with 11 additions and 5 deletions

View File

@ -159,13 +159,14 @@ private:
int32 fOwnerCount;
thread_id fOwner;
thread_id fThread;
addr_t fCachedStack;
int32 fInitPriority;
BHandler* fPreferred;
BList fHandlers;
BList* fCommonFilters;
bool fTerminating;
bool fRunCalled;
uint32 _reserved[12];
uint32 _reserved[11];
};
#endif // _LOOPER_H

View File

@ -546,7 +546,6 @@ BLooper::IsLocked() const
return false;
}
// Got this from Jeremy's BLocker implementation
return find_thread(NULL) == fOwner;
}
@ -907,7 +906,8 @@ BLooper::_Lock(BLooper* looper, port_id port, bigtime_t timeout)
status_t
BLooper::_LockComplete(BLooper *looper, int32 oldCount, thread_id thread, sem_id sem, bigtime_t timeout)
BLooper::_LockComplete(BLooper *looper, int32 oldCount, thread_id thread,
sem_id sem, bigtime_t timeout)
{
status_t err = B_OK;
@ -922,6 +922,7 @@ BLooper::_LockComplete(BLooper *looper, int32 oldCount, thread_id thread, sem_id
#endif
if (err == B_OK) {
looper->fOwner = thread;
looper->fCachedStack = (addr_t)&err & ~(B_PAGE_SIZE - 1);
looper->fOwnerCount = 1;
}
@ -1332,7 +1333,11 @@ BLooper::check_lock()
// This is a cheap variant of AssertLocked()
// It is used in situations where it's clear that the looper is valid,
// ie. from handlers
if (fOwner == -1 || fOwner != find_thread(NULL))
uint32 stack;
if (((uint32)&stack & ~(B_PAGE_SIZE - 1)) == fCachedStack
|| fOwner == find_thread(NULL))
return;
debugger("Looper must be locked.");
}