From 09c1a5488b0aae24e456880df81cdce22956bbe6 Mon Sep 17 00:00:00 2001 From: niubinghui Date: Wed, 7 Aug 2024 15:08:44 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E4=BF=AE=E6=94=B9=E3=80=91=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E4=B8=80=E4=BA=9B=E8=B0=83=E8=AF=95=E4=BF=A1=E6=81=AF?= =?UTF-8?q?=EF=BC=8C=E4=BF=AE=E6=94=B9=E4=B8=80=E4=B8=AA=E5=8F=98=E9=87=8F?= =?UTF-8?q?=E5=90=8D=E7=A7=B0=E4=BF=9D=E6=8C=81=E9=80=BB=E8=BE=91=E7=BB=9F?= =?UTF-8?q?=E4=B8=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/lua_plugin_manage.c | 77 +++++++++++++++++++++++++++++++++-------- 1 file changed, 63 insertions(+), 14 deletions(-) diff --git a/src/lua_plugin_manage.c b/src/lua_plugin_manage.c index 32d9b8d..3543444 100644 --- a/src/lua_plugin_manage.c +++ b/src/lua_plugin_manage.c @@ -625,9 +625,13 @@ int lua_plugin_manage_config_load( if (spec_check_ret) { LOGERROR("check specific failed, ret is %d\n", spec_check_ret); +#if 0 toml_free(conf); free(specific); 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 | 初始化的全局变量 * | int | thread_count | 初始化的线程数量 * Output: @@ -651,27 +655,29 @@ int lua_plugin_manage_config_load( * | -3 | 线程状态机加载过程失败 * Description: 依次创建好每个线程中的状态机 */ -int lua_plugin_manage_thread_load( +int lua_plugin_manage_state_load( struct lua_plugin_manage_schema *schema, int thread_count) { if (__glibc_unlikely(!schema || thread_count <= 0 || thread_count >= LUA_PLUGIN_MANAGE_MAX_THREAD_COUNT)) return -1; - utarray_new(schema->lua_plugin_thread_array, &thread_state_icd); - utarray_reserve(schema->lua_plugin_thread_array, thread_count); + utarray_new(schema->lua_plugin_state_array, &thread_state_icd); + utarray_reserve(schema->lua_plugin_state_array, thread_count); struct lua_thread_state new_thread_state; for (int i = 1; i <= thread_count; ++i) { + /* 依次初始化后加入链表 */ memset(&new_thread_state, 0, sizeof(new_thread_state)); if (thread_state_instance_init(&new_thread_state, i)) 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; - 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)) return -3; } @@ -705,22 +711,26 @@ struct lua_plugin_manage_schema *lua_plugin_manage_init( if (new_schema->lua_config_specific_count < 0) { /* 可以没有插件配置, 但是不能在加载过程中出错 */ - free(new_schema); + lua_plugin_manage_exit(new_schema); return NULL; } #ifdef LUAPLUGIN_BASIC_UNITTEST struct lua_config_specific *specific = NULL; + int unittest_config_num = 0; while ((specific = utarray_next(new_schema->lua_config_specific_array, specific))) { - printf("path is %s\n", specific->config_specific_file); - printf("load is %s\n", specific->config_specific_load_func); - printf("unload is %s\n", specific->config_specific_unload_func); + printf("path[%d] is %s\n", unittest_config_num, specific->config_specific_file); + printf("load[%d] is %s\n", unittest_config_num, specific->config_specific_load_func); + printf("unload[%d] is %s\n", unittest_config_num, specific->config_specific_unload_func); + unittest_config_num += 1; } + printf("\n"); #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; } @@ -738,9 +748,48 @@ void lua_plugin_manage_exit(struct lua_plugin_manage_schema *lua_plug_mgr) return; if (lua_plug_mgr->lua_config_specific_array) utarray_free(lua_plug_mgr->lua_config_specific_array); - if (lua_plug_mgr->lua_plugin_thread_array) - utarray_free(lua_plug_mgr->lua_plugin_thread_array); + if (lua_plug_mgr->lua_plugin_state_array) + utarray_free(lua_plug_mgr->lua_plugin_state_array); + free(lua_plug_mgr); 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