mutex tweaks

This commit is contained in:
Eric House 2024-08-24 09:46:43 -07:00
parent 28edeb1877
commit e492d8f7b5
3 changed files with 12 additions and 5 deletions

View file

@ -417,7 +417,7 @@ comms_make( MPFORMAL XWEnv xwe, XW_UtilCtxt* util, XP_Bool isServer,
XP_U16 forceChannel ) XP_U16 forceChannel )
{ {
CommsCtxt* comms = (CommsCtxt*)XP_CALLOC( mpool, sizeof(*comms) ); CommsCtxt* comms = (CommsCtxt*)XP_CALLOC( mpool, sizeof(*comms) );
MUTEX_INIT( &comms->mutex, XP_TRUE ); MUTEX_INIT_CHECKED( &comms->mutex, XP_TRUE, 3 );
comms->util = util; comms->util = util;
comms->dutil = util_getDevUtilCtxt( util, xwe ); comms->dutil = util_getDevUtilCtxt( util, xwe );
#ifdef DEBUG #ifdef DEBUG

View file

@ -22,7 +22,13 @@
#ifdef DEBUG #ifdef DEBUG
#include <unistd.h> #include <unistd.h>
#define WAIT_ALL_SECS 3 // #define WAIT_ALL_SECS 3
/* #define WAIT_ALL_SECS to enable checking for ALL mutexes, but don't do that
on Android because it kills the app (because locks in mpool are so
frequent, I suspect). I'll keep it on on Linux for testing, but even there
it limits how many games I can run at once. I really need a cleverer
implementation where a single thread checks everything....
*/
/* What is this? It's my attempt to, on debug builds and for all or only /* What is this? It's my attempt to, on debug builds and for all or only
chosen mutexes, get an assertion when the app doesn't get a lock in the chosen mutexes, get an assertion when the app doesn't get a lock in the
@ -95,9 +101,9 @@ mtx_lock_prv( MutexState* state, XP_U16 waitSecs,
(void)pthread_create( &waitThread, NULL, checkLockProc, &ws ); (void)pthread_create( &waitThread, NULL, checkLockProc, &ws );
int count = 0; int count = 0;
while ( !ws.flagLoc ) { while ( !ws.flagLoc ) {
usleep(50); /* wait for thread to start */ usleep(500); /* wait for thread to start */
if ( 0 == (++count%10) ) { if ( 0 == (++count%10) ) {
XP_LOGFF( "count %d; flagLoc still null", count ); // XP_LOGFF( "count %d; flagLoc still null", count );
} }
} }
} }

View file

@ -19,7 +19,8 @@
BUILD_DIR ?= . BUILD_DIR ?= .
ifeq ($(MEMDEBUG),TRUE) ifeq ($(MEMDEBUG),TRUE)
DEFINES = -DMEM_DEBUG -DDEBUG -DENABLE_LOGGING -DNUMBER_KEY_AS_INDEX DEFINES = -DMEM_DEBUG -DDEBUG -DENABLE_LOGGING -DNUMBER_KEY_AS_INDEX
DEFINES += -DWAIT_ALL_SECS=3
DEFINES += -DLOG_COMMS_MSGNOS DEFINES += -DLOG_COMMS_MSGNOS
DEFINES += -DDI_DEBUG DEFINES += -DDI_DEBUG
CFLAGS += -g $(GPROFFLAG) -Wall -Wunused-parameter -Wcast-align -Werror -O0 CFLAGS += -g $(GPROFFLAG) -Wall -Wunused-parameter -Wcast-align -Werror -O0