mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-02-12 08:47:50 +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)/dbgutil.c \
|
||||||
$(COMMON_PATH)/nli.c \
|
$(COMMON_PATH)/nli.c \
|
||||||
$(COMMON_PATH)/smsproto.c \
|
$(COMMON_PATH)/smsproto.c \
|
||||||
|
$(COMMON_PATH)/dutil.c \
|
||||||
$(COMMON_PATH)/device.c \
|
$(COMMON_PATH)/device.c \
|
||||||
$(COMMON_PATH)/knownplyr.c \
|
$(COMMON_PATH)/knownplyr.c \
|
||||||
|
|
||||||
|
|
|
@ -1006,6 +1006,7 @@ makeDUtil( MPFORMAL JNIEnv* env,
|
||||||
JNIUtilCtxt* jniutil, void* closure )
|
JNIUtilCtxt* jniutil, void* closure )
|
||||||
{
|
{
|
||||||
AndDUtil* dutil = (AndDUtil*)XP_CALLOC( mpool, sizeof(*dutil) );
|
AndDUtil* dutil = (AndDUtil*)XP_CALLOC( mpool, sizeof(*dutil) );
|
||||||
|
dutil_super_init( MPPARM(mpool) &dutil->dutil );
|
||||||
#ifdef MAP_THREAD_TO_ENV
|
#ifdef MAP_THREAD_TO_ENV
|
||||||
dutil->ti = ti;
|
dutil->ti = ti;
|
||||||
#endif
|
#endif
|
||||||
|
@ -1017,8 +1018,6 @@ makeDUtil( MPFORMAL JNIEnv* env,
|
||||||
dutil->jdutil = (*env)->NewGlobalRef( env, jdutil );
|
dutil->jdutil = (*env)->NewGlobalRef( env, jdutil );
|
||||||
}
|
}
|
||||||
|
|
||||||
MPASSIGN( dutil->dutil.mpool, mpool );
|
|
||||||
|
|
||||||
DUtilVtable* vtable = &dutil->dutil.vtable;
|
DUtilVtable* vtable = &dutil->dutil.vtable;
|
||||||
#define SET_DPROC(nam) vtable->m_dutil_##nam = and_dutil_##nam
|
#define SET_DPROC(nam) vtable->m_dutil_##nam = and_dutil_##nam
|
||||||
SET_DPROC(getCurSeconds);
|
SET_DPROC(getCurSeconds);
|
||||||
|
|
|
@ -49,6 +49,7 @@ COMMONSRC = \
|
||||||
$(COMMONDIR)/dictmgr.c \
|
$(COMMONDIR)/dictmgr.c \
|
||||||
$(COMMONDIR)/dbgutil.c \
|
$(COMMONDIR)/dbgutil.c \
|
||||||
$(COMMONDIR)/smsproto.c \
|
$(COMMONDIR)/smsproto.c \
|
||||||
|
$(COMMONDIR)/dutil.c \
|
||||||
$(COMMONDIR)/device.c \
|
$(COMMONDIR)/device.c \
|
||||||
|
|
||||||
# PENDING: define this in terms of above!!!
|
# PENDING: define this in terms of above!!!
|
||||||
|
@ -88,6 +89,7 @@ COMMON5 = \
|
||||||
$(COMMONOBJDIR)/dictmgr.o \
|
$(COMMONOBJDIR)/dictmgr.o \
|
||||||
$(COMMONOBJDIR)/dbgutil.o \
|
$(COMMONOBJDIR)/dbgutil.o \
|
||||||
$(COMMONOBJDIR)/smsproto.o \
|
$(COMMONOBJDIR)/smsproto.o \
|
||||||
|
$(COMMONOBJDIR)/dutil.o \
|
||||||
$(COMMONOBJDIR)/device.o \
|
$(COMMONOBJDIR)/device.o \
|
||||||
$(COMMONOBJDIR)/knownplyr.o \
|
$(COMMONOBJDIR)/knownplyr.o \
|
||||||
|
|
||||||
|
|
|
@ -84,11 +84,16 @@ struct XW_DUtilCtxt {
|
||||||
DUtilVtable vtable;
|
DUtilVtable vtable;
|
||||||
void* closure;
|
void* closure;
|
||||||
void* devCtxt; /* owned by device.c */
|
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;
|
VTableMgr* vtMgr;
|
||||||
MPSLOT
|
MPSLOT
|
||||||
};
|
};
|
||||||
|
|
||||||
|
void dutil_super_init( MPFORMAL XW_DUtilCtxt* dutil );
|
||||||
|
|
||||||
/* This one cheats: direct access */
|
/* This one cheats: direct access */
|
||||||
#define dutil_getVTManager(duc) (duc)->vtMgr
|
#define dutil_getVTManager(duc) (duc)->vtMgr
|
||||||
|
|
||||||
|
|
|
@ -64,6 +64,8 @@ static KPState*
|
||||||
loadState( XW_DUtilCtxt* dutil, XWEnv xwe )
|
loadState( XW_DUtilCtxt* dutil, XWEnv xwe )
|
||||||
{
|
{
|
||||||
LOG_FUNC();
|
LOG_FUNC();
|
||||||
|
pthread_mutex_lock( &dutil->kpMutex );
|
||||||
|
|
||||||
KPState* state = (KPState*)dutil->kpCtxt;
|
KPState* state = (KPState*)dutil->kpCtxt;
|
||||||
if ( NULL == state ) {
|
if ( NULL == state ) {
|
||||||
dutil->kpCtxt = state = XP_CALLOC( dutil->mpool, sizeof(*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 );
|
XP_ASSERT( state->inUse );
|
||||||
saveState( dutil, xwe, state );
|
saveState( dutil, xwe, state );
|
||||||
state->inUse = XP_FALSE;
|
state->inUse = XP_FALSE;
|
||||||
|
|
||||||
|
pthread_mutex_unlock( &dutil->kpMutex );
|
||||||
}
|
}
|
||||||
|
|
||||||
static const XP_UCHAR*
|
static const XP_UCHAR*
|
||||||
|
|
|
@ -133,6 +133,9 @@ XW_DUtilCtxt*
|
||||||
dutils_init( MPFORMAL VTableMgr* vtMgr, void* closure )
|
dutils_init( MPFORMAL VTableMgr* vtMgr, void* closure )
|
||||||
{
|
{
|
||||||
XW_DUtilCtxt* result = XP_CALLOC( mpool, sizeof(*result) );
|
XW_DUtilCtxt* result = XP_CALLOC( mpool, sizeof(*result) );
|
||||||
|
|
||||||
|
dutil_super_init( MPPARM(mpool) result );
|
||||||
|
|
||||||
result->vtMgr = vtMgr;
|
result->vtMgr = vtMgr;
|
||||||
result->closure = closure;
|
result->closure = closure;
|
||||||
|
|
||||||
|
@ -170,7 +173,6 @@ dutils_init( MPFORMAL VTableMgr* vtMgr, void* closure )
|
||||||
|
|
||||||
assertTableFull( &result->vtable, sizeof(result->vtable), "lindutil" );
|
assertTableFull( &result->vtable, sizeof(result->vtable), "lindutil" );
|
||||||
|
|
||||||
MPASSIGN( result->mpool, mpool );
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue