|
|
@@ -56,6 +56,10 @@
|
|
|
#define PROCESS_EXIT_TIMEOUT 4000
|
|
|
#define ENTITY_TEST_TIMEOUT 30000
|
|
|
|
|
|
+extern void sp_mod_mgr_lockEx(int EntityId);
|
|
|
+extern void sp_mod_mgr_unlockEx(int EntityId);
|
|
|
+extern void sp_mod_mgr_lockArrClean();
|
|
|
+
|
|
|
struct sp_mod_stub_t
|
|
|
{
|
|
|
sp_mod_stub_cb cb;
|
|
|
@@ -765,7 +769,6 @@ static HANDLE create_module_process(const char *mod_name, int epid, int range, i
|
|
|
}
|
|
|
|
|
|
WaitForSingleObject(hMutex, 5000);
|
|
|
- Sleep(100);
|
|
|
CloseHandle(hMutex);
|
|
|
|
|
|
|
|
|
@@ -922,12 +925,10 @@ static int on_detect_process_end(process_monitor_t *monitor, HANDLE hproc, void
|
|
|
sp_mod_mgr_t *mgr = (sp_mod_mgr_t*)user_data;
|
|
|
sp_mod_t *mod;
|
|
|
|
|
|
- sp_mod_mgr_lock(mgr);
|
|
|
list_for_each_entry(mod, &mgr->mod_list, sp_mod_t, entry) {
|
|
|
if (mod->state && mod->process_handle == hproc) {
|
|
|
sp_entity_t *ent;
|
|
|
-// DWORD dwExitCode = -1;
|
|
|
-// GetExitCodeProcess(hproc, &dwExitCode);
|
|
|
+ sp_mod_mgr_lockEx(mod->cfg->idx);
|
|
|
sp_dbg_info("detect process [mod=%s] exit", mod->cfg->name); //no exit code
|
|
|
CloseHandle(mod->process_handle);
|
|
|
mod->process_handle = NULL;
|
|
|
@@ -942,10 +943,10 @@ static int on_detect_process_end(process_monitor_t *monitor, HANDLE hproc, void
|
|
|
}
|
|
|
}
|
|
|
SetEvent(mod->evt_app_exit);
|
|
|
+ sp_mod_mgr_unlockEx(mod->cfg->idx);
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
- sp_mod_mgr_unlock(mgr);
|
|
|
|
|
|
return TRUE; // delete process handle
|
|
|
}
|
|
|
@@ -1128,7 +1129,7 @@ static int mgr_on_pkt(sp_svc_t *svc,int epid, int svc_id, int pkt_type, int pkt_
|
|
|
sp_entity_t *ent = sp_mod_mgr_find_entity_by_idx(mgr, svc_id);
|
|
|
int state = pkt_id;
|
|
|
if ((ent->state == EntityState_Idle || ent->state == EntityState_Busy) && state != ent->state) {
|
|
|
- sp_mod_mgr_lock(mgr);
|
|
|
+ sp_mod_mgr_lockEx(ent->cfg->idx);
|
|
|
if (ent->state == EntityState_Idle || ent->state == EntityState_Busy) {
|
|
|
if (ent->state != state) {
|
|
|
int old_state = ent->state;
|
|
|
@@ -1136,7 +1137,7 @@ static int mgr_on_pkt(sp_svc_t *svc,int epid, int svc_id, int pkt_type, int pkt_
|
|
|
mgr_on_entity_state(mgr, ent, ent->cfg->idx, old_state, state);
|
|
|
}
|
|
|
}
|
|
|
- sp_mod_mgr_unlock(mgr);
|
|
|
+ sp_mod_mgr_unlockEx(ent->cfg->idx);
|
|
|
}
|
|
|
} else if (cmd_type == MOD_CMD_SUBSCRIBE_STATE_LISTENER) {
|
|
|
subscribe_entity_state(mgr, epid, svc_id, pkt_id);
|
|
|
@@ -1371,13 +1372,13 @@ void sp_mod_mgr_bind_bcm_daemon(sp_mod_mgr_t *mgr, sp_bcm_daemon_t *daemon)
|
|
|
void sp_mod_mgr_lock(sp_mod_mgr_t *mgr)
|
|
|
{
|
|
|
EnterCriticalSection(&mgr->lock);
|
|
|
- //sp_dbg_debug("lock mgr %d", GetCurrentThreadId());
|
|
|
+ //sp_dbg_info("lock mgr %d, lock %d",mgr, &(mgr->lock));
|
|
|
}
|
|
|
|
|
|
void sp_mod_mgr_unlock(sp_mod_mgr_t *mgr)
|
|
|
{
|
|
|
LeaveCriticalSection(&mgr->lock);
|
|
|
- //sp_dbg_debug("unlock mgr %d", GetCurrentThreadId());
|
|
|
+ //sp_dbg_info("unlock mgr %d, lock %d", mgr, &(mgr->lock));
|
|
|
}
|
|
|
|
|
|
sp_mod_t *sp_mod_mgr_find_module_by_name(sp_mod_mgr_t *mgr, const char *mod_name)
|
|
|
@@ -1513,20 +1514,20 @@ int sp_mod_mgr_get_entity_array_nelts(sp_mod_mgr_t *mgr)
|
|
|
static int try_lock_doing(sp_mod_mgr_t *mgr, sp_mod_t *mod)
|
|
|
{
|
|
|
int ok = FALSE;
|
|
|
- sp_mod_mgr_lock(mgr);
|
|
|
+ sp_mod_mgr_lockEx(mod->cfg->idx);
|
|
|
if (!mod->doing) {
|
|
|
mod->doing = 1;
|
|
|
ok = TRUE;
|
|
|
}
|
|
|
- sp_mod_mgr_unlock(mgr);
|
|
|
+ sp_mod_mgr_unlockEx(mod->cfg->idx);
|
|
|
return ok;
|
|
|
}
|
|
|
|
|
|
static void unlock_doing(sp_mod_mgr_t *mgr, sp_mod_t *mod)
|
|
|
{
|
|
|
- sp_mod_mgr_lock(mgr);
|
|
|
+ sp_mod_mgr_lockEx(mod->cfg->idx);
|
|
|
mod->doing = 0;
|
|
|
- sp_mod_mgr_unlock(mgr);
|
|
|
+ sp_mod_mgr_unlockEx(mod->cfg->idx);
|
|
|
}
|
|
|
|
|
|
static int load_module(sp_mod_mgr_t *mgr, sp_mod_t *mod, int trigger_entity_id)
|
|
|
@@ -1536,7 +1537,7 @@ static int load_module(sp_mod_mgr_t *mgr, sp_mod_t *mod, int trigger_entity_id)
|
|
|
|
|
|
sp_dbg_debug("begin load module %s", mod->cfg->name);
|
|
|
|
|
|
- sp_mod_mgr_lock(mgr);
|
|
|
+ sp_mod_mgr_lockEx(mod->cfg->idx);
|
|
|
if (!mod->state) {
|
|
|
ResetEvent(mod->evt_app_exit);
|
|
|
mod->process_handle = create_module_process(mod->cfg->name, mod->cfg->idx, env->shm_range, &mod->process_id, mod->cfg->group);
|
|
|
@@ -1547,7 +1548,7 @@ static int load_module(sp_mod_mgr_t *mgr, sp_mod_t *mod, int trigger_entity_id)
|
|
|
} else {
|
|
|
rc = Error_Duplication;
|
|
|
}
|
|
|
- sp_mod_mgr_unlock(mgr);
|
|
|
+ sp_mod_mgr_unlockEx(mod->cfg->idx);
|
|
|
|
|
|
if (rc == 0) {
|
|
|
const int interval = 50;
|
|
|
@@ -1602,7 +1603,7 @@ static int load_module(sp_mod_mgr_t *mgr, sp_mod_t *mod, int trigger_entity_id)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- sp_mod_mgr_lock(mgr);
|
|
|
+ sp_mod_mgr_lockEx(mod->cfg->idx);
|
|
|
if (rc == 0) {
|
|
|
mod->state = SP_MODULE_STATE_LOAD;
|
|
|
mod->start_time = y2k_time_now();
|
|
|
@@ -1617,7 +1618,7 @@ static int load_module(sp_mod_mgr_t *mgr, sp_mod_t *mod, int trigger_entity_id)
|
|
|
mod->process_id = 0;
|
|
|
sp_dbg_info("load module failed!");
|
|
|
}
|
|
|
- sp_mod_mgr_unlock(mgr);
|
|
|
+ sp_mod_mgr_unlockEx(mod->cfg->idx);
|
|
|
|
|
|
return rc;
|
|
|
}
|
|
|
@@ -1627,7 +1628,7 @@ static int unload_module(sp_mod_mgr_t *mgr, sp_mod_t *mod, int trigger_entity_id
|
|
|
int rc = 0;
|
|
|
sp_entity_t *pos;
|
|
|
|
|
|
- sp_mod_mgr_lock(mgr);
|
|
|
+ sp_mod_mgr_lockEx(mod->cfg->idx);
|
|
|
if (mod->state) {
|
|
|
list_for_each_entry(pos, &mod->entity_list, sp_entity_t, entry) {
|
|
|
if (pos->state != EntityState_Killed &&
|
|
|
@@ -1648,7 +1649,7 @@ static int unload_module(sp_mod_mgr_t *mgr, sp_mod_t *mod, int trigger_entity_id
|
|
|
sp_dbg_debug("module %s already unloaded!", mod->cfg->name);
|
|
|
rc = Error_NotInit;
|
|
|
}
|
|
|
- sp_mod_mgr_unlock(mgr);
|
|
|
+ sp_mod_mgr_unlockEx(mod->cfg->idx);
|
|
|
|
|
|
if (rc == 0) {
|
|
|
int removed = 0;
|
|
|
@@ -1703,12 +1704,12 @@ static int unload_module(sp_mod_mgr_t *mgr, sp_mod_t *mod, int trigger_entity_id
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- sp_mod_mgr_lock(mgr);
|
|
|
+ sp_mod_mgr_lockEx(mod->cfg->idx);
|
|
|
if (removed) {
|
|
|
mod->state = SP_MODULE_STATE_UNLOAD;
|
|
|
SetEvent(mod->evt_app_exit);
|
|
|
}
|
|
|
- sp_mod_mgr_unlock(mgr);
|
|
|
+ sp_mod_mgr_unlockEx(mod->cfg->idx);
|
|
|
|
|
|
}
|
|
|
|
|
|
@@ -1737,7 +1738,7 @@ static int terminate_module(sp_mod_mgr_t *mgr, sp_mod_t *mod, int trigger_entity
|
|
|
int rc = 0;
|
|
|
sp_entity_t *pos;
|
|
|
|
|
|
- sp_mod_mgr_lock(mgr);
|
|
|
+ sp_mod_mgr_lockEx(mod->cfg->idx);
|
|
|
if (mod->state) {
|
|
|
if (mod->process_handle) {
|
|
|
if (process_monitor_remove(mgr->process_monitor, mod->process_handle) == 0) {
|
|
|
@@ -1782,7 +1783,7 @@ static int terminate_module(sp_mod_mgr_t *mgr, sp_mod_t *mod, int trigger_entity
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- sp_mod_mgr_unlock(mgr);
|
|
|
+ sp_mod_mgr_unlockEx(mod->cfg->idx);
|
|
|
|
|
|
return rc;
|
|
|
}
|
|
|
@@ -1794,7 +1795,7 @@ static int start_entity(sp_mod_mgr_t *mgr, sp_entity_t *ent, const char *cmdline
|
|
|
|
|
|
sp_dbg_debug("begin start entity %s", ent->cfg->name);
|
|
|
|
|
|
- sp_mod_mgr_lock(mgr);
|
|
|
+ sp_mod_mgr_lockEx(mod->cfg->idx);
|
|
|
if (mod->state) {
|
|
|
if (ent->state == EntityState_NoStart || ent->state == EntityState_Killed || ent->state == EntityState_Close) {
|
|
|
iobuffer_t *pkt = iobuffer_create(-1, -1);
|
|
|
@@ -1825,7 +1826,7 @@ static int start_entity(sp_mod_mgr_t *mgr, sp_entity_t *ent, const char *cmdline
|
|
|
sp_dbg_debug("entity's %s 's module is not load or is pending!", ent->cfg->name);
|
|
|
rc = Error_Pending;
|
|
|
}
|
|
|
- sp_mod_mgr_unlock(mgr);
|
|
|
+ sp_mod_mgr_unlockEx(mod->cfg->idx);
|
|
|
|
|
|
if (rc == 0) {
|
|
|
int last_state = ent->state;
|
|
|
@@ -1842,7 +1843,7 @@ static int start_entity(sp_mod_mgr_t *mgr, sp_entity_t *ent, const char *cmdline
|
|
|
rc = Error_TimeOut;
|
|
|
}
|
|
|
|
|
|
- sp_mod_mgr_lock(mgr);
|
|
|
+ sp_mod_mgr_lockEx(mod->cfg->idx);
|
|
|
if (rc == 0) {
|
|
|
ent->state = EntityState_Idle;
|
|
|
ent->state_start_time = y2k_time_now();
|
|
|
@@ -1853,7 +1854,7 @@ static int start_entity(sp_mod_mgr_t *mgr, sp_entity_t *ent, const char *cmdline
|
|
|
mgr_on_entity_exception(mgr, ent, trigger_entity_id, Error_Exception);
|
|
|
}
|
|
|
mgr_on_entity_state(mgr, ent, trigger_entity_id, last_state, ent->state);
|
|
|
- sp_mod_mgr_unlock(mgr);
|
|
|
+ sp_mod_mgr_unlockEx(mod->cfg->idx);
|
|
|
}
|
|
|
|
|
|
return rc;
|
|
|
@@ -1864,7 +1865,7 @@ static int stop_entity(sp_mod_mgr_t *mgr, sp_entity_t *ent, int trigger_entity_i
|
|
|
int rc = 0;
|
|
|
sp_mod_t *mod = ent->mod;
|
|
|
|
|
|
- sp_mod_mgr_lock(mgr);
|
|
|
+ sp_mod_mgr_lockEx(mod->cfg->idx);
|
|
|
if (mod->state) {
|
|
|
if (ent->state == EntityState_Busy || ent->state == EntityState_Idle || ent->state == EntityState_Pause) {
|
|
|
iobuffer_t *body = iobuffer_create(-1, -1);
|
|
|
@@ -1891,7 +1892,7 @@ static int stop_entity(sp_mod_mgr_t *mgr, sp_entity_t *ent, int trigger_entity_i
|
|
|
sp_dbg_debug("entity's %s mod %s is not load or is pending!", ent->cfg->name, mod->cfg->name);
|
|
|
rc = Error_Pending;
|
|
|
}
|
|
|
- sp_mod_mgr_unlock(mgr);
|
|
|
+ sp_mod_mgr_unlockEx(mod->cfg->idx);
|
|
|
|
|
|
if (rc == 0) {
|
|
|
int last_state = ent->state;
|
|
|
@@ -1908,7 +1909,7 @@ static int stop_entity(sp_mod_mgr_t *mgr, sp_entity_t *ent, int trigger_entity_i
|
|
|
rc = Error_TimeOut;
|
|
|
}
|
|
|
|
|
|
- sp_mod_mgr_lock(mgr);
|
|
|
+ sp_mod_mgr_lockEx(mod->cfg->idx);
|
|
|
if (rc == 0) {
|
|
|
ent->state = EntityState_Close;
|
|
|
ent->state_start_time = y2k_time_now();
|
|
|
@@ -1919,7 +1920,7 @@ static int stop_entity(sp_mod_mgr_t *mgr, sp_entity_t *ent, int trigger_entity_i
|
|
|
mgr_on_entity_exception(mgr, ent, trigger_entity_id, Error_Exception);
|
|
|
}
|
|
|
mgr_on_entity_state(mgr, ent, trigger_entity_id, last_state, ent->state);
|
|
|
- sp_mod_mgr_unlock(mgr);
|
|
|
+ sp_mod_mgr_unlockEx(mod->cfg->idx);
|
|
|
}
|
|
|
|
|
|
return rc;
|
|
|
@@ -1930,8 +1931,8 @@ static int pause_entity(sp_mod_mgr_t *mgr, sp_entity_t *ent, int trigger_entity_
|
|
|
int rc = 0;
|
|
|
sp_mod_t *mod;
|
|
|
|
|
|
- sp_mod_mgr_lock(mgr);
|
|
|
mod = ent->mod;
|
|
|
+ sp_mod_mgr_lockEx(mod->cfg->idx);
|
|
|
if (mod->state) {
|
|
|
if (ent->state == EntityState_Busy || ent->state == EntityState_Idle) {
|
|
|
iobuffer_t *body = iobuffer_create(-1, -1);
|
|
|
@@ -1953,7 +1954,7 @@ static int pause_entity(sp_mod_mgr_t *mgr, sp_entity_t *ent, int trigger_entity_
|
|
|
sp_dbg_debug("entity's %s mod %s is not load or is pending!", ent->cfg->name, mod->cfg->name);
|
|
|
rc = Error_Unexpect;
|
|
|
}
|
|
|
- sp_mod_mgr_unlock(mgr);
|
|
|
+ sp_mod_mgr_unlockEx(mod->cfg->idx);
|
|
|
|
|
|
if (rc == 0) {
|
|
|
HANDLE hs[] = {mod->evt_app_exit, ent->evt_wait_handle};
|
|
|
@@ -1969,14 +1970,14 @@ static int pause_entity(sp_mod_mgr_t *mgr, sp_entity_t *ent, int trigger_entity_
|
|
|
rc = Error_TimeOut;
|
|
|
}
|
|
|
|
|
|
- sp_mod_mgr_lock(mgr);
|
|
|
+ sp_mod_mgr_lockEx(mod->cfg->idx);
|
|
|
if (rc == 0) {
|
|
|
int last_state = ent->state;
|
|
|
ent->state = EntityState_Pause;
|
|
|
ent->state_start_time = y2k_time_now();
|
|
|
mgr_on_entity_state(mgr, ent, trigger_entity_id, last_state, ent->state);
|
|
|
}
|
|
|
- sp_mod_mgr_unlock(mgr);
|
|
|
+ sp_mod_mgr_unlockEx(mod->cfg->idx);
|
|
|
}
|
|
|
|
|
|
return rc;
|
|
|
@@ -1987,8 +1988,8 @@ static int continue_entity(sp_mod_mgr_t *mgr, sp_entity_t *ent, int trigger_enti
|
|
|
int rc = 0;
|
|
|
sp_mod_t*mod;
|
|
|
|
|
|
- sp_mod_mgr_lock(mgr);
|
|
|
mod = ent->mod;
|
|
|
+ sp_mod_mgr_lockEx(mod->cfg->idx);
|
|
|
if (mod->state) {
|
|
|
if (ent->state == EntityState_Pause) {
|
|
|
iobuffer_t *body = iobuffer_create(-1, -1);
|
|
|
@@ -2010,7 +2011,7 @@ static int continue_entity(sp_mod_mgr_t *mgr, sp_entity_t *ent, int trigger_enti
|
|
|
sp_dbg_debug("entity's %s mod %s is not load or is pending!", ent->cfg->name, mod->cfg->name);
|
|
|
rc = Error_Unexpect;
|
|
|
}
|
|
|
- sp_mod_mgr_unlock(mgr);
|
|
|
+ sp_mod_mgr_unlockEx(mod->cfg->idx);
|
|
|
|
|
|
if (rc == 0) {
|
|
|
HANDLE hs[] = {mod->evt_app_exit, ent->evt_wait_handle};
|
|
|
@@ -2026,13 +2027,13 @@ static int continue_entity(sp_mod_mgr_t *mgr, sp_entity_t *ent, int trigger_enti
|
|
|
rc = Error_TimeOut;
|
|
|
}
|
|
|
|
|
|
- sp_mod_mgr_lock(mgr);
|
|
|
+ sp_mod_mgr_lockEx(mod->cfg->idx);
|
|
|
if (rc == 0) {
|
|
|
ent->state = EntityState_Idle;
|
|
|
ent->state_start_time = y2k_time_now();
|
|
|
mgr_on_entity_state(mgr, ent, trigger_entity_id, EntityState_Pause, ent->state);
|
|
|
}
|
|
|
- sp_mod_mgr_unlock(mgr);
|
|
|
+ sp_mod_mgr_unlockEx(mod->cfg->idx);
|
|
|
}
|
|
|
|
|
|
return rc;
|
|
|
@@ -2043,8 +2044,8 @@ static int test_entity(sp_mod_mgr_t *mgr, sp_entity_t *ent, int test_type, int t
|
|
|
int rc = 0;
|
|
|
sp_mod_t *mod;
|
|
|
|
|
|
- sp_mod_mgr_lock(mgr);
|
|
|
mod = ent->mod;
|
|
|
+ sp_mod_mgr_lockEx(mod->cfg->idx);
|
|
|
if (mod->state) {
|
|
|
if (ent->state == EntityState_Idle || ent->state == EntityState_Busy || ent->state == EntityState_Pause) {
|
|
|
iobuffer_t *body = iobuffer_create(-1, -1);
|
|
|
@@ -2067,7 +2068,7 @@ static int test_entity(sp_mod_mgr_t *mgr, sp_entity_t *ent, int test_type, int t
|
|
|
sp_dbg_debug("entity's %s mod %s is not load or is pending!", ent->cfg->name, mod->cfg->name);
|
|
|
rc = Error_Unexpect;
|
|
|
}
|
|
|
- sp_mod_mgr_unlock(mgr);
|
|
|
+ sp_mod_mgr_unlockEx(mod->cfg->idx);
|
|
|
|
|
|
if (rc == 0) {
|
|
|
HANDLE hs[] = {mod->evt_app_exit, ent->evt_wait_handle};
|
|
|
@@ -2149,8 +2150,8 @@ int sp_mod_mgr_lost_entity(sp_mod_mgr_t *mgr, int entity_id, int trigger_entity_
|
|
|
if (!ent)
|
|
|
return Error_NotExist;
|
|
|
|
|
|
- sp_mod_mgr_lock(mgr);
|
|
|
mod = ent->mod;
|
|
|
+ sp_mod_mgr_lockEx(mod->cfg->idx);
|
|
|
if (mod->state) {
|
|
|
int last_state = ent->state;
|
|
|
sp_dbg_debug("set entity %s lost ok!", ent->cfg->name);
|
|
|
@@ -2159,7 +2160,7 @@ int sp_mod_mgr_lost_entity(sp_mod_mgr_t *mgr, int entity_id, int trigger_entity_
|
|
|
mgr_on_entity_state(mgr, ent, ent->cfg->idx, last_state, ent->state);
|
|
|
}
|
|
|
|
|
|
- sp_mod_mgr_unlock(mgr);
|
|
|
+ sp_mod_mgr_unlockEx(mod->cfg->idx);
|
|
|
return Error_Succeed;
|
|
|
}
|
|
|
|