|
@@ -26,9 +26,11 @@ Critical::~Critical()
|
|
|
void Critical::lock()
|
|
|
{
|
|
|
pthread_t t = GetCurrentThread();
|
|
|
+ getThreadRegister()->lock();
|
|
|
Thread *tmp = getThreadRegister()->zThread( t );
|
|
|
if( tmp )
|
|
|
tmp->addCriticalLock();
|
|
|
+ getThreadRegister()->unlock();
|
|
|
EnterCriticalSection( &cs );
|
|
|
if( !owner )
|
|
|
owner = tmp;
|
|
@@ -39,10 +41,12 @@ void Critical::lock()
|
|
|
bool Critical::tryLock()
|
|
|
{
|
|
|
if( lockCount > 0 )
|
|
|
- return false;
|
|
|
+ return false;
|
|
|
+ getThreadRegister()->lock();
|
|
|
Thread *tmp = getThreadRegister()->zThread( GetCurrentThread() );
|
|
|
if( tmp )
|
|
|
tmp->addCriticalLock();
|
|
|
+ getThreadRegister()->unlock();
|
|
|
EnterCriticalSection( &cs );
|
|
|
if( !owner )
|
|
|
owner = tmp;
|
|
@@ -53,14 +57,22 @@ bool Critical::tryLock()
|
|
|
// entsperrt das Objekt
|
|
|
void Critical::unlock()
|
|
|
{
|
|
|
- if( owner && GetThreadId( owner->getThreadHandle() ) != GetThreadId( GetCurrentThread() ) )
|
|
|
- throw std::runtime_error( "A Thread that does not own a Critical Object trys to unlock it" );
|
|
|
- Thread *tmp = owner;
|
|
|
+ getThreadRegister()->lock();
|
|
|
+ Thread *tmp = 0;
|
|
|
+ if( getThreadRegister()->isThread( owner ) )
|
|
|
+ {
|
|
|
+ if( owner && GetThreadId( owner->getThreadHandle() ) != GetThreadId( GetCurrentThread() ) )
|
|
|
+ throw std::runtime_error( "A Thread that does not own a Critical Object trys to unlock it" );
|
|
|
+ tmp = owner;
|
|
|
+ }
|
|
|
+ getThreadRegister()->unlock();
|
|
|
if( !--lockCount )
|
|
|
owner = 0;
|
|
|
LeaveCriticalSection( &cs );
|
|
|
- if( tmp )
|
|
|
+ getThreadRegister()->lock();
|
|
|
+ if( tmp && getThreadRegister()->isThread( tmp ) )
|
|
|
tmp->removeCriticalLock();
|
|
|
+ getThreadRegister()->unlock();
|
|
|
}
|
|
|
|
|
|
|