| 111 | } |
| 112 | |
| 113 | ts_lua_main_ctx * |
| 114 | create_lua_vms() |
| 115 | { |
| 116 | ts_lua_main_ctx *ctx_array = nullptr; |
| 117 | |
| 118 | // Inject the setting into records.yaml |
| 119 | static bool ts_mgt_int_inserted = false; |
| 120 | if (!ts_mgt_int_inserted) { |
| 121 | if (TS_SUCCESS == TSMgmtIntCreate(TS_RECORDTYPE_CONFIG, ts_lua_mgmt_state_str, TS_LUA_MAX_STATE_COUNT, |
| 122 | TS_RECORDUPDATE_RESTART_TS, TS_RECORDCHECK_INT, ts_lua_mgmt_state_regex, |
| 123 | TS_RECORDACCESS_READ_ONLY)) { |
| 124 | Dbg(dbg_ctl, "[%s] registered config string %s: with default [%d]", __FUNCTION__, ts_lua_mgmt_state_str, |
| 125 | TS_LUA_MAX_STATE_COUNT); |
| 126 | } else { |
| 127 | TSError("[%s][%s] failed to register %s", TS_LUA_DEBUG_TAG, __FUNCTION__, ts_lua_mgmt_state_str); |
| 128 | } |
| 129 | ts_mgt_int_inserted = true; |
| 130 | } |
| 131 | |
| 132 | if (0 == ts_lua_max_state_count) { |
| 133 | TSMgmtInt mgmt_state = 0; |
| 134 | |
| 135 | if (TS_SUCCESS != TSMgmtIntGet(ts_lua_mgmt_state_str, &mgmt_state)) { |
| 136 | Dbg(dbg_ctl, "[%s] setting max state to default: %d", __FUNCTION__, TS_LUA_MAX_STATE_COUNT); |
| 137 | ts_lua_max_state_count = TS_LUA_MAX_STATE_COUNT; |
| 138 | } else { |
| 139 | ts_lua_max_state_count = (int)mgmt_state; |
| 140 | Dbg(dbg_ctl, "[%s] found %s: [%d]", __FUNCTION__, ts_lua_mgmt_state_str, ts_lua_max_state_count); |
| 141 | } |
| 142 | |
| 143 | if (ts_lua_max_state_count < 1) { |
| 144 | TSError("[ts_lua][%s] invalid %s: %d", __FUNCTION__, ts_lua_mgmt_state_str, ts_lua_max_state_count); |
| 145 | ts_lua_max_state_count = 0; |
| 146 | return nullptr; |
| 147 | } |
| 148 | } |
| 149 | |
| 150 | ctx_array = TSRalloc<ts_lua_main_ctx>(ts_lua_max_state_count); |
| 151 | memset(ctx_array, 0, sizeof(ts_lua_main_ctx) * ts_lua_max_state_count); |
| 152 | |
| 153 | int const ret = ts_lua_create_vm(ctx_array, ts_lua_max_state_count); |
| 154 | |
| 155 | if (ret) { |
| 156 | ts_lua_destroy_vm(ctx_array, ts_lua_max_state_count); |
| 157 | TSfree(ctx_array); |
| 158 | ctx_array = nullptr; |
| 159 | return nullptr; |
| 160 | } |
| 161 | |
| 162 | // Initialize the GC numbers, no need to lock here |
| 163 | for (int index = 0; index < ts_lua_max_state_count; ++index) { |
| 164 | ts_lua_main_ctx *const main_ctx = (ctx_array + index); |
| 165 | lua_State *const lstate = main_ctx->lua; |
| 166 | ts_lua_ctx_stats *const stats = main_ctx->stats; |
| 167 | |
| 168 | stats->gc_kb = stats->gc_kb_max = lua_getgccount(lstate); |
| 169 | } |
| 170 |
no test coverage detected