mirror of
https://github.com/cloudwu/skynet.git
synced 2026-07-25 04:33:05 +00:00
rewrite SSM and clonefunction
This commit is contained in:
@@ -4,7 +4,6 @@
|
||||
#include <lauxlib.h>
|
||||
|
||||
#include "malloc_hook.h"
|
||||
#include "luashrtbl.h"
|
||||
|
||||
static int
|
||||
ltotal(lua_State *L) {
|
||||
@@ -36,13 +35,6 @@ ldump(lua_State *L) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
lexpandshrtbl(lua_State *L) {
|
||||
int n = luaL_checkinteger(L, 1);
|
||||
luaS_expandshr(n);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
lcurrent(lua_State *L) {
|
||||
lua_pushinteger(L, malloc_current_memory());
|
||||
@@ -79,8 +71,6 @@ luaopen_skynet_memory(lua_State *L) {
|
||||
{ "dumpinfo", ldumpinfo },
|
||||
{ "dump", ldump },
|
||||
{ "info", dump_mem_lua },
|
||||
{ "ssinfo", luaS_shrinfo },
|
||||
{ "ssexpand", lexpandshrtbl },
|
||||
{ "current", lcurrent },
|
||||
{ "dumpheap", ldumpheap },
|
||||
{ "profactive", lprofactive },
|
||||
|
||||
72
lualib-src/lua-ssm.c
Normal file
72
lualib-src/lua-ssm.c
Normal file
@@ -0,0 +1,72 @@
|
||||
#define LUA_LIB
|
||||
|
||||
#include <lua.h>
|
||||
#include <lauxlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "lstring.h"
|
||||
|
||||
static int
|
||||
linfo(lua_State *L) {
|
||||
struct ssm_info info;
|
||||
memset(&info, 0, sizeof(info));
|
||||
luaS_infossm(&info);
|
||||
lua_createtable(L, 0, 5);
|
||||
lua_pushinteger(L, info.total);
|
||||
lua_setfield(L, -2, "n");
|
||||
lua_pushinteger(L, info.longest);
|
||||
lua_setfield(L, -2, "longest");
|
||||
lua_pushinteger(L, info.slots);
|
||||
lua_setfield(L, -2, "slots");
|
||||
lua_pushinteger(L, info.size);
|
||||
lua_setfield(L, -2, "size");
|
||||
lua_pushnumber(L, info.variance);
|
||||
lua_setfield(L, -2, "variance");
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
lcollect(lua_State *L) {
|
||||
int loop = lua_toboolean(L, 1);
|
||||
if (loop) {
|
||||
int n = 0;
|
||||
struct ssm_collect info;
|
||||
while (luaS_collectssm(&info)) {
|
||||
n+=info.n;
|
||||
}
|
||||
lua_pushinteger(L, n);
|
||||
return 1;
|
||||
} else {
|
||||
struct ssm_collect info;
|
||||
int again = luaS_collectssm(&info);
|
||||
if (again && lua_istable(L, 2)) {
|
||||
lua_pushinteger(L, info.n);
|
||||
lua_setfield(L, 2, "n");
|
||||
lua_pushlightuserdata(L, info.key);
|
||||
lua_setfield(L, 2, "key");
|
||||
}
|
||||
lua_pushboolean(L, again);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
LUAMOD_API int
|
||||
luaopen_skynet_ssm(lua_State *L) {
|
||||
luaL_checkversion(L);
|
||||
|
||||
luaL_Reg l[] = {
|
||||
{ "info", linfo },
|
||||
{ "collect", lcollect },
|
||||
{ NULL, NULL },
|
||||
};
|
||||
|
||||
luaL_newlib(L,l);
|
||||
|
||||
#ifndef ENABLE_SHORT_STRING_TABLE
|
||||
lua_pushboolean(L, 1);
|
||||
lua_setfield(L, -2, "disable");
|
||||
#endif
|
||||
return 1;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user