From eaad52e8d72af216e4b306cd34323e30bb976130 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Wed, 8 Aug 2007 22:43:52 +0000 Subject: [PATCH] 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 --- headers/os/app/Looper.h | 3 ++- src/kits/app/Looper.cpp | 13 +++++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/headers/os/app/Looper.h b/headers/os/app/Looper.h index d667748ca1..a523480141 100644 --- a/headers/os/app/Looper.h +++ b/headers/os/app/Looper.h @@ -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 diff --git a/src/kits/app/Looper.cpp b/src/kits/app/Looper.cpp index 60deb58749..247f627578 100644 --- a/src/kits/app/Looper.cpp +++ b/src/kits/app/Looper.cpp @@ -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,8 +1333,12 @@ 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)) - debugger("Looper must be locked."); + uint32 stack; + if (((uint32)&stack & ~(B_PAGE_SIZE - 1)) == fCachedStack + || fOwner == find_thread(NULL)) + return; + + debugger("Looper must be locked."); }