diff options
author | Jo-Philipp Wich <jow@openwrt.org> | 2009-07-10 17:38:01 +0000 |
---|---|---|
committer | Jo-Philipp Wich <jow@openwrt.org> | 2009-07-10 17:38:01 +0000 |
commit | 60613ef05cd3ca9086c5e5c9ac292f5630f3f533 (patch) | |
tree | 9a76b12284e470269c8ed4868abcaf322751ce10 /libs | |
parent | 7dcb05fd1c4abb4281f6e8eb35616c3a545c961e (diff) |
libs/core: trigger garbage collection in coxpcall() if 80% of the allocated memory pool are filled
Diffstat (limited to 'libs')
-rw-r--r-- | libs/core/luasrc/util.lua | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/libs/core/luasrc/util.lua b/libs/core/luasrc/util.lua index adeb99fb1..e86d5ec23 100644 --- a/libs/core/luasrc/util.lua +++ b/libs/core/luasrc/util.lua @@ -37,6 +37,7 @@ local rawget, rawset, unpack = rawget, rawset, unpack local tostring, type, assert = tostring, type, assert local ipairs, pairs, loadstring = ipairs, pairs, loadstring local require, pcall, xpcall = require, pcall, xpcall +local collectgarbage, get_memory_limit = collectgarbage, get_memory_limit --- LuCI utility functions. module "luci.util" @@ -784,5 +785,11 @@ end -- Resume execution of protected function call function performResume(err, co, ...) + if get_memory_limit and get_memory_limit() > 0 and + collectgarbage("count") > (get_memory_limit() * 0.8) + then + collectgarbage("collect") + end + return handleReturnValue(err, co, coroutine.resume(co, ...)) end |