optimized delay lists

This commit is contained in:
Axel Kittenberger 2010-12-11 23:00:33 +00:00
parent bd6e753fbc
commit 22e4b27a45

View File

@ -164,7 +164,7 @@ Queue = (function()
----- -----
-- Creates a new queue. -- Creates a new queue.
local function new() local function new()
return { first = 0, last = -1, size = 0}; return { first = 1, last = 0, size = 0};
end end
----- -----
@ -206,8 +206,8 @@ Queue = (function()
-- reset indizies if list is empty -- reset indizies if list is empty
if list.last < list.first then if list.last < list.first then
list.last = -1 list.first = 1
list.first = 0 list.last = 0
end end
list.size = list.size - 1 list.size = list.size - 1
end end
@ -740,18 +740,19 @@ local InletFactory = (function()
error("cannot find delay list from event list.") error("cannot find delay list from event list.")
end end
local result = {} local result = {}
for k, d in pairs(dlist) do local resultn = 1
if type(k) == "number" then for k, d in ipairs(dlist) do
local s1, s2 local s1, s2
if mutator then if mutator then
s1, s2 = mutator(d.etype, d.path, d.path2) s1, s2 = mutator(d.etype, d.path, d.path2)
else else
s1, s2 = d.path, d.path2 s1, s2 = d.path, d.path2
end end
table.insert(result, s1) result[resultn] = s1
if s2 then resultn = resultn + 1
table.insert(result, s2) if s2 then
end result[resultn] = s2
resultn = resultn + 1
end end
end end
return result return result
@ -1204,20 +1205,16 @@ local Sync = (function()
alarm = 1 alarm = 1
end end
alarm = now() + alarm alarm = now() + alarm
for k, d in pairs(delay) do for _, d in ipairs(delay) do
if type(k) == "number" then d.alarm = alarm
d.alarm = alarm d.status = "wait"
d.status = "wait"
end
end end
end end
for k, d in pairs(delay) do for _, d in ipairs(delay) do
if type(k) == "number" then if rc ~= "again" then
if rc ~= "again" then removeDelay(self, d)
removeDelay(self, d) else
else d.status = "wait"
d.status = "wait"
end
end end
end end
log("Delay","Finished list = ",exitcode) log("Delay","Finished list = ",exitcode)
@ -1379,6 +1376,8 @@ local Sync = (function()
-- --
local function getDelays(self, test) local function getDelays(self, test)
local dlist = {} local dlist = {}
local dlistn = 1
local blocks = {} local blocks = {}
---- ----
@ -1399,12 +1398,11 @@ local Sync = (function()
then then
getBlocks(d) getBlocks(d)
elseif not blocks[d] then elseif not blocks[d] then
dlist[i] = d dlist[dlistn] = d
dlistn = dlistn + 1
end end
end end
--- TODO: make incremental indexes in dlist,
-- and replace pairs with ipairs.
return dlist return dlist
end end
@ -2928,10 +2926,8 @@ function spawn(agent, binary, ...)
sync.processes[pid] = dol sync.processes[pid] = dol
else else
-- is a list -- is a list
for k, d in pairs(dol) do for _, d in ipairs(dol) do
if type(k) == "number" then d.status = "active"
d.status = "active"
end
end end
sync.processes[pid] = dol sync.processes[pid] = dol
end end