move skynet.memlimit from skynet.manager to skynet

This commit is contained in:
Cloud Wu
2016-05-07 09:23:01 +08:00
parent 4b96ade660
commit a5c79cc4bd
4 changed files with 7 additions and 5 deletions

View File

@@ -656,6 +656,11 @@ function skynet.term(service)
return _error_dispatch(0, service)
end
function skynet.memlimit(bytes)
debug.getregistry().memlimit = bytes
skynet.memlimit = nil -- set only once
end
local function clear_pool()
coroutine_pool = {}
end

View File

@@ -20,10 +20,6 @@ function skynet.abort()
c.command("ABORT")
end
function skynet.memlimit(bytes)
debug.getregistry().memlimit = bytes
end
local function globalname(name, handle)
local c = string.sub(name,1,1)
assert(c ~= ':')

View File

@@ -121,6 +121,8 @@ init_cb(struct snlua *l, struct skynet_context *ctx, const char * args, size_t s
size_t limit = lua_tointeger(L, -1);
l->mem_limit = limit;
skynet_error(ctx, "Set memory limit to %.2f M", (float)limit / (1024 * 1024));
lua_pushnil(L);
lua_setfield(L, LUA_REGISTRYINDEX, "memlimit");
}
lua_pop(L, 1);

View File

@@ -1,5 +1,4 @@
local skynet = require "skynet"
require "skynet.manager"
-- set sandbox memory limit to 1M, must set here (at start, out of skynet.start)
skynet.memlimit(1 * 1024 * 1024)