From 175aace6294e2e0b4a667849d33b9e49ae724e86 Mon Sep 17 00:00:00 2001 From: Andy2 Date: Sat, 2 Jul 2011 13:28:24 -0700 Subject: [PATCH] fix a couple of rare failures due to race conditions testing or valgrind flushed out. --- xwords4/relay/crefmgr.cpp | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/xwords4/relay/crefmgr.cpp b/xwords4/relay/crefmgr.cpp index ced9039cb..99edfe358 100644 --- a/xwords4/relay/crefmgr.cpp +++ b/xwords4/relay/crefmgr.cpp @@ -373,7 +373,6 @@ CRefMgr::getMakeCookieRef( const char* const connName, bool* isDead ) } break; } - assert( cinfo->GetRef() ); return cinfo; } @@ -405,7 +404,15 @@ CRefMgr::PrintSocketInfo( int socket, string& out ) CidInfo* CRefMgr::getCookieRef( CookieID cid ) { - return m_cidlock->Claim( cid ); + CidInfo* cinfo = NULL; + for ( ; ; ) { + cinfo = m_cidlock->Claim( cid ); + if ( NULL != cinfo->GetRef() ) { + break; + } + m_cidlock->Relinquish( cinfo, true ); + } + return cinfo; } /* getCookieRef */ CidInfo* @@ -627,7 +634,7 @@ SafeCref::SafeCref( const char* connName, const char* cookie, HostID hid, } } -/* ConnName case -- must exist */ +/* ConnName case -- must exist (unless DB record's been removed */ SafeCref::SafeCref( const char* const connName ) : m_cinfo( NULL ) , m_mgr( CRefMgr::Get() ) @@ -635,7 +642,7 @@ SafeCref::SafeCref( const char* const connName ) { bool isDead = false; CidInfo* cinfo = m_mgr->getMakeCookieRef( connName, &isDead ); - if ( cinfo != NULL ) { + if ( NULL != cinfo && NULL != cinfo->GetRef() ) { assert( cinfo->GetCid() == cinfo->GetRef()->GetCid() ); m_locked = cinfo->GetRef()->Lock(); m_cinfo = cinfo;