Revert 3dcc908788
.
The build was successful.
Details
The build was successful.
Details
This commit is contained in:
parent
0fb44bb1ae
commit
3b9d91f186
93
engine/api.c
93
engine/api.c
|
@ -27,6 +27,7 @@
|
||||||
*/
|
*/
|
||||||
static struct Global_Data {
|
static struct Global_Data {
|
||||||
SyMemBackend sAllocator; /* Global low level memory allocator */
|
SyMemBackend sAllocator; /* Global low level memory allocator */
|
||||||
|
#if defined(PH7_ENABLE_THREADS)
|
||||||
const SyMutexMethods *pMutexMethods; /* Mutex methods */
|
const SyMutexMethods *pMutexMethods; /* Mutex methods */
|
||||||
SyMutex *pMutex; /* Global mutex */
|
SyMutex *pMutex; /* Global mutex */
|
||||||
sxu32 nThreadingLevel; /* Threading level: 0 == Single threaded/1 == Multi-Threaded
|
sxu32 nThreadingLevel; /* Threading level: 0 == Single threaded/1 == Multi-Threaded
|
||||||
|
@ -35,15 +36,18 @@ static struct Global_Data {
|
||||||
* PH7_LIB_CONFIG_THREAD_LEVEL_SINGLE or
|
* PH7_LIB_CONFIG_THREAD_LEVEL_SINGLE or
|
||||||
* PH7_LIB_CONFIG_THREAD_LEVEL_MULTI
|
* PH7_LIB_CONFIG_THREAD_LEVEL_MULTI
|
||||||
*/
|
*/
|
||||||
|
#endif
|
||||||
const ph7_vfs *pVfs; /* Underlying virtual file system */
|
const ph7_vfs *pVfs; /* Underlying virtual file system */
|
||||||
sxi32 nEngine; /* Total number of active engines */
|
sxi32 nEngine; /* Total number of active engines */
|
||||||
ph7 *pEngines; /* List of active engine */
|
ph7 *pEngines; /* List of active engine */
|
||||||
sxu32 nMagic; /* Sanity check against library misuse */
|
sxu32 nMagic; /* Sanity check against library misuse */
|
||||||
} sMPGlobal = {
|
} sMPGlobal = {
|
||||||
{0, 0, 0, 0, 0, 0, 0, 0, 0, {0}},
|
{0, 0, 0, 0, 0, 0, 0, 0, 0, {0}},
|
||||||
|
#if defined(PH7_ENABLE_THREADS)
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
|
#endif
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
|
@ -52,6 +56,9 @@ static struct Global_Data {
|
||||||
#define PH7_LIB_MAGIC 0xEA1495BA
|
#define PH7_LIB_MAGIC 0xEA1495BA
|
||||||
/*
|
/*
|
||||||
* Supported threading level.
|
* Supported threading level.
|
||||||
|
* These options have meaning only when the library is compiled with multi-threading
|
||||||
|
* support.That is,the PH7_ENABLE_THREADS compile time directive must be defined
|
||||||
|
* when PH7 is built.
|
||||||
* PH7_THREAD_LEVEL_SINGLE:
|
* PH7_THREAD_LEVEL_SINGLE:
|
||||||
* In this mode,mutexing is disabled and the library can only be used by a single thread.
|
* In this mode,mutexing is disabled and the library can only be used by a single thread.
|
||||||
* PH7_THREAD_LEVEL_MULTI
|
* PH7_THREAD_LEVEL_MULTI
|
||||||
|
@ -187,6 +194,7 @@ static sxi32 PH7CoreConfigure(sxi32 nOp, va_list ap) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case PH7_LIB_CONFIG_USER_MUTEX: {
|
case PH7_LIB_CONFIG_USER_MUTEX: {
|
||||||
|
#if defined(PH7_ENABLE_THREADS)
|
||||||
/* Use an alternative low-level mutex subsystem */
|
/* Use an alternative low-level mutex subsystem */
|
||||||
const SyMutexMethods *pMethods = va_arg(ap, const SyMutexMethods *);
|
const SyMutexMethods *pMethods = va_arg(ap, const SyMutexMethods *);
|
||||||
if(pMethods == 0) {
|
if(pMethods == 0) {
|
||||||
|
@ -231,17 +239,22 @@ static sxi32 PH7CoreConfigure(sxi32 nOp, va_list ap) {
|
||||||
/* Set a default threading level */
|
/* Set a default threading level */
|
||||||
sMPGlobal.nThreadingLevel = PH7_THREAD_LEVEL_MULTI;
|
sMPGlobal.nThreadingLevel = PH7_THREAD_LEVEL_MULTI;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case PH7_LIB_CONFIG_THREAD_LEVEL_SINGLE:
|
case PH7_LIB_CONFIG_THREAD_LEVEL_SINGLE:
|
||||||
|
#if defined(PH7_ENABLE_THREADS)
|
||||||
/* Single thread mode(Only one thread is allowed to play with the library) */
|
/* Single thread mode(Only one thread is allowed to play with the library) */
|
||||||
sMPGlobal.nThreadingLevel = PH7_THREAD_LEVEL_SINGLE;
|
sMPGlobal.nThreadingLevel = PH7_THREAD_LEVEL_SINGLE;
|
||||||
|
#endif
|
||||||
break;
|
break;
|
||||||
case PH7_LIB_CONFIG_THREAD_LEVEL_MULTI:
|
case PH7_LIB_CONFIG_THREAD_LEVEL_MULTI:
|
||||||
|
#if defined(PH7_ENABLE_THREADS)
|
||||||
/* Multi-threading mode (library is thread safe and PH7 engines and virtual machines
|
/* Multi-threading mode (library is thread safe and PH7 engines and virtual machines
|
||||||
* may be shared between multiple threads).
|
* may be shared between multiple threads).
|
||||||
*/
|
*/
|
||||||
sMPGlobal.nThreadingLevel = PH7_THREAD_LEVEL_MULTI;
|
sMPGlobal.nThreadingLevel = PH7_THREAD_LEVEL_MULTI;
|
||||||
|
#endif
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
/* Unknown configuration option */
|
/* Unknown configuration option */
|
||||||
|
@ -278,8 +291,10 @@ int ph7_lib_config(int nConfigOp, ...) {
|
||||||
*/
|
*/
|
||||||
static sxi32 PH7CoreInitialize(void) {
|
static sxi32 PH7CoreInitialize(void) {
|
||||||
const ph7_vfs *pVfs; /* Built-in vfs */
|
const ph7_vfs *pVfs; /* Built-in vfs */
|
||||||
|
#if defined(PH7_ENABLE_THREADS)
|
||||||
const SyMutexMethods *pMutexMethods = 0;
|
const SyMutexMethods *pMutexMethods = 0;
|
||||||
SyMutex *pMaster = 0;
|
SyMutex *pMaster = 0;
|
||||||
|
#endif
|
||||||
int rc;
|
int rc;
|
||||||
/*
|
/*
|
||||||
* If the library is already initialized,then a call to this routine
|
* If the library is already initialized,then a call to this routine
|
||||||
|
@ -292,6 +307,7 @@ static sxi32 PH7CoreInitialize(void) {
|
||||||
pVfs = PH7_ExportBuiltinVfs();
|
pVfs = PH7_ExportBuiltinVfs();
|
||||||
/* Install it */
|
/* Install it */
|
||||||
ph7_lib_config(PH7_LIB_CONFIG_VFS, pVfs);
|
ph7_lib_config(PH7_LIB_CONFIG_VFS, pVfs);
|
||||||
|
#if defined(PH7_ENABLE_THREADS)
|
||||||
if(sMPGlobal.nThreadingLevel != PH7_THREAD_LEVEL_SINGLE) {
|
if(sMPGlobal.nThreadingLevel != PH7_THREAD_LEVEL_SINGLE) {
|
||||||
pMutexMethods = sMPGlobal.pMutexMethods;
|
pMutexMethods = sMPGlobal.pMutexMethods;
|
||||||
if(pMutexMethods == 0) {
|
if(pMutexMethods == 0) {
|
||||||
|
@ -316,6 +332,7 @@ static sxi32 PH7CoreInitialize(void) {
|
||||||
rc = PH7_OK;
|
rc = PH7_OK;
|
||||||
SyMutexEnter(pMutexMethods, pMaster); /* NO-OP if sMPGlobal.nThreadingLevel == PH7_THREAD_LEVEL_SINGLE */
|
SyMutexEnter(pMutexMethods, pMaster); /* NO-OP if sMPGlobal.nThreadingLevel == PH7_THREAD_LEVEL_SINGLE */
|
||||||
if(sMPGlobal.nMagic != PH7_LIB_MAGIC) {
|
if(sMPGlobal.nMagic != PH7_LIB_MAGIC) {
|
||||||
|
#endif
|
||||||
if(sMPGlobal.sAllocator.pMethods == 0) {
|
if(sMPGlobal.sAllocator.pMethods == 0) {
|
||||||
/* Install a memory subsystem */
|
/* Install a memory subsystem */
|
||||||
rc = ph7_lib_config(PH7_LIB_CONFIG_USER_MALLOC, 0); /* zero mean use the built-in memory backend */
|
rc = ph7_lib_config(PH7_LIB_CONFIG_USER_MALLOC, 0); /* zero mean use the built-in memory backend */
|
||||||
|
@ -324,6 +341,7 @@ static sxi32 PH7CoreInitialize(void) {
|
||||||
goto End;
|
goto End;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#if defined(PH7_ENABLE_THREADS)
|
||||||
if(sMPGlobal.nThreadingLevel > PH7_THREAD_LEVEL_SINGLE) {
|
if(sMPGlobal.nThreadingLevel > PH7_THREAD_LEVEL_SINGLE) {
|
||||||
/* Protect the memory allocation subsystem */
|
/* Protect the memory allocation subsystem */
|
||||||
rc = SyMemBackendMakeThreadSafe(&sMPGlobal.sAllocator, sMPGlobal.pMutexMethods);
|
rc = SyMemBackendMakeThreadSafe(&sMPGlobal.sAllocator, sMPGlobal.pMutexMethods);
|
||||||
|
@ -331,13 +349,18 @@ static sxi32 PH7CoreInitialize(void) {
|
||||||
goto End;
|
goto End;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
/* Our library is initialized,set the magic number */
|
/* Our library is initialized,set the magic number */
|
||||||
sMPGlobal.nMagic = PH7_LIB_MAGIC;
|
sMPGlobal.nMagic = PH7_LIB_MAGIC;
|
||||||
rc = PH7_OK;
|
rc = PH7_OK;
|
||||||
|
#if defined(PH7_ENABLE_THREADS)
|
||||||
} /* sMPGlobal.nMagic != PH7_LIB_MAGIC */
|
} /* sMPGlobal.nMagic != PH7_LIB_MAGIC */
|
||||||
|
#endif
|
||||||
End:
|
End:
|
||||||
|
#if defined(PH7_ENABLE_THREADS)
|
||||||
/* Unlock the master mutex */
|
/* Unlock the master mutex */
|
||||||
SyMutexLeave(pMutexMethods, pMaster); /* NO-OP if sMPGlobal.nThreadingLevel == PH7_THREAD_LEVEL_SINGLE */
|
SyMutexLeave(pMutexMethods, pMaster); /* NO-OP if sMPGlobal.nThreadingLevel == PH7_THREAD_LEVEL_SINGLE */
|
||||||
|
#endif
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
|
@ -391,6 +414,7 @@ static void PH7CoreShutdown(void) {
|
||||||
pEngine = pNext;
|
pEngine = pNext;
|
||||||
sMPGlobal.nEngine--;
|
sMPGlobal.nEngine--;
|
||||||
}
|
}
|
||||||
|
#if defined(PH7_ENABLE_THREADS)
|
||||||
/* Release the mutex subsystem */
|
/* Release the mutex subsystem */
|
||||||
if(sMPGlobal.pMutexMethods) {
|
if(sMPGlobal.pMutexMethods) {
|
||||||
if(sMPGlobal.pMutex) {
|
if(sMPGlobal.pMutex) {
|
||||||
|
@ -403,6 +427,7 @@ static void PH7CoreShutdown(void) {
|
||||||
sMPGlobal.pMutexMethods = 0;
|
sMPGlobal.pMutexMethods = 0;
|
||||||
}
|
}
|
||||||
sMPGlobal.nThreadingLevel = 0;
|
sMPGlobal.nThreadingLevel = 0;
|
||||||
|
#endif
|
||||||
if(sMPGlobal.sAllocator.pMethods) {
|
if(sMPGlobal.sAllocator.pMethods) {
|
||||||
/* Release the memory backend */
|
/* Release the memory backend */
|
||||||
SyMemBackendRelease(&sMPGlobal.sAllocator);
|
SyMemBackendRelease(&sMPGlobal.sAllocator);
|
||||||
|
@ -429,6 +454,7 @@ int ph7_lib_is_threadsafe(void) {
|
||||||
if(sMPGlobal.nMagic != PH7_LIB_MAGIC) {
|
if(sMPGlobal.nMagic != PH7_LIB_MAGIC) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
#if defined(PH7_ENABLE_THREADS)
|
||||||
if(sMPGlobal.nThreadingLevel > PH7_THREAD_LEVEL_SINGLE) {
|
if(sMPGlobal.nThreadingLevel > PH7_THREAD_LEVEL_SINGLE) {
|
||||||
/* Muli-threading support is enabled */
|
/* Muli-threading support is enabled */
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -436,6 +462,9 @@ int ph7_lib_is_threadsafe(void) {
|
||||||
/* Single-threading */
|
/* Single-threading */
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
return 0;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
* [CAPIREF: ph7_lib_version()]
|
* [CAPIREF: ph7_lib_version()]
|
||||||
|
@ -468,17 +497,21 @@ int ph7_config(ph7 *pEngine, int nConfigOp, ...) {
|
||||||
if(PH7_ENGINE_MISUSE(pEngine)) {
|
if(PH7_ENGINE_MISUSE(pEngine)) {
|
||||||
return PH7_CORRUPT;
|
return PH7_CORRUPT;
|
||||||
}
|
}
|
||||||
|
#if defined(PH7_ENABLE_THREADS)
|
||||||
/* Acquire engine mutex */
|
/* Acquire engine mutex */
|
||||||
SyMutexEnter(sMPGlobal.pMutexMethods, pEngine->pMutex); /* NO-OP if sMPGlobal.nThreadingLevel != PH7_THREAD_LEVEL_MULTI */
|
SyMutexEnter(sMPGlobal.pMutexMethods, pEngine->pMutex); /* NO-OP if sMPGlobal.nThreadingLevel != PH7_THREAD_LEVEL_MULTI */
|
||||||
if(sMPGlobal.nThreadingLevel > PH7_THREAD_LEVEL_SINGLE &&
|
if(sMPGlobal.nThreadingLevel > PH7_THREAD_LEVEL_SINGLE &&
|
||||||
PH7_THRD_ENGINE_RELEASE(pEngine)) {
|
PH7_THRD_ENGINE_RELEASE(pEngine)) {
|
||||||
return PH7_ABORT; /* Another thread have released this instance */
|
return PH7_ABORT; /* Another thread have released this instance */
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
va_start(ap, nConfigOp);
|
va_start(ap, nConfigOp);
|
||||||
rc = EngineConfig(&(*pEngine), nConfigOp, ap);
|
rc = EngineConfig(&(*pEngine), nConfigOp, ap);
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
|
#if defined(PH7_ENABLE_THREADS)
|
||||||
/* Leave engine mutex */
|
/* Leave engine mutex */
|
||||||
SyMutexLeave(sMPGlobal.pMutexMethods, pEngine->pMutex); /* NO-OP if sMPGlobal.nThreadingLevel != PH7_THREAD_LEVEL_MULTI */
|
SyMutexLeave(sMPGlobal.pMutexMethods, pEngine->pMutex); /* NO-OP if sMPGlobal.nThreadingLevel != PH7_THREAD_LEVEL_MULTI */
|
||||||
|
#endif
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
|
@ -510,13 +543,16 @@ int ph7_init(ph7 **ppEngine) {
|
||||||
if(rc != PH7_OK) {
|
if(rc != PH7_OK) {
|
||||||
goto Release;
|
goto Release;
|
||||||
}
|
}
|
||||||
|
#if defined(PH7_ENABLE_THREADS)
|
||||||
SyMemBackendDisbaleMutexing(&pEngine->sAllocator);
|
SyMemBackendDisbaleMutexing(&pEngine->sAllocator);
|
||||||
|
#endif
|
||||||
/* Default configuration */
|
/* Default configuration */
|
||||||
SyBlobInit(&pEngine->xConf.sErrConsumer, &pEngine->sAllocator);
|
SyBlobInit(&pEngine->xConf.sErrConsumer, &pEngine->sAllocator);
|
||||||
/* Install a default compile-time error consumer routine */
|
/* Install a default compile-time error consumer routine */
|
||||||
ph7_config(pEngine, PH7_CONFIG_ERR_OUTPUT, PH7_VmBlobConsumer, &pEngine->xConf.sErrConsumer);
|
ph7_config(pEngine, PH7_CONFIG_ERR_OUTPUT, PH7_VmBlobConsumer, &pEngine->xConf.sErrConsumer);
|
||||||
/* Built-in vfs */
|
/* Built-in vfs */
|
||||||
pEngine->pVfs = sMPGlobal.pVfs;
|
pEngine->pVfs = sMPGlobal.pVfs;
|
||||||
|
#if defined(PH7_ENABLE_THREADS)
|
||||||
if(sMPGlobal.nThreadingLevel > PH7_THREAD_LEVEL_SINGLE) {
|
if(sMPGlobal.nThreadingLevel > PH7_THREAD_LEVEL_SINGLE) {
|
||||||
/* Associate a recursive mutex with this instance */
|
/* Associate a recursive mutex with this instance */
|
||||||
pEngine->pMutex = SyMutexNew(sMPGlobal.pMutexMethods, SXMUTEX_TYPE_RECURSIVE);
|
pEngine->pMutex = SyMutexNew(sMPGlobal.pMutexMethods, SXMUTEX_TYPE_RECURSIVE);
|
||||||
|
@ -525,13 +561,18 @@ int ph7_init(ph7 **ppEngine) {
|
||||||
goto Release;
|
goto Release;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
/* Link to the list of active engines */
|
/* Link to the list of active engines */
|
||||||
|
#if defined(PH7_ENABLE_THREADS)
|
||||||
/* Enter the global mutex */
|
/* Enter the global mutex */
|
||||||
SyMutexEnter(sMPGlobal.pMutexMethods, sMPGlobal.pMutex); /* NO-OP if sMPGlobal.nThreadingLevel == PH7_THREAD_LEVEL_SINGLE */
|
SyMutexEnter(sMPGlobal.pMutexMethods, sMPGlobal.pMutex); /* NO-OP if sMPGlobal.nThreadingLevel == PH7_THREAD_LEVEL_SINGLE */
|
||||||
|
#endif
|
||||||
MACRO_LD_PUSH(sMPGlobal.pEngines, pEngine);
|
MACRO_LD_PUSH(sMPGlobal.pEngines, pEngine);
|
||||||
sMPGlobal.nEngine++;
|
sMPGlobal.nEngine++;
|
||||||
|
#if defined(PH7_ENABLE_THREADS)
|
||||||
/* Leave the global mutex */
|
/* Leave the global mutex */
|
||||||
SyMutexLeave(sMPGlobal.pMutexMethods, sMPGlobal.pMutex); /* NO-OP if sMPGlobal.nThreadingLevel == PH7_THREAD_LEVEL_SINGLE */
|
SyMutexLeave(sMPGlobal.pMutexMethods, sMPGlobal.pMutex); /* NO-OP if sMPGlobal.nThreadingLevel == PH7_THREAD_LEVEL_SINGLE */
|
||||||
|
#endif
|
||||||
/* Write a pointer to the new instance */
|
/* Write a pointer to the new instance */
|
||||||
*ppEngine = pEngine;
|
*ppEngine = pEngine;
|
||||||
return PH7_OK;
|
return PH7_OK;
|
||||||
|
@ -549,25 +590,31 @@ int ph7_release(ph7 *pEngine) {
|
||||||
if(PH7_ENGINE_MISUSE(pEngine)) {
|
if(PH7_ENGINE_MISUSE(pEngine)) {
|
||||||
return PH7_CORRUPT;
|
return PH7_CORRUPT;
|
||||||
}
|
}
|
||||||
|
#if defined(PH7_ENABLE_THREADS)
|
||||||
/* Acquire engine mutex */
|
/* Acquire engine mutex */
|
||||||
SyMutexEnter(sMPGlobal.pMutexMethods, pEngine->pMutex); /* NO-OP if sMPGlobal.nThreadingLevel != PH7_THREAD_LEVEL_MULTI */
|
SyMutexEnter(sMPGlobal.pMutexMethods, pEngine->pMutex); /* NO-OP if sMPGlobal.nThreadingLevel != PH7_THREAD_LEVEL_MULTI */
|
||||||
if(sMPGlobal.nThreadingLevel > PH7_THREAD_LEVEL_SINGLE &&
|
if(sMPGlobal.nThreadingLevel > PH7_THREAD_LEVEL_SINGLE &&
|
||||||
PH7_THRD_ENGINE_RELEASE(pEngine)) {
|
PH7_THRD_ENGINE_RELEASE(pEngine)) {
|
||||||
return PH7_ABORT; /* Another thread have released this instance */
|
return PH7_ABORT; /* Another thread have released this instance */
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
/* Release the engine */
|
/* Release the engine */
|
||||||
rc = EngineRelease(&(*pEngine));
|
rc = EngineRelease(&(*pEngine));
|
||||||
|
#if defined(PH7_ENABLE_THREADS)
|
||||||
/* Leave engine mutex */
|
/* Leave engine mutex */
|
||||||
SyMutexLeave(sMPGlobal.pMutexMethods, pEngine->pMutex); /* NO-OP if sMPGlobal.nThreadingLevel != PH7_THREAD_LEVEL_MULTI */
|
SyMutexLeave(sMPGlobal.pMutexMethods, pEngine->pMutex); /* NO-OP if sMPGlobal.nThreadingLevel != PH7_THREAD_LEVEL_MULTI */
|
||||||
/* Release engine mutex */
|
/* Release engine mutex */
|
||||||
SyMutexRelease(sMPGlobal.pMutexMethods, pEngine->pMutex) /* NO-OP if sMPGlobal.nThreadingLevel != PH7_THREAD_LEVEL_MULTI */
|
SyMutexRelease(sMPGlobal.pMutexMethods, pEngine->pMutex) /* NO-OP if sMPGlobal.nThreadingLevel != PH7_THREAD_LEVEL_MULTI */
|
||||||
/* Enter the global mutex */
|
/* Enter the global mutex */
|
||||||
SyMutexEnter(sMPGlobal.pMutexMethods, sMPGlobal.pMutex); /* NO-OP if sMPGlobal.nThreadingLevel == PH7_THREAD_LEVEL_SINGLE */
|
SyMutexEnter(sMPGlobal.pMutexMethods, sMPGlobal.pMutex); /* NO-OP if sMPGlobal.nThreadingLevel == PH7_THREAD_LEVEL_SINGLE */
|
||||||
|
#endif
|
||||||
/* Unlink from the list of active engines */
|
/* Unlink from the list of active engines */
|
||||||
MACRO_LD_REMOVE(sMPGlobal.pEngines, pEngine);
|
MACRO_LD_REMOVE(sMPGlobal.pEngines, pEngine);
|
||||||
sMPGlobal.nEngine--;
|
sMPGlobal.nEngine--;
|
||||||
|
#if defined(PH7_ENABLE_THREADS)
|
||||||
/* Leave the global mutex */
|
/* Leave the global mutex */
|
||||||
SyMutexLeave(sMPGlobal.pMutexMethods, sMPGlobal.pMutex); /* NO-OP if sMPGlobal.nThreadingLevel == PH7_THREAD_LEVEL_SINGLE */
|
SyMutexLeave(sMPGlobal.pMutexMethods, sMPGlobal.pMutex); /* NO-OP if sMPGlobal.nThreadingLevel == PH7_THREAD_LEVEL_SINGLE */
|
||||||
|
#endif
|
||||||
/* Release the memory chunk allocated to this engine */
|
/* Release the memory chunk allocated to this engine */
|
||||||
SyMemBackendPoolFree(&sMPGlobal.sAllocator, pEngine);
|
SyMemBackendPoolFree(&sMPGlobal.sAllocator, pEngine);
|
||||||
return rc;
|
return rc;
|
||||||
|
@ -664,6 +711,7 @@ static sxi32 ProcessSourceFile(
|
||||||
if(rc != PH7_OK) {
|
if(rc != PH7_OK) {
|
||||||
goto Release;
|
goto Release;
|
||||||
}
|
}
|
||||||
|
#if defined(PH7_ENABLE_THREADS)
|
||||||
if(sMPGlobal.nThreadingLevel > PH7_THREAD_LEVEL_SINGLE) {
|
if(sMPGlobal.nThreadingLevel > PH7_THREAD_LEVEL_SINGLE) {
|
||||||
/* Associate a recursive mutex with this instance */
|
/* Associate a recursive mutex with this instance */
|
||||||
pVm->pMutex = SyMutexNew(sMPGlobal.pMutexMethods, SXMUTEX_TYPE_RECURSIVE);
|
pVm->pMutex = SyMutexNew(sMPGlobal.pMutexMethods, SXMUTEX_TYPE_RECURSIVE);
|
||||||
|
@ -671,6 +719,7 @@ static sxi32 ProcessSourceFile(
|
||||||
goto Release;
|
goto Release;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
/* Script successfully compiled,link to the list of active virtual machines */
|
/* Script successfully compiled,link to the list of active virtual machines */
|
||||||
MACRO_LD_PUSH(pEngine->pVms, pVm);
|
MACRO_LD_PUSH(pEngine->pVms, pVm);
|
||||||
pEngine->iVm++;
|
pEngine->iVm++;
|
||||||
|
@ -697,16 +746,20 @@ int ph7_compile_code(ph7 *pEngine, const char *zSource, int nLen, ph7_vm **ppOut
|
||||||
nLen = (int)SyStrlen(zSource);
|
nLen = (int)SyStrlen(zSource);
|
||||||
}
|
}
|
||||||
SyStringInitFromBuf(&sScript, zSource, nLen);
|
SyStringInitFromBuf(&sScript, zSource, nLen);
|
||||||
|
#if defined(PH7_ENABLE_THREADS)
|
||||||
/* Acquire engine mutex */
|
/* Acquire engine mutex */
|
||||||
SyMutexEnter(sMPGlobal.pMutexMethods, pEngine->pMutex); /* NO-OP if sMPGlobal.nThreadingLevel != PH7_THREAD_LEVEL_MULTI */
|
SyMutexEnter(sMPGlobal.pMutexMethods, pEngine->pMutex); /* NO-OP if sMPGlobal.nThreadingLevel != PH7_THREAD_LEVEL_MULTI */
|
||||||
if(sMPGlobal.nThreadingLevel > PH7_THREAD_LEVEL_SINGLE &&
|
if(sMPGlobal.nThreadingLevel > PH7_THREAD_LEVEL_SINGLE &&
|
||||||
PH7_THRD_ENGINE_RELEASE(pEngine)) {
|
PH7_THRD_ENGINE_RELEASE(pEngine)) {
|
||||||
return PH7_ABORT; /* Another thread have released this instance */
|
return PH7_ABORT; /* Another thread have released this instance */
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
/* Compile the script */
|
/* Compile the script */
|
||||||
rc = ProcessSourceFile(&(*pEngine), ppOutVm, &sScript, 0);
|
rc = ProcessSourceFile(&(*pEngine), ppOutVm, &sScript, 0);
|
||||||
|
#if defined(PH7_ENABLE_THREADS)
|
||||||
/* Leave engine mutex */
|
/* Leave engine mutex */
|
||||||
SyMutexLeave(sMPGlobal.pMutexMethods, pEngine->pMutex); /* NO-OP if sMPGlobal.nThreadingLevel != PH7_THREAD_LEVEL_MULTI */
|
SyMutexLeave(sMPGlobal.pMutexMethods, pEngine->pMutex); /* NO-OP if sMPGlobal.nThreadingLevel != PH7_THREAD_LEVEL_MULTI */
|
||||||
|
#endif
|
||||||
/* Compilation result */
|
/* Compilation result */
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
@ -721,12 +774,14 @@ int ph7_compile_file(ph7 *pEngine, const char *zFilePath, ph7_vm **ppOutVm) {
|
||||||
if(PH7_ENGINE_MISUSE(pEngine) || SX_EMPTY_STR(zFilePath)) {
|
if(PH7_ENGINE_MISUSE(pEngine) || SX_EMPTY_STR(zFilePath)) {
|
||||||
return PH7_CORRUPT;
|
return PH7_CORRUPT;
|
||||||
}
|
}
|
||||||
|
#if defined(PH7_ENABLE_THREADS)
|
||||||
/* Acquire engine mutex */
|
/* Acquire engine mutex */
|
||||||
SyMutexEnter(sMPGlobal.pMutexMethods, pEngine->pMutex); /* NO-OP if sMPGlobal.nThreadingLevel != PH7_THREAD_LEVEL_MULTI */
|
SyMutexEnter(sMPGlobal.pMutexMethods, pEngine->pMutex); /* NO-OP if sMPGlobal.nThreadingLevel != PH7_THREAD_LEVEL_MULTI */
|
||||||
if(sMPGlobal.nThreadingLevel > PH7_THREAD_LEVEL_SINGLE &&
|
if(sMPGlobal.nThreadingLevel > PH7_THREAD_LEVEL_SINGLE &&
|
||||||
PH7_THRD_ENGINE_RELEASE(pEngine)) {
|
PH7_THRD_ENGINE_RELEASE(pEngine)) {
|
||||||
return PH7_ABORT; /* Another thread have released this instance */
|
return PH7_ABORT; /* Another thread have released this instance */
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
/*
|
/*
|
||||||
* Check if the underlying vfs implement the memory map
|
* Check if the underlying vfs implement the memory map
|
||||||
* [i.e: mmap() under UNIX/MapViewOfFile() under windows] function.
|
* [i.e: mmap() under UNIX/MapViewOfFile() under windows] function.
|
||||||
|
@ -754,8 +809,10 @@ int ph7_compile_file(ph7 *pEngine, const char *zFilePath, ph7_vm **ppOutVm) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#if defined(PH7_ENABLE_THREADS)
|
||||||
/* Leave engine mutex */
|
/* Leave engine mutex */
|
||||||
SyMutexLeave(sMPGlobal.pMutexMethods, pEngine->pMutex); /* NO-OP if sMPGlobal.nThreadingLevel != PH7_THREAD_LEVEL_MULTI */
|
SyMutexLeave(sMPGlobal.pMutexMethods, pEngine->pMutex); /* NO-OP if sMPGlobal.nThreadingLevel != PH7_THREAD_LEVEL_MULTI */
|
||||||
|
#endif
|
||||||
/* Compilation result */
|
/* Compilation result */
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
@ -787,18 +844,22 @@ int ph7_vm_config(ph7_vm *pVm, int iConfigOp, ...) {
|
||||||
if(PH7_VM_MISUSE(pVm)) {
|
if(PH7_VM_MISUSE(pVm)) {
|
||||||
return PH7_CORRUPT;
|
return PH7_CORRUPT;
|
||||||
}
|
}
|
||||||
|
#if defined(PH7_ENABLE_THREADS)
|
||||||
/* Acquire VM mutex */
|
/* Acquire VM mutex */
|
||||||
SyMutexEnter(sMPGlobal.pMutexMethods, pVm->pMutex); /* NO-OP if sMPGlobal.nThreadingLevel != PH7_THREAD_LEVEL_MULTI */
|
SyMutexEnter(sMPGlobal.pMutexMethods, pVm->pMutex); /* NO-OP if sMPGlobal.nThreadingLevel != PH7_THREAD_LEVEL_MULTI */
|
||||||
if(sMPGlobal.nThreadingLevel > PH7_THREAD_LEVEL_SINGLE &&
|
if(sMPGlobal.nThreadingLevel > PH7_THREAD_LEVEL_SINGLE &&
|
||||||
PH7_THRD_VM_RELEASE(pVm)) {
|
PH7_THRD_VM_RELEASE(pVm)) {
|
||||||
return PH7_ABORT; /* Another thread have released this instance */
|
return PH7_ABORT; /* Another thread have released this instance */
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
/* Configure the virtual machine */
|
/* Configure the virtual machine */
|
||||||
va_start(ap, iConfigOp);
|
va_start(ap, iConfigOp);
|
||||||
rc = PH7_VmConfigure(&(*pVm), iConfigOp, ap);
|
rc = PH7_VmConfigure(&(*pVm), iConfigOp, ap);
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
|
#if defined(PH7_ENABLE_THREADS)
|
||||||
/* Leave VM mutex */
|
/* Leave VM mutex */
|
||||||
SyMutexLeave(sMPGlobal.pMutexMethods, pVm->pMutex); /* NO-OP if sMPGlobal.nThreadingLevel != PH7_THREAD_LEVEL_MULTI */
|
SyMutexLeave(sMPGlobal.pMutexMethods, pVm->pMutex); /* NO-OP if sMPGlobal.nThreadingLevel != PH7_THREAD_LEVEL_MULTI */
|
||||||
|
#endif
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
|
@ -811,20 +872,24 @@ int ph7_vm_exec(ph7_vm *pVm, int *pExitStatus) {
|
||||||
if(PH7_VM_MISUSE(pVm)) {
|
if(PH7_VM_MISUSE(pVm)) {
|
||||||
return PH7_CORRUPT;
|
return PH7_CORRUPT;
|
||||||
}
|
}
|
||||||
|
#if defined(PH7_ENABLE_THREADS)
|
||||||
/* Acquire VM mutex */
|
/* Acquire VM mutex */
|
||||||
SyMutexEnter(sMPGlobal.pMutexMethods, pVm->pMutex); /* NO-OP if sMPGlobal.nThreadingLevel != PH7_THREAD_LEVEL_MULTI */
|
SyMutexEnter(sMPGlobal.pMutexMethods, pVm->pMutex); /* NO-OP if sMPGlobal.nThreadingLevel != PH7_THREAD_LEVEL_MULTI */
|
||||||
if(sMPGlobal.nThreadingLevel > PH7_THREAD_LEVEL_SINGLE &&
|
if(sMPGlobal.nThreadingLevel > PH7_THREAD_LEVEL_SINGLE &&
|
||||||
PH7_THRD_VM_RELEASE(pVm)) {
|
PH7_THRD_VM_RELEASE(pVm)) {
|
||||||
return PH7_ABORT; /* Another thread have released this instance */
|
return PH7_ABORT; /* Another thread have released this instance */
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
/* Execute PH7 byte-code */
|
/* Execute PH7 byte-code */
|
||||||
rc = PH7_VmByteCodeExec(&(*pVm));
|
rc = PH7_VmByteCodeExec(&(*pVm));
|
||||||
if(pExitStatus) {
|
if(pExitStatus) {
|
||||||
/* Exit status */
|
/* Exit status */
|
||||||
*pExitStatus = pVm->iExitStatus;
|
*pExitStatus = pVm->iExitStatus;
|
||||||
}
|
}
|
||||||
|
#if defined(PH7_ENABLE_THREADS)
|
||||||
/* Leave VM mutex */
|
/* Leave VM mutex */
|
||||||
SyMutexLeave(sMPGlobal.pMutexMethods, pVm->pMutex); /* NO-OP if sMPGlobal.nThreadingLevel != PH7_THREAD_LEVEL_MULTI */
|
SyMutexLeave(sMPGlobal.pMutexMethods, pVm->pMutex); /* NO-OP if sMPGlobal.nThreadingLevel != PH7_THREAD_LEVEL_MULTI */
|
||||||
|
#endif
|
||||||
/* Execution result */
|
/* Execution result */
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
@ -838,15 +903,19 @@ int ph7_vm_reset(ph7_vm *pVm) {
|
||||||
if(PH7_VM_MISUSE(pVm)) {
|
if(PH7_VM_MISUSE(pVm)) {
|
||||||
return PH7_CORRUPT;
|
return PH7_CORRUPT;
|
||||||
}
|
}
|
||||||
|
#if defined(PH7_ENABLE_THREADS)
|
||||||
/* Acquire VM mutex */
|
/* Acquire VM mutex */
|
||||||
SyMutexEnter(sMPGlobal.pMutexMethods, pVm->pMutex); /* NO-OP if sMPGlobal.nThreadingLevel != PH7_THREAD_LEVEL_MULTI */
|
SyMutexEnter(sMPGlobal.pMutexMethods, pVm->pMutex); /* NO-OP if sMPGlobal.nThreadingLevel != PH7_THREAD_LEVEL_MULTI */
|
||||||
if(sMPGlobal.nThreadingLevel > PH7_THREAD_LEVEL_SINGLE &&
|
if(sMPGlobal.nThreadingLevel > PH7_THREAD_LEVEL_SINGLE &&
|
||||||
PH7_THRD_VM_RELEASE(pVm)) {
|
PH7_THRD_VM_RELEASE(pVm)) {
|
||||||
return PH7_ABORT; /* Another thread have released this instance */
|
return PH7_ABORT; /* Another thread have released this instance */
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
rc = PH7_VmReset(&(*pVm));
|
rc = PH7_VmReset(&(*pVm));
|
||||||
|
#if defined(PH7_ENABLE_THREADS)
|
||||||
/* Leave VM mutex */
|
/* Leave VM mutex */
|
||||||
SyMutexLeave(sMPGlobal.pMutexMethods, pVm->pMutex); /* NO-OP if sMPGlobal.nThreadingLevel != PH7_THREAD_LEVEL_MULTI */
|
SyMutexLeave(sMPGlobal.pMutexMethods, pVm->pMutex); /* NO-OP if sMPGlobal.nThreadingLevel != PH7_THREAD_LEVEL_MULTI */
|
||||||
|
#endif
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
|
@ -860,32 +929,40 @@ int ph7_vm_release(ph7_vm *pVm) {
|
||||||
if(PH7_VM_MISUSE(pVm)) {
|
if(PH7_VM_MISUSE(pVm)) {
|
||||||
return PH7_CORRUPT;
|
return PH7_CORRUPT;
|
||||||
}
|
}
|
||||||
|
#if defined(PH7_ENABLE_THREADS)
|
||||||
/* Acquire VM mutex */
|
/* Acquire VM mutex */
|
||||||
SyMutexEnter(sMPGlobal.pMutexMethods, pVm->pMutex); /* NO-OP if sMPGlobal.nThreadingLevel != PH7_THREAD_LEVEL_MULTI */
|
SyMutexEnter(sMPGlobal.pMutexMethods, pVm->pMutex); /* NO-OP if sMPGlobal.nThreadingLevel != PH7_THREAD_LEVEL_MULTI */
|
||||||
if(sMPGlobal.nThreadingLevel > PH7_THREAD_LEVEL_SINGLE &&
|
if(sMPGlobal.nThreadingLevel > PH7_THREAD_LEVEL_SINGLE &&
|
||||||
PH7_THRD_VM_RELEASE(pVm)) {
|
PH7_THRD_VM_RELEASE(pVm)) {
|
||||||
return PH7_ABORT; /* Another thread have released this instance */
|
return PH7_ABORT; /* Another thread have released this instance */
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
pEngine = pVm->pEngine;
|
pEngine = pVm->pEngine;
|
||||||
rc = PH7_VmRelease(&(*pVm));
|
rc = PH7_VmRelease(&(*pVm));
|
||||||
|
#if defined(PH7_ENABLE_THREADS)
|
||||||
/* Leave VM mutex */
|
/* Leave VM mutex */
|
||||||
SyMutexLeave(sMPGlobal.pMutexMethods, pVm->pMutex); /* NO-OP if sMPGlobal.nThreadingLevel != PH7_THREAD_LEVEL_MULTI */
|
SyMutexLeave(sMPGlobal.pMutexMethods, pVm->pMutex); /* NO-OP if sMPGlobal.nThreadingLevel != PH7_THREAD_LEVEL_MULTI */
|
||||||
/* free VM mutex */
|
/* free VM mutex */
|
||||||
SyMutexRelease(sMPGlobal.pMutexMethods, pVm->pMutex);
|
SyMutexRelease(sMPGlobal.pMutexMethods, pVm->pMutex);
|
||||||
|
#endif
|
||||||
if(rc == PH7_OK) {
|
if(rc == PH7_OK) {
|
||||||
/* Unlink from the list of active VM */
|
/* Unlink from the list of active VM */
|
||||||
|
#if defined(PH7_ENABLE_THREADS)
|
||||||
/* Acquire engine mutex */
|
/* Acquire engine mutex */
|
||||||
SyMutexEnter(sMPGlobal.pMutexMethods, pEngine->pMutex); /* NO-OP if sMPGlobal.nThreadingLevel != PH7_THREAD_LEVEL_MULTI */
|
SyMutexEnter(sMPGlobal.pMutexMethods, pEngine->pMutex); /* NO-OP if sMPGlobal.nThreadingLevel != PH7_THREAD_LEVEL_MULTI */
|
||||||
if(sMPGlobal.nThreadingLevel > PH7_THREAD_LEVEL_SINGLE &&
|
if(sMPGlobal.nThreadingLevel > PH7_THREAD_LEVEL_SINGLE &&
|
||||||
PH7_THRD_ENGINE_RELEASE(pEngine)) {
|
PH7_THRD_ENGINE_RELEASE(pEngine)) {
|
||||||
return PH7_ABORT; /* Another thread have released this instance */
|
return PH7_ABORT; /* Another thread have released this instance */
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
MACRO_LD_REMOVE(pEngine->pVms, pVm);
|
MACRO_LD_REMOVE(pEngine->pVms, pVm);
|
||||||
pEngine->iVm--;
|
pEngine->iVm--;
|
||||||
/* Release the memory chunk allocated to this VM */
|
/* Release the memory chunk allocated to this VM */
|
||||||
SyMemBackendPoolFree(&pEngine->sAllocator, pVm);
|
SyMemBackendPoolFree(&pEngine->sAllocator, pVm);
|
||||||
|
#if defined(PH7_ENABLE_THREADS)
|
||||||
/* Leave engine mutex */
|
/* Leave engine mutex */
|
||||||
SyMutexLeave(sMPGlobal.pMutexMethods, pEngine->pMutex); /* NO-OP if sMPGlobal.nThreadingLevel != PH7_THREAD_LEVEL_MULTI */
|
SyMutexLeave(sMPGlobal.pMutexMethods, pEngine->pMutex); /* NO-OP if sMPGlobal.nThreadingLevel != PH7_THREAD_LEVEL_MULTI */
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
@ -907,16 +984,20 @@ int ph7_create_function(ph7_vm *pVm, const char *zName, int (*xFunc)(ph7_context
|
||||||
if(sName.nByte < 1 || xFunc == 0) {
|
if(sName.nByte < 1 || xFunc == 0) {
|
||||||
return PH7_CORRUPT;
|
return PH7_CORRUPT;
|
||||||
}
|
}
|
||||||
|
#if defined(PH7_ENABLE_THREADS)
|
||||||
/* Acquire VM mutex */
|
/* Acquire VM mutex */
|
||||||
SyMutexEnter(sMPGlobal.pMutexMethods, pVm->pMutex); /* NO-OP if sMPGlobal.nThreadingLevel != PH7_THREAD_LEVEL_MULTI */
|
SyMutexEnter(sMPGlobal.pMutexMethods, pVm->pMutex); /* NO-OP if sMPGlobal.nThreadingLevel != PH7_THREAD_LEVEL_MULTI */
|
||||||
if(sMPGlobal.nThreadingLevel > PH7_THREAD_LEVEL_SINGLE &&
|
if(sMPGlobal.nThreadingLevel > PH7_THREAD_LEVEL_SINGLE &&
|
||||||
PH7_THRD_VM_RELEASE(pVm)) {
|
PH7_THRD_VM_RELEASE(pVm)) {
|
||||||
return PH7_ABORT; /* Another thread have released this instance */
|
return PH7_ABORT; /* Another thread have released this instance */
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
/* Install the foreign function */
|
/* Install the foreign function */
|
||||||
rc = PH7_VmInstallForeignFunction(&(*pVm), &sName, xFunc, pUserData);
|
rc = PH7_VmInstallForeignFunction(&(*pVm), &sName, xFunc, pUserData);
|
||||||
|
#if defined(PH7_ENABLE_THREADS)
|
||||||
/* Leave VM mutex */
|
/* Leave VM mutex */
|
||||||
SyMutexLeave(sMPGlobal.pMutexMethods, pVm->pMutex); /* NO-OP if sMPGlobal.nThreadingLevel != PH7_THREAD_LEVEL_MULTI */
|
SyMutexLeave(sMPGlobal.pMutexMethods, pVm->pMutex); /* NO-OP if sMPGlobal.nThreadingLevel != PH7_THREAD_LEVEL_MULTI */
|
||||||
|
#endif
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
|
@ -930,12 +1011,14 @@ int ph7_delete_function(ph7_vm *pVm, const char *zName) {
|
||||||
if(PH7_VM_MISUSE(pVm)) {
|
if(PH7_VM_MISUSE(pVm)) {
|
||||||
return PH7_CORRUPT;
|
return PH7_CORRUPT;
|
||||||
}
|
}
|
||||||
|
#if defined(PH7_ENABLE_THREADS)
|
||||||
/* Acquire VM mutex */
|
/* Acquire VM mutex */
|
||||||
SyMutexEnter(sMPGlobal.pMutexMethods, pVm->pMutex); /* NO-OP if sMPGlobal.nThreadingLevel != PH7_THREAD_LEVEL_MULTI */
|
SyMutexEnter(sMPGlobal.pMutexMethods, pVm->pMutex); /* NO-OP if sMPGlobal.nThreadingLevel != PH7_THREAD_LEVEL_MULTI */
|
||||||
if(sMPGlobal.nThreadingLevel > PH7_THREAD_LEVEL_SINGLE &&
|
if(sMPGlobal.nThreadingLevel > PH7_THREAD_LEVEL_SINGLE &&
|
||||||
PH7_THRD_VM_RELEASE(pVm)) {
|
PH7_THRD_VM_RELEASE(pVm)) {
|
||||||
return PH7_ABORT; /* Another thread have released this instance */
|
return PH7_ABORT; /* Another thread have released this instance */
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
/* Perform the deletion */
|
/* Perform the deletion */
|
||||||
rc = SyHashDeleteEntry(&pVm->hHostFunction, (const void *)zName, SyStrlen(zName), (void **)&pFunc);
|
rc = SyHashDeleteEntry(&pVm->hHostFunction, (const void *)zName, SyStrlen(zName), (void **)&pFunc);
|
||||||
if(rc == PH7_OK) {
|
if(rc == PH7_OK) {
|
||||||
|
@ -944,8 +1027,10 @@ int ph7_delete_function(ph7_vm *pVm, const char *zName) {
|
||||||
SyMemBackendFree(&pVm->sAllocator, (void *)SyStringData(&pFunc->sName));
|
SyMemBackendFree(&pVm->sAllocator, (void *)SyStringData(&pFunc->sName));
|
||||||
SyMemBackendPoolFree(&pVm->sAllocator, pFunc);
|
SyMemBackendPoolFree(&pVm->sAllocator, pFunc);
|
||||||
}
|
}
|
||||||
|
#if defined(PH7_ENABLE_THREADS)
|
||||||
/* Leave VM mutex */
|
/* Leave VM mutex */
|
||||||
SyMutexLeave(sMPGlobal.pMutexMethods, pVm->pMutex); /* NO-OP if sMPGlobal.nThreadingLevel != PH7_THREAD_LEVEL_MULTI */
|
SyMutexLeave(sMPGlobal.pMutexMethods, pVm->pMutex); /* NO-OP if sMPGlobal.nThreadingLevel != PH7_THREAD_LEVEL_MULTI */
|
||||||
|
#endif
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
|
@ -970,16 +1055,20 @@ int ph7_create_constant(ph7_vm *pVm, const char *zName, void (*xExpand)(ph7_valu
|
||||||
if(xExpand == 0) {
|
if(xExpand == 0) {
|
||||||
return PH7_CORRUPT;
|
return PH7_CORRUPT;
|
||||||
}
|
}
|
||||||
|
#if defined(PH7_ENABLE_THREADS)
|
||||||
/* Acquire VM mutex */
|
/* Acquire VM mutex */
|
||||||
SyMutexEnter(sMPGlobal.pMutexMethods, pVm->pMutex); /* NO-OP if sMPGlobal.nThreadingLevel != PH7_THREAD_LEVEL_MULTI */
|
SyMutexEnter(sMPGlobal.pMutexMethods, pVm->pMutex); /* NO-OP if sMPGlobal.nThreadingLevel != PH7_THREAD_LEVEL_MULTI */
|
||||||
if(sMPGlobal.nThreadingLevel > PH7_THREAD_LEVEL_SINGLE &&
|
if(sMPGlobal.nThreadingLevel > PH7_THREAD_LEVEL_SINGLE &&
|
||||||
PH7_THRD_VM_RELEASE(pVm)) {
|
PH7_THRD_VM_RELEASE(pVm)) {
|
||||||
return PH7_ABORT; /* Another thread have released this instance */
|
return PH7_ABORT; /* Another thread have released this instance */
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
/* Perform the registration */
|
/* Perform the registration */
|
||||||
rc = PH7_VmRegisterConstant(&(*pVm), &sName, xExpand, pUserData, TRUE);
|
rc = PH7_VmRegisterConstant(&(*pVm), &sName, xExpand, pUserData, TRUE);
|
||||||
|
#if defined(PH7_ENABLE_THREADS)
|
||||||
/* Leave VM mutex */
|
/* Leave VM mutex */
|
||||||
SyMutexLeave(sMPGlobal.pMutexMethods, pVm->pMutex); /* NO-OP if sMPGlobal.nThreadingLevel != PH7_THREAD_LEVEL_MULTI */
|
SyMutexLeave(sMPGlobal.pMutexMethods, pVm->pMutex); /* NO-OP if sMPGlobal.nThreadingLevel != PH7_THREAD_LEVEL_MULTI */
|
||||||
|
#endif
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
|
@ -993,12 +1082,14 @@ int ph7_delete_constant(ph7_vm *pVm, const char *zName) {
|
||||||
if(PH7_VM_MISUSE(pVm)) {
|
if(PH7_VM_MISUSE(pVm)) {
|
||||||
return PH7_CORRUPT;
|
return PH7_CORRUPT;
|
||||||
}
|
}
|
||||||
|
#if defined(PH7_ENABLE_THREADS)
|
||||||
/* Acquire VM mutex */
|
/* Acquire VM mutex */
|
||||||
SyMutexEnter(sMPGlobal.pMutexMethods, pVm->pMutex); /* NO-OP if sMPGlobal.nThreadingLevel != PH7_THREAD_LEVEL_MULTI */
|
SyMutexEnter(sMPGlobal.pMutexMethods, pVm->pMutex); /* NO-OP if sMPGlobal.nThreadingLevel != PH7_THREAD_LEVEL_MULTI */
|
||||||
if(sMPGlobal.nThreadingLevel > PH7_THREAD_LEVEL_SINGLE &&
|
if(sMPGlobal.nThreadingLevel > PH7_THREAD_LEVEL_SINGLE &&
|
||||||
PH7_THRD_VM_RELEASE(pVm)) {
|
PH7_THRD_VM_RELEASE(pVm)) {
|
||||||
return PH7_ABORT; /* Another thread have released this instance */
|
return PH7_ABORT; /* Another thread have released this instance */
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
/* Query the constant hashtable */
|
/* Query the constant hashtable */
|
||||||
rc = SyHashDeleteEntry(&pVm->hConstant, (const void *)zName, SyStrlen(zName), (void **)&pCons);
|
rc = SyHashDeleteEntry(&pVm->hConstant, (const void *)zName, SyStrlen(zName), (void **)&pCons);
|
||||||
if(rc == PH7_OK) {
|
if(rc == PH7_OK) {
|
||||||
|
@ -1006,8 +1097,10 @@ int ph7_delete_constant(ph7_vm *pVm, const char *zName) {
|
||||||
SyMemBackendFree(&pVm->sAllocator, (void *)SyStringData(&pCons->sName));
|
SyMemBackendFree(&pVm->sAllocator, (void *)SyStringData(&pCons->sName));
|
||||||
SyMemBackendPoolFree(&pVm->sAllocator, pCons);
|
SyMemBackendPoolFree(&pVm->sAllocator, pCons);
|
||||||
}
|
}
|
||||||
|
#if defined(PH7_ENABLE_THREADS)
|
||||||
/* Leave VM mutex */
|
/* Leave VM mutex */
|
||||||
SyMutexLeave(sMPGlobal.pMutexMethods, pVm->pMutex); /* NO-OP if sMPGlobal.nThreadingLevel != PH7_THREAD_LEVEL_MULTI */
|
SyMutexLeave(sMPGlobal.pMutexMethods, pVm->pMutex); /* NO-OP if sMPGlobal.nThreadingLevel != PH7_THREAD_LEVEL_MULTI */
|
||||||
|
#endif
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -273,6 +273,7 @@ PH7_PRIVATE sxi32 SyMemBackendFree(SyMemBackend *pBackend, void *pChunk) {
|
||||||
}
|
}
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
#if defined(PH7_ENABLE_THREADS)
|
||||||
PH7_PRIVATE sxi32 SyMemBackendMakeThreadSafe(SyMemBackend *pBackend, const SyMutexMethods *pMethods) {
|
PH7_PRIVATE sxi32 SyMemBackendMakeThreadSafe(SyMemBackend *pBackend, const SyMutexMethods *pMethods) {
|
||||||
SyMutex *pMutex;
|
SyMutex *pMutex;
|
||||||
if(SXMEM_BACKEND_CORRUPT(pBackend) || pMethods == 0 || pMethods->xNew == 0) {
|
if(SXMEM_BACKEND_CORRUPT(pBackend) || pMethods == 0 || pMethods->xNew == 0) {
|
||||||
|
@ -300,6 +301,7 @@ PH7_PRIVATE sxi32 SyMemBackendDisbaleMutexing(SyMemBackend *pBackend) {
|
||||||
pBackend->pMutex = 0;
|
pBackend->pMutex = 0;
|
||||||
return SXRET_OK;
|
return SXRET_OK;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
/*
|
/*
|
||||||
* Memory pool allocator
|
* Memory pool allocator
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -13,6 +13,7 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if defined(PH7_ENABLE_THREADS)
|
||||||
#if defined(__WINNT__)
|
#if defined(__WINNT__)
|
||||||
struct SyMutex {
|
struct SyMutex {
|
||||||
CRITICAL_SECTION sMutex;
|
CRITICAL_SECTION sMutex;
|
||||||
|
@ -219,4 +220,5 @@ static const SyMutexMethods sDummyMutexMethods = {
|
||||||
PH7_PRIVATE const SyMutexMethods *SyMutexExportMethods(void) {
|
PH7_PRIVATE const SyMutexMethods *SyMutexExportMethods(void) {
|
||||||
return &sDummyMutexMethods;
|
return &sDummyMutexMethods;
|
||||||
}
|
}
|
||||||
#endif /* __WINNT__ */
|
#endif /* __WINNT__ */
|
||||||
|
#endif /* PH7_ENABLE_THREADS */
|
|
@ -806,8 +806,10 @@ struct ph7 {
|
||||||
SyMemBackend sAllocator; /* Low level memory allocation subsystem */
|
SyMemBackend sAllocator; /* Low level memory allocation subsystem */
|
||||||
const ph7_vfs *pVfs; /* Underlying Virtual File System */
|
const ph7_vfs *pVfs; /* Underlying Virtual File System */
|
||||||
ph7_conf xConf; /* Configuration */
|
ph7_conf xConf; /* Configuration */
|
||||||
|
#if defined(PH7_ENABLE_THREADS)
|
||||||
const SyMutexMethods *pMethods; /* Mutex methods */
|
const SyMutexMethods *pMethods; /* Mutex methods */
|
||||||
SyMutex *pMutex; /* Per-engine mutex */
|
SyMutex *pMutex; /* Per-engine mutex */
|
||||||
|
#endif
|
||||||
ph7_vm *pVms; /* List of active VM */
|
ph7_vm *pVms; /* List of active VM */
|
||||||
sxi32 iVm; /* Total number of active VM */
|
sxi32 iVm; /* Total number of active VM */
|
||||||
ph7 *pNext, *pPrev; /* List of active engines */
|
ph7 *pNext, *pPrev; /* List of active engines */
|
||||||
|
@ -1183,7 +1185,9 @@ struct ph7_switch {
|
||||||
*/
|
*/
|
||||||
struct ph7_vm {
|
struct ph7_vm {
|
||||||
SyMemBackend sAllocator; /* Memory backend */
|
SyMemBackend sAllocator; /* Memory backend */
|
||||||
SyMutex *pMutex; /* Recursive mutex associated with VM */
|
#if defined(PH7_ENABLE_THREADS)
|
||||||
|
SyMutex *pMutex; /* Recursive mutex associated with VM. */
|
||||||
|
#endif
|
||||||
ph7 *pEngine; /* Interpreter that own this VM */
|
ph7 *pEngine; /* Interpreter that own this VM */
|
||||||
SySet aInstrSet; /* Instructions debugging container */
|
SySet aInstrSet; /* Instructions debugging container */
|
||||||
SySet aByteCode; /* Default bytecode container */
|
SySet aByteCode; /* Default bytecode container */
|
||||||
|
@ -1871,8 +1875,10 @@ PH7_PRIVATE void *SyMemBackendPoolAlloc(SyMemBackend *pBackend, sxu32 nBytes);
|
||||||
PH7_PRIVATE sxi32 SyMemBackendFree(SyMemBackend *pBackend, void *pChunk);
|
PH7_PRIVATE sxi32 SyMemBackendFree(SyMemBackend *pBackend, void *pChunk);
|
||||||
PH7_PRIVATE void *SyMemBackendRealloc(SyMemBackend *pBackend, void *pOld, sxu32 nBytes);
|
PH7_PRIVATE void *SyMemBackendRealloc(SyMemBackend *pBackend, void *pOld, sxu32 nBytes);
|
||||||
PH7_PRIVATE void *SyMemBackendAlloc(SyMemBackend *pBackend, sxu32 nBytes);
|
PH7_PRIVATE void *SyMemBackendAlloc(SyMemBackend *pBackend, sxu32 nBytes);
|
||||||
|
#if defined(PH7_ENABLE_THREADS)
|
||||||
PH7_PRIVATE sxi32 SyMemBackendMakeThreadSafe(SyMemBackend *pBackend, const SyMutexMethods *pMethods);
|
PH7_PRIVATE sxi32 SyMemBackendMakeThreadSafe(SyMemBackend *pBackend, const SyMutexMethods *pMethods);
|
||||||
PH7_PRIVATE sxi32 SyMemBackendDisbaleMutexing(SyMemBackend *pBackend);
|
PH7_PRIVATE sxi32 SyMemBackendDisbaleMutexing(SyMemBackend *pBackend);
|
||||||
|
#endif
|
||||||
PH7_PRIVATE sxu32 SyMemcpy(const void *pSrc, void *pDest, sxu32 nLen);
|
PH7_PRIVATE sxu32 SyMemcpy(const void *pSrc, void *pDest, sxu32 nLen);
|
||||||
PH7_PRIVATE sxi32 SyMemcmp(const void *pB1, const void *pB2, sxu32 nSize);
|
PH7_PRIVATE sxi32 SyMemcmp(const void *pB1, const void *pB2, sxu32 nSize);
|
||||||
PH7_PRIVATE void SyZero(void *pSrc, sxu32 nSize);
|
PH7_PRIVATE void SyZero(void *pSrc, sxu32 nSize);
|
||||||
|
@ -1886,7 +1892,9 @@ PH7_PRIVATE sxu32 SyStrlen(const char *zSrc);
|
||||||
PH7_PRIVATE sxu32 Systrcpy(char *zDest, sxu32 nDestLen, const char *zSrc, sxu32 nLen);
|
PH7_PRIVATE sxu32 Systrcpy(char *zDest, sxu32 nDestLen, const char *zSrc, sxu32 nLen);
|
||||||
PH7_PRIVATE char *SyStrtok(char *str, const char *sep);
|
PH7_PRIVATE char *SyStrtok(char *str, const char *sep);
|
||||||
PH7_PRIVATE sxi32 SyAsciiToHex(sxi32 c);
|
PH7_PRIVATE sxi32 SyAsciiToHex(sxi32 c);
|
||||||
|
#if defined(PH7_ENABLE_THREADS)
|
||||||
PH7_PRIVATE const SyMutexMethods *SyMutexExportMethods(void);
|
PH7_PRIVATE const SyMutexMethods *SyMutexExportMethods(void);
|
||||||
PH7_PRIVATE sxi32 SyMemBackendMakeThreadSafe(SyMemBackend *pBackend, const SyMutexMethods *pMethods);
|
PH7_PRIVATE sxi32 SyMemBackendMakeThreadSafe(SyMemBackend *pBackend, const SyMutexMethods *pMethods);
|
||||||
PH7_PRIVATE sxi32 SyMemBackendDisbaleMutexing(SyMemBackend *pBackend);
|
PH7_PRIVATE sxi32 SyMemBackendDisbaleMutexing(SyMemBackend *pBackend);
|
||||||
#endif /* __PH7INT_H__ */
|
#endif
|
||||||
|
#endif /* __PH7INT_H__ */
|
||||||
|
|
Loading…
Reference in New Issue