mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2024-12-30 10:26:58 +01:00
protect refcount operations with mutex
This commit is contained in:
parent
4231ed1108
commit
d1a9b716bb
2 changed files with 9 additions and 0 deletions
|
@ -47,9 +47,11 @@ p_dict_ref( DictionaryCtxt* dict
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
if ( !!dict ) {
|
if ( !!dict ) {
|
||||||
|
pthread_mutex_lock( &dict->mutex );
|
||||||
++dict->refCount;
|
++dict->refCount;
|
||||||
XP_LOGF( "%s(dict=%p): refCount now %d (from line %d of %s() in %s)",
|
XP_LOGF( "%s(dict=%p): refCount now %d (from line %d of %s() in %s)",
|
||||||
__func__, dict, dict->refCount, line, func, file );
|
__func__, dict, dict->refCount, line, func, file );
|
||||||
|
pthread_mutex_unlock( &dict->mutex );
|
||||||
}
|
}
|
||||||
return dict;
|
return dict;
|
||||||
}
|
}
|
||||||
|
@ -62,12 +64,15 @@ p_dict_unref( DictionaryCtxt* dict
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
if ( !!dict ) {
|
if ( !!dict ) {
|
||||||
|
pthread_mutex_lock( &dict->mutex );
|
||||||
--dict->refCount;
|
--dict->refCount;
|
||||||
XP_ASSERT( 0 <= dict->refCount );
|
XP_ASSERT( 0 <= dict->refCount );
|
||||||
XP_LOGF( "%s(dict=%p): refCount now %d (from line %d of %s() in %s)",
|
XP_LOGF( "%s(dict=%p): refCount now %d (from line %d of %s() in %s)",
|
||||||
__func__, dict, dict->refCount, line, func, file );
|
__func__, dict, dict->refCount, line, func, file );
|
||||||
|
pthread_mutex_unlock( &dict->mutex );
|
||||||
if ( 0 == dict->refCount ) {
|
if ( 0 == dict->refCount ) {
|
||||||
(*dict->destructor)( dict );
|
(*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_follow = dict_super_follow;
|
||||||
dict->func_dict_edge_with_tile = dict_super_edge_with_tile;
|
dict->func_dict_edge_with_tile = dict_super_edge_with_tile;
|
||||||
dict->func_dict_getShortName = dict_getName;
|
dict->func_dict_getShortName = dict_getName;
|
||||||
|
|
||||||
|
pthread_mutex_init( &dict->mutex, NULL );
|
||||||
} /* dict_super_init */
|
} /* dict_super_init */
|
||||||
|
|
||||||
const XP_UCHAR*
|
const XP_UCHAR*
|
||||||
|
|
|
@ -72,6 +72,8 @@ struct DictionaryCtxt {
|
||||||
array_edge* from, Tile tile );
|
array_edge* from, Tile tile );
|
||||||
const XP_UCHAR* (*func_dict_getShortName)( const DictionaryCtxt* dict );
|
const XP_UCHAR* (*func_dict_getShortName)( const DictionaryCtxt* dict );
|
||||||
|
|
||||||
|
pthread_mutex_t mutex;
|
||||||
|
|
||||||
array_edge* topEdge;
|
array_edge* topEdge;
|
||||||
array_edge* base; /* the physical beginning of the dictionary; not
|
array_edge* base; /* the physical beginning of the dictionary; not
|
||||||
necessarily the entry point for search!! */
|
necessarily the entry point for search!! */
|
||||||
|
|
Loading…
Reference in a new issue