mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-30 08:34:16 +01:00
use semaphore to protect known players data
Requires adding a common method called by platform code on creating a new dutil ctxt.
This commit is contained in:
parent
479ec4ef44
commit
f90d76329b
6 changed files with 17 additions and 4 deletions
|
@ -86,6 +86,7 @@ COMMON_SRC_FILES += \
|
|||
$(COMMON_PATH)/dbgutil.c \
|
||||
$(COMMON_PATH)/nli.c \
|
||||
$(COMMON_PATH)/smsproto.c \
|
||||
$(COMMON_PATH)/dutil.c \
|
||||
$(COMMON_PATH)/device.c \
|
||||
$(COMMON_PATH)/knownplyr.c \
|
||||
|
||||
|
|
|
@ -1006,6 +1006,7 @@ makeDUtil( MPFORMAL JNIEnv* env,
|
|||
JNIUtilCtxt* jniutil, void* closure )
|
||||
{
|
||||
AndDUtil* dutil = (AndDUtil*)XP_CALLOC( mpool, sizeof(*dutil) );
|
||||
dutil_super_init( MPPARM(mpool) &dutil->dutil );
|
||||
#ifdef MAP_THREAD_TO_ENV
|
||||
dutil->ti = ti;
|
||||
#endif
|
||||
|
@ -1017,8 +1018,6 @@ makeDUtil( MPFORMAL JNIEnv* env,
|
|||
dutil->jdutil = (*env)->NewGlobalRef( env, jdutil );
|
||||
}
|
||||
|
||||
MPASSIGN( dutil->dutil.mpool, mpool );
|
||||
|
||||
DUtilVtable* vtable = &dutil->dutil.vtable;
|
||||
#define SET_DPROC(nam) vtable->m_dutil_##nam = and_dutil_##nam
|
||||
SET_DPROC(getCurSeconds);
|
||||
|
|
|
@ -49,6 +49,7 @@ COMMONSRC = \
|
|||
$(COMMONDIR)/dictmgr.c \
|
||||
$(COMMONDIR)/dbgutil.c \
|
||||
$(COMMONDIR)/smsproto.c \
|
||||
$(COMMONDIR)/dutil.c \
|
||||
$(COMMONDIR)/device.c \
|
||||
|
||||
# PENDING: define this in terms of above!!!
|
||||
|
@ -88,6 +89,7 @@ COMMON5 = \
|
|||
$(COMMONOBJDIR)/dictmgr.o \
|
||||
$(COMMONOBJDIR)/dbgutil.o \
|
||||
$(COMMONOBJDIR)/smsproto.o \
|
||||
$(COMMONOBJDIR)/dutil.o \
|
||||
$(COMMONOBJDIR)/device.o \
|
||||
$(COMMONOBJDIR)/knownplyr.o \
|
||||
|
||||
|
|
|
@ -84,11 +84,16 @@ struct XW_DUtilCtxt {
|
|||
DUtilVtable vtable;
|
||||
void* closure;
|
||||
void* devCtxt; /* owned by device.c */
|
||||
void* kpCtxt; /* owned by knownplyr.c */
|
||||
#ifdef XWFEATURE_KNOWNPLAYERS /* owned by knownplyr.c */
|
||||
void* kpCtxt;
|
||||
pthread_mutex_t kpMutex;
|
||||
#endif
|
||||
VTableMgr* vtMgr;
|
||||
MPSLOT
|
||||
};
|
||||
|
||||
void dutil_super_init( MPFORMAL XW_DUtilCtxt* dutil );
|
||||
|
||||
/* This one cheats: direct access */
|
||||
#define dutil_getVTManager(duc) (duc)->vtMgr
|
||||
|
||||
|
|
|
@ -64,6 +64,8 @@ static KPState*
|
|||
loadState( XW_DUtilCtxt* dutil, XWEnv xwe )
|
||||
{
|
||||
LOG_FUNC();
|
||||
pthread_mutex_lock( &dutil->kpMutex );
|
||||
|
||||
KPState* state = (KPState*)dutil->kpCtxt;
|
||||
if ( NULL == state ) {
|
||||
dutil->kpCtxt = state = XP_CALLOC( dutil->mpool, sizeof(*state) );
|
||||
|
@ -107,6 +109,8 @@ releaseState( XW_DUtilCtxt* dutil, XWEnv xwe, KPState* state )
|
|||
XP_ASSERT( state->inUse );
|
||||
saveState( dutil, xwe, state );
|
||||
state->inUse = XP_FALSE;
|
||||
|
||||
pthread_mutex_unlock( &dutil->kpMutex );
|
||||
}
|
||||
|
||||
static const XP_UCHAR*
|
||||
|
|
|
@ -133,6 +133,9 @@ XW_DUtilCtxt*
|
|||
dutils_init( MPFORMAL VTableMgr* vtMgr, void* closure )
|
||||
{
|
||||
XW_DUtilCtxt* result = XP_CALLOC( mpool, sizeof(*result) );
|
||||
|
||||
dutil_super_init( MPPARM(mpool) result );
|
||||
|
||||
result->vtMgr = vtMgr;
|
||||
result->closure = closure;
|
||||
|
||||
|
@ -170,7 +173,6 @@ dutils_init( MPFORMAL VTableMgr* vtMgr, void* closure )
|
|||
|
||||
assertTableFull( &result->vtable, sizeof(result->vtable), "lindutil" );
|
||||
|
||||
MPASSIGN( result->mpool, mpool );
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue