From f3a4ff9dfc4bd7f9b8914b6e231a4616371b18e4 Mon Sep 17 00:00:00 2001 From: Andy2 Date: Wed, 29 Jun 2011 18:42:41 -0700 Subject: [PATCH] use cid for variables of type CookieID everywhere instead of almost everywhere --- xwords4/relay/cref.cpp | 8 ++++---- xwords4/relay/cref.h | 6 +++--- xwords4/relay/crefmgr.cpp | 26 ++++++++++++-------------- xwords4/relay/crefmgr.h | 10 +++++----- 4 files changed, 24 insertions(+), 26 deletions(-) diff --git a/xwords4/relay/cref.cpp b/xwords4/relay/cref.cpp index bbe9a6ef3..28c1a135e 100644 --- a/xwords4/relay/cref.cpp +++ b/xwords4/relay/cref.cpp @@ -80,12 +80,12 @@ using namespace std; assert( m_locking_thread == pthread_self() ) void -CookieRef::ReInit( const char* cookie, const char* connName, CookieID id, +CookieRef::ReInit( const char* cookie, const char* connName, CookieID cid, int langCode, int nPlayers, int nAlreadyHere ) { m_cookie = cookie==NULL?"":cookie; m_connName = connName==NULL?"":connName; - m_cid = id; + m_cid = cid; m_curState = XWS_EMPTY; m_nPlayersSought = nPlayers; m_nPlayersHere = nAlreadyHere; @@ -111,11 +111,11 @@ CookieRef::ReInit( const char* cookie, const char* connName, CookieID id, } } -CookieRef::CookieRef( const char* cookie, const char* connName, CookieID id, +CookieRef::CookieRef( const char* cookie, const char* connName, CookieID cid, int langCode, int nPlayersT, int nAlreadyHere ) { pthread_rwlock_init( &m_socketsRWLock, NULL ); - ReInit( cookie, connName, id, langCode, nPlayersT, nAlreadyHere ); + ReInit( cookie, connName, cid, langCode, nPlayersT, nAlreadyHere ); } CookieRef::~CookieRef() diff --git a/xwords4/relay/cref.h b/xwords4/relay/cref.h index e2cd7fb93..1158feb67 100644 --- a/xwords4/relay/cref.h +++ b/xwords4/relay/cref.h @@ -74,9 +74,9 @@ class CookieRef { friend class SafeCref; friend class CookieMapIterator; - CookieRef( const char* cookie, const char* connName, CookieID id, + CookieRef( const char* cookie, const char* connName, CookieID cid, int langCode, int nPlayersT, int nPlayersH ); - void ReInit( const char* cookie, const char* connName, CookieID id, + void ReInit( const char* cookie, const char* connName, CookieID cid, int langCode, int nPlayers, int nAlreadyHere ); ~CookieRef(); @@ -116,7 +116,7 @@ class CookieRef { static CookieMapIterator GetCookieIterator(); /* Nuke an existing */ - static void Delete( CookieID id ); + static void Delete( CookieID cid ); static void Delete( const char* name ); bool _Connect( int socket, int nPlayersH, int nPlayersS, int seed, diff --git a/xwords4/relay/crefmgr.cpp b/xwords4/relay/crefmgr.cpp index 1df8ca3ef..ced9039cb 100644 --- a/xwords4/relay/crefmgr.cpp +++ b/xwords4/relay/crefmgr.cpp @@ -157,7 +157,7 @@ CRefMgr::GetStats( CrefMgrInfo& mgrInfo ) CrefInfo info; info.m_cookie = cref->Cookie(); info.m_connName = cref->ConnName(); - info.m_cookieID = cref->GetCid(); + info.m_cid = cref->GetCid(); info.m_curState = cref->CurState(); info.m_nPlayersSought = cref->GetPlayersSought(); info.m_nPlayersHere = cref->GetPlayersHere(); @@ -310,7 +310,6 @@ CRefMgr::getMakeCookieRef( const char* connName, const char* cookie, continue; } } else { - CookieID cid; /* The entry may not even be in the DB, e.g. if it got deleted. Deal with that possibility by taking the caller's word for it. */ cinfo = m_cidlock->Claim(); @@ -474,7 +473,7 @@ void CRefMgr::Recycle_locked( CookieRef* cref ) { logf( XW_LOGINFO, "%s(cref=%p,cookie=%s)", __func__, cref, cref->Cookie() ); - CookieID id = cref->GetCid(); + CookieID cid = cref->GetCid(); DBMgr::Get()->ClearCID( cref->ConnName() ); cref->Clear(); addToFreeList( cref ); @@ -489,7 +488,7 @@ CRefMgr::Recycle_locked( CookieRef* cref ) while ( iter != m_cookieMap.end() ) { CookieRef* ref = iter->second; if ( ref == cref ) { - logf( XW_LOGINFO, "%s: erasing cref cid %d", __func__, id ); + logf( XW_LOGINFO, "%s: erasing cref cid %d", __func__, cid ); m_cookieMap.erase( iter ); break; } @@ -505,9 +504,9 @@ CRefMgr::Recycle_locked( CookieRef* cref ) } /* CRefMgr::Recycle */ void -CRefMgr::Recycle( CookieID id ) +CRefMgr::Recycle( CookieID cid ) { - CidInfo* cinfo = getCookieRef( id ); + CidInfo* cinfo = getCookieRef( cid ); if ( cinfo != NULL ) { CookieRef* cref = cinfo->GetRef(); cref->Lock(); @@ -518,8 +517,7 @@ CRefMgr::Recycle( CookieID id ) void CRefMgr::Recycle( const char* connName ) { - CookieID id = cookieIDForConnName( connName ); - Recycle( id ); + Recycle( cookieIDForConnName( connName ) ); } /* Delete */ #ifdef RELAY_HEARTBEAT @@ -568,13 +566,13 @@ CookieMapIterator::CookieMapIterator(pthread_rwlock_t* rwlock) CookieID CookieMapIterator::Next() { - CookieID id = 0; + CookieID cid = 0; if ( _iter != CRefMgr::Get()->m_cookieMap.end() ) { CookieRef* cref = _iter->second; - id = cref->GetCid(); + cid = cref->GetCid(); ++_iter; } - return id; + return cid; } ////////////////////////////////////////////////////////////////////////////// @@ -646,17 +644,17 @@ SafeCref::SafeCref( const char* const connName ) } } -SafeCref::SafeCref( CookieID connID, bool failOk ) +SafeCref::SafeCref( CookieID cid, bool failOk ) : m_cinfo( NULL ) , m_mgr( CRefMgr::Get() ) , m_isValid( false ) { - CidInfo* cinfo = m_mgr->getCookieRef( connID ); + CidInfo* cinfo = m_mgr->getCookieRef( cid ); if ( cinfo != NULL ) { /* known cookie? */ CookieRef* cref = cinfo->GetRef(); assert( cinfo->GetCid() == cref->GetCid() ); m_locked = cref->Lock(); - m_isValid = m_locked && connID == cref->GetCid(); + m_isValid = m_locked && cid == cref->GetCid(); m_cinfo = cinfo; } } diff --git a/xwords4/relay/crefmgr.h b/xwords4/relay/crefmgr.h index 6b06d45dc..5385f64aa 100644 --- a/xwords4/relay/crefmgr.h +++ b/xwords4/relay/crefmgr.h @@ -36,7 +36,7 @@ class CrefInfo { public: string m_cookie; string m_connName; - CookieID m_cookieID; + CookieID m_cid; int m_nPlayersSought; int m_nPlayersHere; XW_RELAY_STATE m_curState; @@ -77,7 +77,7 @@ class CRefMgr { CookieMapIterator GetCookieIterator(); /* PENDING. These need to go through SafeCref */ - void Recycle( CookieID id ); + void Recycle( CookieID cid ); void Recycle_locked( CookieRef* cref ); void Recycle( const char* connName ); CookieID CookieIdForName( const char* name ); @@ -131,11 +131,11 @@ class CRefMgr { CidInfo* getMakeCookieRef( const char* const connName, bool* isDead ); - CidInfo* getCookieRef( CookieID cookieID ); + CidInfo* getCookieRef( CookieID cid ); CidInfo* getCookieRef( int socket ); bool checkCookieRef_locked( CookieRef* cref ); - CidInfo* getCookieRef_impl( CookieID cookieID ); - CookieRef* AddNew( const char* cookie, const char* connName, CookieID id, + CidInfo* getCookieRef_impl( CookieID cid ); + CookieRef* AddNew( const char* cookie, const char* connName, CookieID cid, int langCode, int nPlayers, int nAlreadyHere ); CookieRef* FindOpenGameFor( const char* cookie, const char* connName, HostID hid, int socket, int nPlayersH,