comment out internal mutexes: shouldn't be needed now that only one

thread at a time is given access to a cref instance.
This commit is contained in:
ehouse 2005-09-14 05:15:27 +00:00
parent 1afdfa3732
commit 86c42c40c0
2 changed files with 49 additions and 49 deletions

View file

@ -77,8 +77,8 @@ CookieRef::CookieRef( const char* s, CookieID id )
, m_totalSent(0) , m_totalSent(0)
, m_curState(XW_ST_INITED) , m_curState(XW_ST_INITED)
{ {
pthread_rwlock_init( &m_sockets_rwlock, NULL ); /* pthread_rwlock_init( &m_sockets_rwlock, NULL ); */
pthread_mutex_init( &m_EventsMutex, NULL ); /* pthread_mutex_init( &m_EventsMutex, NULL ); */
if ( id == 0 ) { if ( id == 0 ) {
MutexLock ml( &g_IdsMutex ); MutexLock ml( &g_IdsMutex );
@ -96,7 +96,7 @@ CookieRef::~CookieRef()
XWThreadPool* tPool = XWThreadPool::GetTPool(); XWThreadPool* tPool = XWThreadPool::GetTPool();
for ( ; ; ) { for ( ; ; ) {
RWWriteLock rwl( &m_sockets_rwlock ); /* RWWriteLock rwl( &m_sockets_rwlock ); */
map<HostID,HostRec>::iterator iter = m_sockets.begin(); map<HostID,HostRec>::iterator iter = m_sockets.begin();
if ( iter == m_sockets.end() ) { if ( iter == m_sockets.end() ) {
@ -108,18 +108,18 @@ CookieRef::~CookieRef()
m_sockets.erase( iter ); m_sockets.erase( iter );
} }
pthread_rwlock_destroy( &m_sockets_rwlock ); /* pthread_rwlock_destroy( &m_sockets_rwlock ); */
logf( "CookieRef for %d being deleted", m_connectionID ); logf( "CookieRef for %d being deleted", m_connectionID );
pthread_mutex_destroy( &m_EventsMutex ); /* pthread_mutex_destroy( &m_EventsMutex ); */
pthread_rwlock_destroy( &m_sockets_rwlock ); /* pthread_rwlock_destroy( &m_sockets_rwlock ); */
} /* ~CookieRef */ } /* ~CookieRef */
void void
CookieRef::_Connect( int socket, HostID srcID ) CookieRef::_Connect( int socket, HostID srcID )
{ {
CRefMgr::Get()->Associate( socket, this ); CRefMgr::Get()->Associate( socket, this );
MutexLock ml( &m_EventsMutex ); /* MutexLock ml( &m_EventsMutex ); */
pushConnectEvent( socket, srcID ); pushConnectEvent( socket, srcID );
handleEvents(); handleEvents();
} }
@ -128,7 +128,7 @@ void
CookieRef::_Reconnect( int socket, HostID srcID ) CookieRef::_Reconnect( int socket, HostID srcID )
{ {
CRefMgr::Get()->Associate( socket, this ); CRefMgr::Get()->Associate( socket, this );
MutexLock ml( &m_EventsMutex ); /* MutexLock ml( &m_EventsMutex ); */
pushReconnectEvent( socket, srcID ); pushReconnectEvent( socket, srcID );
handleEvents(); handleEvents();
} }
@ -138,10 +138,10 @@ CookieRef::_Disconnect( int socket, HostID hostID )
{ {
CRefMgr::Get()->Disassociate( socket, this ); CRefMgr::Get()->Disassociate( socket, this );
MutexLock ml( &m_EventsMutex ); /* MutexLock ml( &m_EventsMutex ); */
CRefEvent evt; CRefEvent evt;
evt.type = XW_EVENT_DISCONNECTMSG; evt.type = XW_EVT_DISCONNECTMSG;
evt.u.discon.socket = socket; evt.u.discon.socket = socket;
evt.u.discon.srcID = hostID; evt.u.discon.srcID = hostID;
m_eventQueue.push_back( evt ); m_eventQueue.push_back( evt );
@ -193,7 +193,7 @@ CookieRef::removeSocket( int socket )
{ {
int count; int count;
{ {
RWWriteLock rwl( &m_sockets_rwlock ); /* RWWriteLock rwl( &m_sockets_rwlock ); */
count = m_sockets.size(); count = m_sockets.size();
assert( count > 0 ); assert( count > 0 );
@ -218,7 +218,7 @@ CookieRef::HasSocket( int socket )
{ {
int found = 0; int found = 0;
logf( "CookieRef::HasSocket" ); logf( "CookieRef::HasSocket" );
RWReadLock rwl( &m_sockets_rwlock ); /* RWReadLock rwl( &m_sockets_rwlock ); */
map<HostID,HostRec>::iterator iter = m_sockets.begin(); map<HostID,HostRec>::iterator iter = m_sockets.begin();
while ( iter != m_sockets.end() ) { while ( iter != m_sockets.end() ) {
@ -234,7 +234,7 @@ CookieRef::HasSocket( int socket )
void void
CookieRef::_HandleHeartbeat( HostID id, int socket ) CookieRef::_HandleHeartbeat( HostID id, int socket )
{ {
MutexLock ml( &m_EventsMutex ); /* MutexLock ml( &m_EventsMutex ); */
pushHeartbeatEvent( id, socket ); pushHeartbeatEvent( id, socket );
handleEvents(); handleEvents();
} /* HandleHeartbeat */ } /* HandleHeartbeat */
@ -243,9 +243,9 @@ void
CookieRef::_CheckHeartbeats( time_t now ) CookieRef::_CheckHeartbeats( time_t now )
{ {
logf( "CookieRef::_CheckHeartbeats" ); logf( "CookieRef::_CheckHeartbeats" );
MutexLock ml( &m_EventsMutex ); /* MutexLock ml( &m_EventsMutex ); */
{ {
RWReadLock rwl( &m_sockets_rwlock ); /* RWReadLock rwl( &m_sockets_rwlock ); */
map<HostID,HostRec>::iterator iter = m_sockets.begin(); map<HostID,HostRec>::iterator iter = m_sockets.begin();
while ( iter != m_sockets.end() ) { while ( iter != m_sockets.end() ) {
time_t last = iter->second.m_lastHeartbeat; time_t last = iter->second.m_lastHeartbeat;
@ -261,7 +261,7 @@ CookieRef::_CheckHeartbeats( time_t now )
void void
CookieRef::_Forward( HostID src, HostID dest, unsigned char* buf, int buflen ) CookieRef::_Forward( HostID src, HostID dest, unsigned char* buf, int buflen )
{ {
MutexLock ml( &m_EventsMutex ); /* MutexLock ml( &m_EventsMutex ); */
pushForwardEvent( src, dest, buf, buflen ); pushForwardEvent( src, dest, buf, buflen );
handleEvents(); handleEvents();
} /* Forward */ } /* Forward */
@ -269,7 +269,7 @@ CookieRef::_Forward( HostID src, HostID dest, unsigned char* buf, int buflen )
void void
CookieRef::_Remove( int socket ) CookieRef::_Remove( int socket )
{ {
MutexLock ml( &m_EventsMutex ); /* MutexLock ml( &m_EventsMutex ); */
pushRemoveSocketEvent( socket ); pushRemoveSocketEvent( socket );
handleEvents(); handleEvents();
} /* Forward */ } /* Forward */
@ -278,7 +278,7 @@ void
CookieRef::pushConnectEvent( int socket, HostID srcID ) CookieRef::pushConnectEvent( int socket, HostID srcID )
{ {
CRefEvent evt; CRefEvent evt;
evt.type = XW_EVENT_CONNECTMSG; evt.type = XW_EVT_CONNECTMSG;
evt.u.con.socket = socket; evt.u.con.socket = socket;
evt.u.con.srcID = srcID; evt.u.con.srcID = srcID;
m_eventQueue.push_back( evt ); m_eventQueue.push_back( evt );
@ -288,7 +288,7 @@ void
CookieRef::pushReconnectEvent( int socket, HostID srcID ) CookieRef::pushReconnectEvent( int socket, HostID srcID )
{ {
CRefEvent evt; CRefEvent evt;
evt.type = XW_EVENT_RECONNECTMSG; evt.type = XW_EVT_RECONNECTMSG;
evt.u.con.socket = socket; evt.u.con.socket = socket;
evt.u.con.srcID = srcID; evt.u.con.srcID = srcID;
m_eventQueue.push_back( evt ); m_eventQueue.push_back( evt );
@ -298,7 +298,7 @@ void
CookieRef::pushHeartbeatEvent( HostID id, int socket ) CookieRef::pushHeartbeatEvent( HostID id, int socket )
{ {
CRefEvent evt; CRefEvent evt;
evt.type = XW_EVENT_HEARTRCVD; evt.type = XW_EVT_HEARTRCVD;
evt.u.heart.id = id; evt.u.heart.id = id;
evt.u.heart.socket = socket; evt.u.heart.socket = socket;
m_eventQueue.push_back( evt ); m_eventQueue.push_back( evt );
@ -308,7 +308,7 @@ void
CookieRef::pushHeartFailedEvent( int socket ) CookieRef::pushHeartFailedEvent( int socket )
{ {
CRefEvent evt; CRefEvent evt;
evt.type = XW_EVENT_HEARTFAILED; evt.type = XW_EVT_HEARTFAILED;
evt.u.heart.socket = socket; evt.u.heart.socket = socket;
m_eventQueue.push_back( evt ); m_eventQueue.push_back( evt );
} }
@ -318,7 +318,7 @@ CookieRef::pushForwardEvent( HostID src, HostID dest,
unsigned char* buf, int buflen ) unsigned char* buf, int buflen )
{ {
CRefEvent evt; CRefEvent evt;
evt.type = XW_EVENT_FORWARDMSG; evt.type = XW_EVT_FORWARDMSG;
evt.u.fwd.src = src; evt.u.fwd.src = src;
evt.u.fwd.dest = dest; evt.u.fwd.dest = dest;
evt.u.fwd.buf = buf; evt.u.fwd.buf = buf;
@ -330,7 +330,7 @@ void
CookieRef::pushRemoveSocketEvent( int socket ) CookieRef::pushRemoveSocketEvent( int socket )
{ {
CRefEvent evt; CRefEvent evt;
evt.type = XW_EVENT_REMOVESOCKET; evt.type = XW_EVT_REMOVESOCKET;
evt.u.rmsock.socket = socket; evt.u.rmsock.socket = socket;
m_eventQueue.push_back( evt ); m_eventQueue.push_back( evt );
} }
@ -339,7 +339,7 @@ void
CookieRef::pushNotifyDisconEvent( int socket, XWREASON why ) CookieRef::pushNotifyDisconEvent( int socket, XWREASON why )
{ {
CRefEvent evt; CRefEvent evt;
evt.type = XW_EVENT_NOTIFYDISCON; evt.type = XW_EVT_NOTIFYDISCON;
evt.u.disnote.socket = socket; evt.u.disnote.socket = socket;
evt.u.disnote.why = why; evt.u.disnote.why = why;
m_eventQueue.push_back( evt ); m_eventQueue.push_back( evt );
@ -349,7 +349,7 @@ void
CookieRef::pushDestBadEvent() CookieRef::pushDestBadEvent()
{ {
CRefEvent evt; CRefEvent evt;
evt.type = XW_EVENT_DESTBAD; evt.type = XW_EVT_DESTBAD;
m_eventQueue.push_back( evt ); m_eventQueue.push_back( evt );
} }
@ -358,7 +358,7 @@ CookieRef::pushDestOkEvent( const CRefEvent* oldEvt )
{ {
CRefEvent evt; CRefEvent evt;
memcpy( &evt, oldEvt, sizeof(evt) ); memcpy( &evt, oldEvt, sizeof(evt) );
evt.type = XW_EVENT_DESTOK; evt.type = XW_EVT_DESTOK;
m_eventQueue.push_back( evt ); m_eventQueue.push_back( evt );
} }
@ -367,7 +367,7 @@ CookieRef::pushCanLockEvent( const CRefEvent* oldEvt )
{ {
CRefEvent evt; CRefEvent evt;
memcpy( &evt, oldEvt, sizeof(evt) ); memcpy( &evt, oldEvt, sizeof(evt) );
evt.type = XW_EVENT_CAN_LOCK; evt.type = XW_EVT_CAN_LOCK;
m_eventQueue.push_back( evt ); m_eventQueue.push_back( evt );
} }
@ -376,7 +376,7 @@ CookieRef::pushCantLockEvent( const CRefEvent* oldEvt )
{ {
CRefEvent evt; CRefEvent evt;
memcpy( &evt, oldEvt, sizeof(evt) ); memcpy( &evt, oldEvt, sizeof(evt) );
evt.type = XW_EVENT_CANT_LOCK; evt.type = XW_EVT_CANT_LOCK;
m_eventQueue.push_back( evt ); m_eventQueue.push_back( evt );
} }
@ -384,7 +384,7 @@ void
CookieRef::pushLastSocketGoneEvent() CookieRef::pushLastSocketGoneEvent()
{ {
CRefEvent evt; CRefEvent evt;
evt.type = XW_EVENT_NOMORESOCKETS; evt.type = XW_EVT_NOMORESOCKETS;
m_eventQueue.push_back( evt ); m_eventQueue.push_back( evt );
} }
@ -404,59 +404,59 @@ CookieRef::handleEvents()
stateString(m_nextState), eventString(evt.type) ); stateString(m_nextState), eventString(evt.type) );
switch( takeAction ) { switch( takeAction ) {
case XW_ACTION_SEND_1ST_RSP: case XW_ACT_SEND_1ST_RSP:
setAllConnectedTimer(); setAllConnectedTimer();
sendResponse( &evt ); sendResponse( &evt );
break; break;
case XW_ACTION_SENDRSP: case XW_ACT_SENDRSP:
notifyOthers( evt.u.con.socket, XWRELAY_OTHERCONNECT, notifyOthers( evt.u.con.socket, XWRELAY_OTHERCONNECT,
XWRELAY_ERROR_NONE ); XWRELAY_ERROR_NONE );
sendResponse( &evt ); sendResponse( &evt );
break; break;
case XW_ACTION_FWD: case XW_ACT_FWD:
forward( &evt ); forward( &evt );
break; break;
case XW_ACTION_CHECKDEST: case XW_ACT_CHECKDEST:
checkDest( &evt ); checkDest( &evt );
break; break;
case XW_ACTION_CHECK_CAN_LOCK: case XW_ACT_CHECK_CAN_LOCK:
checkFromServer( &evt ); checkFromServer( &evt );
break; break;
case XW_ACTION_TIMERDISCONNECT: case XW_ACT_TIMERDISCONNECT:
disconnectSockets( 0, XWRELAY_ERROR_TIMEOUT ); disconnectSockets( 0, XWRELAY_ERROR_TIMEOUT );
break; break;
case XW_ACTION_HEARTDISCONNECT: case XW_ACT_HEARTDISCONNECT:
notifyOthers( evt.u.heart.socket, XWRELAY_DISCONNECT_OTHER, notifyOthers( evt.u.heart.socket, XWRELAY_DISCONNECT_OTHER,
XWRELAY_ERROR_HEART_OTHER ); XWRELAY_ERROR_HEART_OTHER );
disconnectSockets( evt.u.heart.socket, disconnectSockets( evt.u.heart.socket,
XWRELAY_ERROR_HEART_YOU ); XWRELAY_ERROR_HEART_YOU );
break; break;
case XW_ACTION_DISCONNECT: case XW_ACT_DISCONNECT:
removeSocket( evt.u.discon.socket ); removeSocket( evt.u.discon.socket );
/* Don't notify. This is a normal part of a game ending. */ /* Don't notify. This is a normal part of a game ending. */
break; break;
case XW_ACTION_NOTEHEART: case XW_ACT_NOTEHEART:
noteHeartbeat( &evt ); noteHeartbeat( &evt );
break; break;
case XW_ACTION_NOTIFYDISCON: case XW_ACT_NOTIFYDISCON:
notifyDisconn( &evt ); notifyDisconn( &evt );
break; break;
case XW_ACTION_REMOVESOCKET: case XW_ACT_REMOVESOCKET:
notifyOthers( evt.u.rmsock.socket, XWRELAY_DISCONNECT_OTHER, notifyOthers( evt.u.rmsock.socket, XWRELAY_DISCONNECT_OTHER,
XWRELAY_ERROR_LOST_OTHER ); XWRELAY_ERROR_LOST_OTHER );
removeSocket( evt.u.rmsock.socket ); removeSocket( evt.u.rmsock.socket );
break; break;
case XW_ACTION_NONE: case XW_ACT_NONE:
/* nothing to do for these */ /* nothing to do for these */
break; break;
@ -525,7 +525,7 @@ CookieRef::sendResponse( const CRefEvent* evt )
assert( id != HOST_ID_NONE ); assert( id != HOST_ID_NONE );
logf( "remembering pair: hostid=%x, socket=%d", id, socket ); logf( "remembering pair: hostid=%x, socket=%d", id, socket );
RWWriteLock ml( &m_sockets_rwlock ); /* RWWriteLock ml( &m_sockets_rwlock ); */
HostRec hr(socket); HostRec hr(socket);
m_sockets.insert( pair<HostID,HostRec>(id,hr) ); m_sockets.insert( pair<HostID,HostRec>(id,hr) );
@ -616,7 +616,7 @@ CookieRef::notifyOthers( int socket, XWRelayMsg msg, XWREASON why )
{ {
assert( socket != 0 ); assert( socket != 0 );
RWReadLock ml( &m_sockets_rwlock ); /* RWReadLock ml( &m_sockets_rwlock ); */
map<HostID,HostRec>::iterator iter = m_sockets.begin(); map<HostID,HostRec>::iterator iter = m_sockets.begin();
while ( iter != m_sockets.end() ) { while ( iter != m_sockets.end() ) {
@ -632,7 +632,7 @@ void
CookieRef::disconnectSockets( int socket, XWREASON why ) CookieRef::disconnectSockets( int socket, XWREASON why )
{ {
if ( socket == 0 ) { if ( socket == 0 ) {
RWReadLock ml( &m_sockets_rwlock ); /* RWReadLock ml( &m_sockets_rwlock ); */
map<HostID,HostRec>::iterator iter = m_sockets.begin(); map<HostID,HostRec>::iterator iter = m_sockets.begin();
while ( iter != m_sockets.end() ) { while ( iter != m_sockets.end() ) {
assert( iter->second.m_socket != 0 ); assert( iter->second.m_socket != 0 );
@ -651,7 +651,7 @@ CookieRef::noteHeartbeat( const CRefEvent* evt )
int socket = evt->u.heart.socket; int socket = evt->u.heart.socket;
HostID id = evt->u.heart.id; HostID id = evt->u.heart.id;
RWWriteLock rwl( &m_sockets_rwlock ); /* RWWriteLock rwl( &m_sockets_rwlock ); */
map<HostID,HostRec>::iterator iter = m_sockets.find(id); map<HostID,HostRec>::iterator iter = m_sockets.find(id);
if ( iter == m_sockets.end() ) { if ( iter == m_sockets.end() ) {
@ -684,9 +684,9 @@ void
CookieRef::_CheckAllConnected() CookieRef::_CheckAllConnected()
{ {
logf( "checkAllConnected" ); logf( "checkAllConnected" );
MutexLock ml( &m_EventsMutex ); /* MutexLock ml( &m_EventsMutex ); */
CRefEvent newEvt; CRefEvent newEvt;
newEvt.type = XW_EVENT_CONNTIMER; newEvt.type = XW_EVT_CONNTIMER;
m_eventQueue.push_back( newEvt ); m_eventQueue.push_back( newEvt );
handleEvents(); handleEvents();
} }

View file

@ -168,7 +168,7 @@ class CookieRef {
static void s_checkAllConnected( void* closure ); static void s_checkAllConnected( void* closure );
map<HostID,HostRec> m_sockets; map<HostID,HostRec> m_sockets;
pthread_rwlock_t m_sockets_rwlock; /* pthread_rwlock_t m_sockets_rwlock; */
CookieID m_connectionID; CookieID m_connectionID;
short m_heatbeat; /* might change per carrier or something. */ short m_heatbeat; /* might change per carrier or something. */
@ -178,7 +178,7 @@ class CookieRef {
/* Guard the event queue. Only one thread at a time can post to the /* Guard the event queue. Only one thread at a time can post to the
queue, but once in a thread can post new events while processing queue, but once in a thread can post new events while processing
current ones. */ current ones. */
pthread_mutex_t m_EventsMutex; /* pthread_mutex_t m_EventsMutex; */
XW_RELAY_STATE m_curState; XW_RELAY_STATE m_curState;