fix ClaimSocket: it was neither marking claims nor checking for marks.

This commit is contained in:
Andy2 2011-06-23 18:58:50 -07:00
parent 63a4e6c953
commit c51e5e41f4

View file

@ -96,18 +96,31 @@ CidInfo*
CidLock::ClaimSocket( int sock ) CidLock::ClaimSocket( int sock )
{ {
CidInfo* info = NULL; CidInfo* info = NULL;
logf( XW_LOGINFO, "%s(%d)", __func__, sock ); logf( XW_LOGINFO, "%s(sock=%d)", __func__, sock );
MutexLock ml( &m_infos_mutex ); for ( ; ; ) {
map< CookieID, CidInfo*>::iterator iter = m_infos.begin(); MutexLock ml( &m_infos_mutex );
while ( iter != m_infos.end() ) {
if ( sock == iter->second->GetSocket() ) { map< CookieID, CidInfo*>::iterator iter = m_infos.begin();
info = iter->second; while ( iter != m_infos.end() ) {
if ( sock == iter->second->GetSocket() ) {
if ( 0 == iter->second->GetOwner() ) {
info = iter->second;
info->SetOwner( pthread_self() );
}
break;
}
++iter;
}
/* break if socket isn't here or if it's not claimed */
if ( iter == m_infos.end() || NULL != info ) {
break; break;
} }
++iter; logf( XW_LOGINFO, "%s(sock=%d): waiting....", __func__, sock );
pthread_cond_wait( &m_infos_condvar, &m_infos_mutex );
} }
print_claimed();
logf( XW_LOGINFO, "%s(%d): DONE", __func__, info? info->GetCid():0 ); logf( XW_LOGINFO, "%s(%d): DONE", __func__, info? info->GetCid():0 );
return info; return info;
} }
@ -149,12 +162,14 @@ void
CidLock::Relinquish( CidInfo* claim, bool drop ) CidLock::Relinquish( CidInfo* claim, bool drop )
{ {
CookieID cid = claim->GetCid(); CookieID cid = claim->GetCid();
logf( XW_LOGINFO, "%s(%d)", __func__, cid ); logf( XW_LOGINFO, "%s(%d,drop=%d)", __func__, cid, drop );
MutexLock ml( &m_infos_mutex ); MutexLock ml( &m_infos_mutex );
map< CookieID, CidInfo*>::iterator iter = m_infos.find( cid ); map< CookieID, CidInfo*>::iterator iter = m_infos.find( cid );
assert( iter != m_infos.end() ); assert( iter != m_infos.end() );
assert( iter->second->GetOwner() == pthread_self() );
if ( drop ) { if ( drop ) {
logf( XW_LOGINFO, "%s: deleting %p", __func__, iter->second );
delete iter->second; delete iter->second;
m_infos.erase( iter ); m_infos.erase( iter );
} else { } else {
@ -162,5 +177,5 @@ CidLock::Relinquish( CidInfo* claim, bool drop )
} }
print_claimed(); print_claimed();
pthread_cond_signal( &m_infos_condvar ); pthread_cond_signal( &m_infos_condvar );
logf( XW_LOGINFO, "%s(%d): DONE", __func__, cid ); logf( XW_LOGINFO, "%s(%d,drop=%d): DONE", __func__, cid, drop );
} }