|
@@ -24,12 +24,17 @@ Critical::~Critical()
|
|
|
DeleteCriticalSection(&cs);
|
|
|
}
|
|
|
|
|
|
+pthread_t CachedCurrentThread()
|
|
|
+{
|
|
|
+ volatile thread_local static pthread_t t = GetCurrentThread();
|
|
|
+ return (pthread_t)t;
|
|
|
+}
|
|
|
+
|
|
|
// sperrt das Objekt
|
|
|
void Critical::lock()
|
|
|
{
|
|
|
- pthread_t t = GetCurrentThread();
|
|
|
getThreadRegister()->lock();
|
|
|
- Thread* tmp = getThreadRegister()->zThread(t);
|
|
|
+ Thread* tmp = getThreadRegister()->zThread(CachedCurrentThread());
|
|
|
if (tmp) tmp->addCriticalLock();
|
|
|
getThreadRegister()->unlock();
|
|
|
EnterCriticalSection(&cs);
|
|
@@ -42,7 +47,7 @@ bool Critical::tryLock()
|
|
|
{
|
|
|
if (lockCount > 0) return false;
|
|
|
getThreadRegister()->lock();
|
|
|
- Thread* tmp = getThreadRegister()->zThread(GetCurrentThread());
|
|
|
+ Thread* tmp = getThreadRegister()->zThread(CachedCurrentThread());
|
|
|
if (tmp) tmp->addCriticalLock();
|
|
|
getThreadRegister()->unlock();
|
|
|
EnterCriticalSection(&cs);
|
|
@@ -60,7 +65,7 @@ void Critical::unlock()
|
|
|
{
|
|
|
if (owner
|
|
|
&& GetThreadId(owner->getThreadHandle())
|
|
|
- != GetThreadId(GetCurrentThread()))
|
|
|
+ != GetThreadId(CachedCurrentThread()))
|
|
|
throw std::runtime_error("A Thread that does not own a Critical "
|
|
|
"Object trys to unlock it");
|
|
|
tmp = owner;
|