From 89f487e0a4413c91d48af27bf6bed4898977a0e0 Mon Sep 17 00:00:00 2001 From: Cloud Wu Date: Tue, 2 Jul 2019 23:08:54 +0800 Subject: [PATCH] bugfix: init the lock of code cache at start --- 3rd/lua/lauxlib.c | 6 +++++- 3rd/lua/lualib.h | 1 + skynet-src/skynet_main.c | 5 +++++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/3rd/lua/lauxlib.c b/3rd/lua/lauxlib.c index 6b2f98f2..6da4db78 100644 --- a/3rd/lua/lauxlib.c +++ b/3rd/lua/lauxlib.c @@ -1063,10 +1063,14 @@ clearcache() { static void init() { - SPIN_INIT(&CC); CC.L = luaL_newstate(); } +LUALIB_API void +luaL_initcodecache(void) { + SPIN_INIT(&CC); +} + static const void * load(const char *key) { if (CC.L == NULL) diff --git a/3rd/lua/lualib.h b/3rd/lua/lualib.h index 422b9ea5..1bd3fb51 100644 --- a/3rd/lua/lualib.h +++ b/3rd/lua/lualib.h @@ -49,6 +49,7 @@ LUAMOD_API int (luaopen_package) (lua_State *L); #define LUA_CACHELIB LUAMOD_API int (luaopen_cache) (lua_State *L); +LUALIB_API void (luaL_initcodecache) (void); /* open all previous libraries */ LUALIB_API void (luaL_openlibs) (lua_State *L); diff --git a/skynet-src/skynet_main.c b/skynet-src/skynet_main.c index ba7bb847..a96c312d 100644 --- a/skynet-src/skynet_main.c +++ b/skynet-src/skynet_main.c @@ -132,6 +132,11 @@ main(int argc, char *argv[]) { struct skynet_config config; +#ifdef LUA_CACHELIB + // init the lock of code cache + luaL_initcodecache(); +#endif + struct lua_State *L = luaL_newstate(); luaL_openlibs(L); // link lua lib