diff --git a/xwords4/common/dictnry.c b/xwords4/common/dictnry.c index 15130444d..08a9650e7 100644 --- a/xwords4/common/dictnry.c +++ b/xwords4/common/dictnry.c @@ -47,9 +47,11 @@ p_dict_ref( DictionaryCtxt* dict ) { if ( !!dict ) { + pthread_mutex_lock( &dict->mutex ); ++dict->refCount; XP_LOGF( "%s(dict=%p): refCount now %d (from line %d of %s() in %s)", __func__, dict, dict->refCount, line, func, file ); + pthread_mutex_unlock( &dict->mutex ); } return dict; } @@ -62,12 +64,15 @@ p_dict_unref( DictionaryCtxt* dict ) { if ( !!dict ) { + pthread_mutex_lock( &dict->mutex ); --dict->refCount; XP_ASSERT( 0 <= dict->refCount ); XP_LOGF( "%s(dict=%p): refCount now %d (from line %d of %s() in %s)", __func__, dict, dict->refCount, line, func, file ); + pthread_mutex_unlock( &dict->mutex ); if ( 0 == dict->refCount ) { (*dict->destructor)( dict ); + pthread_mutex_destroy( &dict->mutex ); } } } @@ -776,6 +781,8 @@ dict_super_init( DictionaryCtxt* dict ) dict->func_dict_follow = dict_super_follow; dict->func_dict_edge_with_tile = dict_super_edge_with_tile; dict->func_dict_getShortName = dict_getName; + + pthread_mutex_init( &dict->mutex, NULL ); } /* dict_super_init */ const XP_UCHAR* diff --git a/xwords4/common/dictnry.h b/xwords4/common/dictnry.h index af96d1599..1d1296257 100644 --- a/xwords4/common/dictnry.h +++ b/xwords4/common/dictnry.h @@ -72,6 +72,8 @@ struct DictionaryCtxt { array_edge* from, Tile tile ); const XP_UCHAR* (*func_dict_getShortName)( const DictionaryCtxt* dict ); + pthread_mutex_t mutex; + array_edge* topEdge; array_edge* base; /* the physical beginning of the dictionary; not necessarily the entry point for search!! */