Fix LuCId behaviour if thread-limit is reached
This commit is contained in:
parent
2dcd2eb9b2
commit
7372c00dda
2 changed files with 26 additions and 12 deletions
|
@ -110,23 +110,26 @@ end
|
||||||
-- This main function of LuCId will wait for events on given file descriptors.
|
-- This main function of LuCId will wait for events on given file descriptors.
|
||||||
function run()
|
function run()
|
||||||
local pollint = tonumber((cursor:get(UCINAME, "main", "pollinterval")))
|
local pollint = tonumber((cursor:get(UCINAME, "main", "pollinterval")))
|
||||||
local threadlimit = tonumber(cursor:get(UCINAME, "main", "threadlimit"))
|
local threadlimit = tonumber((cursor:get(UCINAME, "main", "threadlimit")))
|
||||||
|
|
||||||
while true do
|
while true do
|
||||||
if not threadlimit or tcount < threadlimit then
|
|
||||||
local stat, code = nixio.poll(pollt, pollint)
|
local stat, code = nixio.poll(pollt, pollint)
|
||||||
|
|
||||||
if stat and stat > 0 then
|
if stat and stat > 0 then
|
||||||
|
local ok = false
|
||||||
for _, polle in ipairs(pollt) do
|
for _, polle in ipairs(pollt) do
|
||||||
if polle.revents ~= 0 and polle.handler then
|
if polle.revents ~= 0 and polle.handler then
|
||||||
polle.handler(polle)
|
ok = ok or polle.handler(polle)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
if not ok then
|
||||||
|
-- Avoid high CPU usage if thread limit is reached
|
||||||
|
nixio.nanosleep(0, 100000000)
|
||||||
|
end
|
||||||
elseif stat == 0 then
|
elseif stat == 0 then
|
||||||
ifaddrs = nixio.getifaddrs()
|
ifaddrs = nixio.getifaddrs()
|
||||||
collectgarbage("collect")
|
collectgarbage("collect")
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
for _, cb in ipairs(tickt) do
|
for _, cb in ipairs(tickt) do
|
||||||
cb()
|
cb()
|
||||||
|
@ -200,6 +203,14 @@ function unregister_tick(cb)
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--- Tests whether a given number of processes can be created.
|
||||||
|
-- @oaram num Processes to be created
|
||||||
|
-- @return boolean status
|
||||||
|
function try_process(num)
|
||||||
|
local threadlimit = tonumber((cursor:get(UCINAME, "main", "threadlimit")))
|
||||||
|
return not threadlimit or (threadlimit - tcount) >= (num or 1)
|
||||||
|
end
|
||||||
|
|
||||||
--- Create a new child process from a Lua function and assign a destructor.
|
--- Create a new child process from a Lua function and assign a destructor.
|
||||||
-- @param threadcb main function of the new process
|
-- @param threadcb main function of the new process
|
||||||
-- @param waitcb destructor callback
|
-- @param waitcb destructor callback
|
||||||
|
|
|
@ -111,6 +111,9 @@ end
|
||||||
-- @param polle Poll descriptor
|
-- @param polle Poll descriptor
|
||||||
-- @return handler process id or nil, error code, error message
|
-- @return handler process id or nil, error code, error message
|
||||||
function accept(polle)
|
function accept(polle)
|
||||||
|
if not lucid.try_process() then
|
||||||
|
return false
|
||||||
|
end
|
||||||
local socket, host, port = polle.fd:accept()
|
local socket, host, port = polle.fd:accept()
|
||||||
if not socket then
|
if not socket then
|
||||||
return nixio.syslog("warn", "accept() failed: " .. port)
|
return nixio.syslog("warn", "accept() failed: " .. port)
|
||||||
|
|
Loading…
Reference in a new issue