mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-02-05 20:45:49 +01:00
use cid for variables of type CookieID everywhere instead of almost
everywhere
This commit is contained in:
parent
4cb45d3b82
commit
f3a4ff9dfc
4 changed files with 24 additions and 26 deletions
|
@ -80,12 +80,12 @@ using namespace std;
|
||||||
assert( m_locking_thread == pthread_self() )
|
assert( m_locking_thread == pthread_self() )
|
||||||
|
|
||||||
void
|
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 )
|
int langCode, int nPlayers, int nAlreadyHere )
|
||||||
{
|
{
|
||||||
m_cookie = cookie==NULL?"":cookie;
|
m_cookie = cookie==NULL?"":cookie;
|
||||||
m_connName = connName==NULL?"":connName;
|
m_connName = connName==NULL?"":connName;
|
||||||
m_cid = id;
|
m_cid = cid;
|
||||||
m_curState = XWS_EMPTY;
|
m_curState = XWS_EMPTY;
|
||||||
m_nPlayersSought = nPlayers;
|
m_nPlayersSought = nPlayers;
|
||||||
m_nPlayersHere = nAlreadyHere;
|
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 )
|
int langCode, int nPlayersT, int nAlreadyHere )
|
||||||
{
|
{
|
||||||
pthread_rwlock_init( &m_socketsRWLock, NULL );
|
pthread_rwlock_init( &m_socketsRWLock, NULL );
|
||||||
ReInit( cookie, connName, id, langCode, nPlayersT, nAlreadyHere );
|
ReInit( cookie, connName, cid, langCode, nPlayersT, nAlreadyHere );
|
||||||
}
|
}
|
||||||
|
|
||||||
CookieRef::~CookieRef()
|
CookieRef::~CookieRef()
|
||||||
|
|
|
@ -74,9 +74,9 @@ class CookieRef {
|
||||||
friend class SafeCref;
|
friend class SafeCref;
|
||||||
friend class CookieMapIterator;
|
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 );
|
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 );
|
int langCode, int nPlayers, int nAlreadyHere );
|
||||||
~CookieRef();
|
~CookieRef();
|
||||||
|
|
||||||
|
@ -116,7 +116,7 @@ class CookieRef {
|
||||||
static CookieMapIterator GetCookieIterator();
|
static CookieMapIterator GetCookieIterator();
|
||||||
|
|
||||||
/* Nuke an existing */
|
/* Nuke an existing */
|
||||||
static void Delete( CookieID id );
|
static void Delete( CookieID cid );
|
||||||
static void Delete( const char* name );
|
static void Delete( const char* name );
|
||||||
|
|
||||||
bool _Connect( int socket, int nPlayersH, int nPlayersS, int seed,
|
bool _Connect( int socket, int nPlayersH, int nPlayersS, int seed,
|
||||||
|
|
|
@ -157,7 +157,7 @@ CRefMgr::GetStats( CrefMgrInfo& mgrInfo )
|
||||||
CrefInfo info;
|
CrefInfo info;
|
||||||
info.m_cookie = cref->Cookie();
|
info.m_cookie = cref->Cookie();
|
||||||
info.m_connName = cref->ConnName();
|
info.m_connName = cref->ConnName();
|
||||||
info.m_cookieID = cref->GetCid();
|
info.m_cid = cref->GetCid();
|
||||||
info.m_curState = cref->CurState();
|
info.m_curState = cref->CurState();
|
||||||
info.m_nPlayersSought = cref->GetPlayersSought();
|
info.m_nPlayersSought = cref->GetPlayersSought();
|
||||||
info.m_nPlayersHere = cref->GetPlayersHere();
|
info.m_nPlayersHere = cref->GetPlayersHere();
|
||||||
|
@ -310,7 +310,6 @@ CRefMgr::getMakeCookieRef( const char* connName, const char* cookie,
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
CookieID cid;
|
|
||||||
/* The entry may not even be in the DB, e.g. if it got deleted.
|
/* 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. */
|
Deal with that possibility by taking the caller's word for it. */
|
||||||
cinfo = m_cidlock->Claim();
|
cinfo = m_cidlock->Claim();
|
||||||
|
@ -474,7 +473,7 @@ void
|
||||||
CRefMgr::Recycle_locked( CookieRef* cref )
|
CRefMgr::Recycle_locked( CookieRef* cref )
|
||||||
{
|
{
|
||||||
logf( XW_LOGINFO, "%s(cref=%p,cookie=%s)", __func__, cref, cref->Cookie() );
|
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() );
|
DBMgr::Get()->ClearCID( cref->ConnName() );
|
||||||
cref->Clear();
|
cref->Clear();
|
||||||
addToFreeList( cref );
|
addToFreeList( cref );
|
||||||
|
@ -489,7 +488,7 @@ CRefMgr::Recycle_locked( CookieRef* cref )
|
||||||
while ( iter != m_cookieMap.end() ) {
|
while ( iter != m_cookieMap.end() ) {
|
||||||
CookieRef* ref = iter->second;
|
CookieRef* ref = iter->second;
|
||||||
if ( ref == cref ) {
|
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 );
|
m_cookieMap.erase( iter );
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -505,9 +504,9 @@ CRefMgr::Recycle_locked( CookieRef* cref )
|
||||||
} /* CRefMgr::Recycle */
|
} /* CRefMgr::Recycle */
|
||||||
|
|
||||||
void
|
void
|
||||||
CRefMgr::Recycle( CookieID id )
|
CRefMgr::Recycle( CookieID cid )
|
||||||
{
|
{
|
||||||
CidInfo* cinfo = getCookieRef( id );
|
CidInfo* cinfo = getCookieRef( cid );
|
||||||
if ( cinfo != NULL ) {
|
if ( cinfo != NULL ) {
|
||||||
CookieRef* cref = cinfo->GetRef();
|
CookieRef* cref = cinfo->GetRef();
|
||||||
cref->Lock();
|
cref->Lock();
|
||||||
|
@ -518,8 +517,7 @@ CRefMgr::Recycle( CookieID id )
|
||||||
void
|
void
|
||||||
CRefMgr::Recycle( const char* connName )
|
CRefMgr::Recycle( const char* connName )
|
||||||
{
|
{
|
||||||
CookieID id = cookieIDForConnName( connName );
|
Recycle( cookieIDForConnName( connName ) );
|
||||||
Recycle( id );
|
|
||||||
} /* Delete */
|
} /* Delete */
|
||||||
|
|
||||||
#ifdef RELAY_HEARTBEAT
|
#ifdef RELAY_HEARTBEAT
|
||||||
|
@ -568,13 +566,13 @@ CookieMapIterator::CookieMapIterator(pthread_rwlock_t* rwlock)
|
||||||
CookieID
|
CookieID
|
||||||
CookieMapIterator::Next()
|
CookieMapIterator::Next()
|
||||||
{
|
{
|
||||||
CookieID id = 0;
|
CookieID cid = 0;
|
||||||
if ( _iter != CRefMgr::Get()->m_cookieMap.end() ) {
|
if ( _iter != CRefMgr::Get()->m_cookieMap.end() ) {
|
||||||
CookieRef* cref = _iter->second;
|
CookieRef* cref = _iter->second;
|
||||||
id = cref->GetCid();
|
cid = cref->GetCid();
|
||||||
++_iter;
|
++_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_cinfo( NULL )
|
||||||
, m_mgr( CRefMgr::Get() )
|
, m_mgr( CRefMgr::Get() )
|
||||||
, m_isValid( false )
|
, m_isValid( false )
|
||||||
{
|
{
|
||||||
CidInfo* cinfo = m_mgr->getCookieRef( connID );
|
CidInfo* cinfo = m_mgr->getCookieRef( cid );
|
||||||
if ( cinfo != NULL ) { /* known cookie? */
|
if ( cinfo != NULL ) { /* known cookie? */
|
||||||
CookieRef* cref = cinfo->GetRef();
|
CookieRef* cref = cinfo->GetRef();
|
||||||
assert( cinfo->GetCid() == cref->GetCid() );
|
assert( cinfo->GetCid() == cref->GetCid() );
|
||||||
m_locked = cref->Lock();
|
m_locked = cref->Lock();
|
||||||
m_isValid = m_locked && connID == cref->GetCid();
|
m_isValid = m_locked && cid == cref->GetCid();
|
||||||
m_cinfo = cinfo;
|
m_cinfo = cinfo;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,7 +36,7 @@ class CrefInfo {
|
||||||
public:
|
public:
|
||||||
string m_cookie;
|
string m_cookie;
|
||||||
string m_connName;
|
string m_connName;
|
||||||
CookieID m_cookieID;
|
CookieID m_cid;
|
||||||
int m_nPlayersSought;
|
int m_nPlayersSought;
|
||||||
int m_nPlayersHere;
|
int m_nPlayersHere;
|
||||||
XW_RELAY_STATE m_curState;
|
XW_RELAY_STATE m_curState;
|
||||||
|
@ -77,7 +77,7 @@ class CRefMgr {
|
||||||
CookieMapIterator GetCookieIterator();
|
CookieMapIterator GetCookieIterator();
|
||||||
|
|
||||||
/* PENDING. These need to go through SafeCref */
|
/* PENDING. These need to go through SafeCref */
|
||||||
void Recycle( CookieID id );
|
void Recycle( CookieID cid );
|
||||||
void Recycle_locked( CookieRef* cref );
|
void Recycle_locked( CookieRef* cref );
|
||||||
void Recycle( const char* connName );
|
void Recycle( const char* connName );
|
||||||
CookieID CookieIdForName( const char* name );
|
CookieID CookieIdForName( const char* name );
|
||||||
|
@ -131,11 +131,11 @@ class CRefMgr {
|
||||||
|
|
||||||
CidInfo* getMakeCookieRef( const char* const connName, bool* isDead );
|
CidInfo* getMakeCookieRef( const char* const connName, bool* isDead );
|
||||||
|
|
||||||
CidInfo* getCookieRef( CookieID cookieID );
|
CidInfo* getCookieRef( CookieID cid );
|
||||||
CidInfo* getCookieRef( int socket );
|
CidInfo* getCookieRef( int socket );
|
||||||
bool checkCookieRef_locked( CookieRef* cref );
|
bool checkCookieRef_locked( CookieRef* cref );
|
||||||
CidInfo* getCookieRef_impl( CookieID cookieID );
|
CidInfo* getCookieRef_impl( CookieID cid );
|
||||||
CookieRef* AddNew( const char* cookie, const char* connName, CookieID id,
|
CookieRef* AddNew( const char* cookie, const char* connName, CookieID cid,
|
||||||
int langCode, int nPlayers, int nAlreadyHere );
|
int langCode, int nPlayers, int nAlreadyHere );
|
||||||
CookieRef* FindOpenGameFor( const char* cookie, const char* connName,
|
CookieRef* FindOpenGameFor( const char* cookie, const char* connName,
|
||||||
HostID hid, int socket, int nPlayersH,
|
HostID hid, int socket, int nPlayersH,
|
||||||
|
|
Loading…
Add table
Reference in a new issue