mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-02-15 08:47:56 +01:00
add thread checking for more comms methods
And add a hack for that requiring non-const decls for DEBUG builds
This commit is contained in:
parent
973a60a8f3
commit
707c9a08b1
4 changed files with 28 additions and 10 deletions
|
@ -105,14 +105,16 @@ typedef struct _SD {
|
|||
StackData _data = { .func = __func__, \
|
||||
.prev = _sdp->head, \
|
||||
.prevThread = _sdp->thread, \
|
||||
.count = NULL == _data.prev ? 0 : _data.prev->count + 1, \
|
||||
}; \
|
||||
_data.count = NULL == _data.prev ? 0 : _data.prev->count + 1; \
|
||||
\
|
||||
(OBJ)->_sd.head = &_data; \
|
||||
pthread_t thread = pthread_self(); \
|
||||
if ( 0 == (OBJ)->_sd.thread ) { \
|
||||
(OBJ)->_sd.thread = thread; \
|
||||
} else if ( thread != (OBJ)->_sd.thread ) { \
|
||||
XP_LOGFF( "ERROR: from %s(); new thread: %lX; old thread: %lX", \
|
||||
__func__, thread, (OBJ)->_sd.thread ); \
|
||||
printStack( &_data ); \
|
||||
XP_ASSERT(0); \
|
||||
} \
|
||||
|
@ -528,7 +530,7 @@ static void
|
|||
forEachElem( CommsCtxt* comms, EachMsgProc proc, void* closure )
|
||||
|
||||
{
|
||||
THREAD_CHECK_START(comms);
|
||||
THREAD_CHECK_START(comms); /* firing */
|
||||
for ( AddressRecord* recs = comms->recs; !!recs; recs = recs->next ) {
|
||||
for ( MsgQueueElem** home = &recs->_msgQueueHead; !!*home; ) {
|
||||
MsgQueueElem* elem = *home;
|
||||
|
@ -622,6 +624,7 @@ set_reset_timer( CommsCtxt* comms, XWEnv xwe )
|
|||
void
|
||||
comms_destroy( CommsCtxt* comms, XWEnv xwe )
|
||||
{
|
||||
THREAD_CHECK_START(comms);
|
||||
/* did I call comms_stop()? */
|
||||
XP_ASSERT( ! addr_hasType( &comms->selfAddr, COMMS_CONN_RELAY )
|
||||
|| COMMS_RELAYSTATE_UNCONNECTED == comms->rr.relayState );
|
||||
|
@ -631,6 +634,7 @@ comms_destroy( CommsCtxt* comms, XWEnv xwe )
|
|||
|
||||
util_clearTimer( comms->util, xwe, TIMER_COMMS );
|
||||
|
||||
THREAD_CHECK_END();
|
||||
XP_FREE( comms->mpool, comms );
|
||||
} /* comms_destroy */
|
||||
|
||||
|
@ -1146,6 +1150,7 @@ elemToStream( MsgQueueElem* elem, void* closure )
|
|||
void
|
||||
comms_writeToStream( CommsCtxt* comms, XWStreamCtxt* stream, XP_U16 saveToken )
|
||||
{
|
||||
THREAD_CHECK_START(comms);
|
||||
XP_U16 nAddrRecs;
|
||||
AddressRecord* rec;
|
||||
|
||||
|
@ -1225,6 +1230,7 @@ comms_writeToStream( CommsCtxt* comms, XWStreamCtxt* stream, XP_U16 saveToken )
|
|||
}
|
||||
|
||||
comms->lastSaveToken = saveToken;
|
||||
THREAD_CHECK_END();
|
||||
} /* comms_writeToStream */
|
||||
|
||||
static void
|
||||
|
@ -1404,16 +1410,18 @@ countNonAcks( MsgQueueElem* elem, void* closure )
|
|||
}
|
||||
|
||||
XP_U16
|
||||
comms_countPendingPackets( const CommsCtxt* comms, XP_Bool* quashed )
|
||||
comms_countPendingPackets( RELCONST CommsCtxt* comms, XP_Bool* quashed )
|
||||
{
|
||||
NonAcks na = {0};
|
||||
THREAD_CHECK_START(comms);
|
||||
if ( !!quashed ) {
|
||||
*quashed = QUASHED(comms);
|
||||
}
|
||||
|
||||
NonAcks na = {0};
|
||||
forEachElem( (CommsCtxt*)comms, countNonAcks, &na );
|
||||
|
||||
// COMMS_LOGFF( "=> %d (queueLen = %d)", na.count, comms->queueLen );
|
||||
THREAD_CHECK_END();
|
||||
return na.count;
|
||||
}
|
||||
|
||||
|
@ -1750,12 +1758,14 @@ getInvitedProc( MsgQueueElem* elem, void* closure )
|
|||
}
|
||||
|
||||
void
|
||||
comms_getInvited( const CommsCtxt* comms, XP_U16* nInvites )
|
||||
comms_getInvited( RELCONST CommsCtxt* comms, XP_U16* nInvites )
|
||||
{
|
||||
THREAD_CHECK_START(comms);
|
||||
GetInvitedData gid = {0};
|
||||
forEachElem( (CommsCtxt*)comms, getInvitedProc, &gid );
|
||||
*nInvites = gid.count;
|
||||
// LOG_RETURNF( "%d", *nInvites );
|
||||
THREAD_CHECK_END();
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -3388,8 +3398,9 @@ statsProc( MsgQueueElem* elem, void* closure )
|
|||
}
|
||||
|
||||
void
|
||||
comms_getStats( const CommsCtxt* comms, XWStreamCtxt* stream )
|
||||
comms_getStats( RELCONST CommsCtxt* comms, XWStreamCtxt* stream )
|
||||
{
|
||||
THREAD_CHECK_START(comms);
|
||||
XP_UCHAR buf[100];
|
||||
|
||||
XP_SNPRINTF( (XP_UCHAR*)buf, sizeof(buf),
|
||||
|
@ -3416,6 +3427,7 @@ comms_getStats( const CommsCtxt* comms, XWStreamCtxt* stream )
|
|||
rec->lastMsgRcd );
|
||||
stream_catString( stream, buf );
|
||||
}
|
||||
THREAD_CHECK_END();
|
||||
} /* comms_getStats */
|
||||
|
||||
void
|
||||
|
|
|
@ -173,7 +173,7 @@ void comms_getAddrs( const CommsCtxt* comms, CommsAddrRec addr[],
|
|||
XP_Bool comms_formatRelayID( const CommsCtxt* comms, XP_U16 indx,
|
||||
XP_UCHAR* buf, XP_U16* lenp );
|
||||
|
||||
XP_U16 comms_countPendingPackets( const CommsCtxt* comms, XP_Bool* quashed );
|
||||
XP_U16 comms_countPendingPackets( RELCONST CommsCtxt* comms, XP_Bool* quashed );
|
||||
|
||||
|
||||
#ifdef XWFEATURE_RELAY
|
||||
|
@ -206,7 +206,7 @@ void addrToStream( XWStreamCtxt* stream, const CommsAddrRec* addr );
|
|||
#ifdef XWFEATURE_COMMS_INVITE
|
||||
void comms_invite( CommsCtxt* comms, XWEnv xwe, const NetLaunchInfo* nli,
|
||||
const CommsAddrRec* destAddr, XP_Bool sendNow );
|
||||
void comms_getInvited( const CommsCtxt* comms, XP_U16* nInvites );
|
||||
void comms_getInvited( RELCONST CommsCtxt* comms, XP_U16* nInvites );
|
||||
#endif
|
||||
XP_S16 comms_send( CommsCtxt* comms, XWEnv xwe, XWStreamCtxt* stream );
|
||||
XP_S16 comms_resendAll( CommsCtxt* comms, XWEnv xwe, CommsConnType filter,
|
||||
|
@ -272,7 +272,7 @@ void comms_gatherPlayers( CommsCtxt* comms, XWEnv xwe, XP_U32 created );
|
|||
const char* ConnType2Str( CommsConnType typ );
|
||||
|
||||
# ifdef DEBUG
|
||||
void comms_getStats( const CommsCtxt* comms, XWStreamCtxt* stream );
|
||||
void comms_getStats( RELCONST CommsCtxt* comms, XWStreamCtxt* stream );
|
||||
const char* CommsRelayState2Str( CommsRelayState state );
|
||||
const char* XWREASON2Str( XWREASON reason );
|
||||
|
||||
|
|
|
@ -22,6 +22,12 @@
|
|||
#ifndef _COMTYPES_H_
|
||||
#define _COMTYPES_H_
|
||||
|
||||
#ifdef DEBUG
|
||||
# define RELCONST
|
||||
#else
|
||||
# define RELCONST const
|
||||
#endif
|
||||
|
||||
#include "xptypes.h"
|
||||
|
||||
#ifndef EXTERN_C_START
|
||||
|
|
|
@ -559,7 +559,7 @@ static void
|
|||
informMissing( const ServerCtxt* server, XWEnv xwe )
|
||||
{
|
||||
const XP_Bool isHost = amHost( server );
|
||||
const CommsCtxt* comms = server->vol.comms;
|
||||
RELCONST CommsCtxt* comms = server->vol.comms;
|
||||
const CurGameInfo* gi = server->vol.gi;
|
||||
XP_U16 nInvited = 0;
|
||||
CommsAddrRec selfAddr;
|
||||
|
|
Loading…
Add table
Reference in a new issue