【修改】增加一些调试信息,修改一个变量名称保持逻辑统一
This commit is contained in:
@@ -625,9 +625,13 @@ int lua_plugin_manage_config_load(
|
|||||||
if (spec_check_ret)
|
if (spec_check_ret)
|
||||||
{
|
{
|
||||||
LOGERROR("check specific failed, ret is %d\n", spec_check_ret);
|
LOGERROR("check specific failed, ret is %d\n", spec_check_ret);
|
||||||
|
#if 0
|
||||||
toml_free(conf);
|
toml_free(conf);
|
||||||
free(specific);
|
free(specific);
|
||||||
return -6;
|
return -6;
|
||||||
|
#endif
|
||||||
|
specific_instance_destory(specific);
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 插入到队列中 */
|
/* 插入到队列中 */
|
||||||
@@ -641,7 +645,7 @@ int lua_plugin_manage_config_load(
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Function: lua_plugin_manage_thread_load
|
* Function: lua_plugin_manage_state_load
|
||||||
* Input: | struct lua_plugin_manage_schema * | schema | 初始化的全局变量
|
* Input: | struct lua_plugin_manage_schema * | schema | 初始化的全局变量
|
||||||
* | int | thread_count | 初始化的线程数量
|
* | int | thread_count | 初始化的线程数量
|
||||||
* Output:
|
* Output:
|
||||||
@@ -651,27 +655,29 @@ int lua_plugin_manage_config_load(
|
|||||||
* | -3 | 线程状态机加载过程失败
|
* | -3 | 线程状态机加载过程失败
|
||||||
* Description: 依次创建好每个线程中的状态机
|
* Description: 依次创建好每个线程中的状态机
|
||||||
*/
|
*/
|
||||||
int lua_plugin_manage_thread_load(
|
int lua_plugin_manage_state_load(
|
||||||
struct lua_plugin_manage_schema *schema,
|
struct lua_plugin_manage_schema *schema,
|
||||||
int thread_count)
|
int thread_count)
|
||||||
{
|
{
|
||||||
if (__glibc_unlikely(!schema || thread_count <= 0 || thread_count >= LUA_PLUGIN_MANAGE_MAX_THREAD_COUNT))
|
if (__glibc_unlikely(!schema || thread_count <= 0 || thread_count >= LUA_PLUGIN_MANAGE_MAX_THREAD_COUNT))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
utarray_new(schema->lua_plugin_thread_array, &thread_state_icd);
|
utarray_new(schema->lua_plugin_state_array, &thread_state_icd);
|
||||||
utarray_reserve(schema->lua_plugin_thread_array, thread_count);
|
utarray_reserve(schema->lua_plugin_state_array, thread_count);
|
||||||
struct lua_thread_state new_thread_state;
|
struct lua_thread_state new_thread_state;
|
||||||
for (int i = 1; i <= thread_count; ++i)
|
for (int i = 1; i <= thread_count; ++i)
|
||||||
{
|
{
|
||||||
|
/* 依次初始化后加入链表 */
|
||||||
memset(&new_thread_state, 0, sizeof(new_thread_state));
|
memset(&new_thread_state, 0, sizeof(new_thread_state));
|
||||||
if (thread_state_instance_init(&new_thread_state, i))
|
if (thread_state_instance_init(&new_thread_state, i))
|
||||||
return -2;
|
return -2;
|
||||||
utarray_push_back(schema->lua_plugin_thread_array, &new_thread_state);
|
utarray_push_back(schema->lua_plugin_state_array, &new_thread_state);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct lua_thread_state *thread_state = NULL;
|
struct lua_thread_state *thread_state = NULL;
|
||||||
while ((thread_state = utarray_next(schema->lua_plugin_thread_array, thread_state)))
|
while ((thread_state = utarray_next(schema->lua_plugin_state_array, thread_state)))
|
||||||
{
|
{
|
||||||
|
/* 依次对每一个线程中的状态机进行初始化 */
|
||||||
if (thread_state_instance_load(thread_state, schema))
|
if (thread_state_instance_load(thread_state, schema))
|
||||||
return -3;
|
return -3;
|
||||||
}
|
}
|
||||||
@@ -705,22 +711,26 @@ struct lua_plugin_manage_schema *lua_plugin_manage_init(
|
|||||||
if (new_schema->lua_config_specific_count < 0)
|
if (new_schema->lua_config_specific_count < 0)
|
||||||
{
|
{
|
||||||
/* 可以没有插件配置, 但是不能在加载过程中出错 */
|
/* 可以没有插件配置, 但是不能在加载过程中出错 */
|
||||||
free(new_schema);
|
lua_plugin_manage_exit(new_schema);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
#ifdef LUAPLUGIN_BASIC_UNITTEST
|
#ifdef LUAPLUGIN_BASIC_UNITTEST
|
||||||
struct lua_config_specific *specific = NULL;
|
struct lua_config_specific *specific = NULL;
|
||||||
|
int unittest_config_num = 0;
|
||||||
while ((specific = utarray_next(new_schema->lua_config_specific_array, specific)))
|
while ((specific = utarray_next(new_schema->lua_config_specific_array, specific)))
|
||||||
{
|
{
|
||||||
printf("path is %s\n", specific->config_specific_file);
|
printf("path[%d] is %s\n", unittest_config_num, specific->config_specific_file);
|
||||||
printf("load is %s\n", specific->config_specific_load_func);
|
printf("load[%d] is %s\n", unittest_config_num, specific->config_specific_load_func);
|
||||||
printf("unload is %s\n", specific->config_specific_unload_func);
|
printf("unload[%d] is %s\n", unittest_config_num, specific->config_specific_unload_func);
|
||||||
|
unittest_config_num += 1;
|
||||||
}
|
}
|
||||||
|
printf("\n");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int thread_count = 1;
|
int thread_count = stellar_get_worker_thread_num(st);
|
||||||
/* 依次创建线程状态机, 并加入链表 */
|
/* 依次创建线程状态机, 并加入链表 */
|
||||||
new_schema->lua_plugin_thread_count = lua_plugin_manage_thread_load(new_schema, thread_count);
|
new_schema->lua_plugin_state_count = lua_plugin_manage_state_load(new_schema, thread_count);
|
||||||
|
LOGDEBUG("load thread state finish, load count is %d", new_schema->lua_plugin_state_count);
|
||||||
|
|
||||||
return new_schema;
|
return new_schema;
|
||||||
}
|
}
|
||||||
@@ -738,9 +748,48 @@ void lua_plugin_manage_exit(struct lua_plugin_manage_schema *lua_plug_mgr)
|
|||||||
return;
|
return;
|
||||||
if (lua_plug_mgr->lua_config_specific_array)
|
if (lua_plug_mgr->lua_config_specific_array)
|
||||||
utarray_free(lua_plug_mgr->lua_config_specific_array);
|
utarray_free(lua_plug_mgr->lua_config_specific_array);
|
||||||
if (lua_plug_mgr->lua_plugin_thread_array)
|
if (lua_plug_mgr->lua_plugin_state_array)
|
||||||
utarray_free(lua_plug_mgr->lua_plugin_thread_array);
|
utarray_free(lua_plug_mgr->lua_plugin_state_array);
|
||||||
|
free(lua_plug_mgr);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef LUAPLUGIN_BASIC_UNITTEST
|
||||||
|
void debug_lua_state_stack(lua_State * state, int mod, const char * message)
|
||||||
|
{
|
||||||
|
int stackcount = lua_gettop(state);
|
||||||
|
/* nothing in stack */
|
||||||
|
if ( !stackcount ) {
|
||||||
|
printf("debug stack, but stack is empty");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("\n***** begin to debug one lua stack *****\n");
|
||||||
|
if ( message ) printf("debug here: %s\n", message);
|
||||||
|
int i = stackcount;
|
||||||
|
/* print variables one by one */
|
||||||
|
for ( ; i > 0; --i ) {
|
||||||
|
/* adjust variables according to mod */
|
||||||
|
if ( mod ) i = 0 - i;
|
||||||
|
int type = lua_type(state, i);
|
||||||
|
printf("stack[%d]: ", i);
|
||||||
|
switch (type) {
|
||||||
|
case LUA_TBOOLEAN:
|
||||||
|
printf(lua_toboolean(state, i) ? "true\n" : "false\n");
|
||||||
|
break;
|
||||||
|
case LUA_TNUMBER:
|
||||||
|
printf("%g\n", lua_tonumber(state, i));
|
||||||
|
break;
|
||||||
|
case LUA_TSTRING:
|
||||||
|
printf("%s\n", lua_tostring(state, i));
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
printf("this is not normal type, type is: %d[%s]\n", type, lua_typename(state, type));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
/* adjust variables according to mod */
|
||||||
|
if ( mod ) i = 0 - i;
|
||||||
|
}
|
||||||
|
printf("***** end of debug one lua stack *****\n\n");
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user