mirror of
https://github.com/octoleo/lsyncd.git
synced 2025-01-08 09:18:30 +00:00
changed e2d logic to be unlucky garbage collector safe
This commit is contained in:
parent
8ff50c0a48
commit
559936fe84
83
lsyncd.lua
83
lsyncd.lua
@ -522,11 +522,25 @@ end)()
|
|||||||
-- Creates inlets for syncs: the user interface for events.
|
-- Creates inlets for syncs: the user interface for events.
|
||||||
--
|
--
|
||||||
local InletFactory = (function()
|
local InletFactory = (function()
|
||||||
-- table to receive the delay of an event.
|
-----
|
||||||
|
-- table to receive the delay of an event
|
||||||
-- or the delay list of an event list.
|
-- or the delay list of an event list.
|
||||||
|
--
|
||||||
|
-- Keys are events and values are delays.
|
||||||
local e2d = {}
|
local e2d = {}
|
||||||
-- dont stop the garbage collector to remove entries.
|
|
||||||
setmetatable(e2d, { __mode = 'v' })
|
-----
|
||||||
|
-- table to ensure the uniqueness of every event
|
||||||
|
-- related to a delay.
|
||||||
|
--
|
||||||
|
-- Keys are delay and values are events.
|
||||||
|
local e2d2 = {}
|
||||||
|
|
||||||
|
-----
|
||||||
|
-- allows the garbage collector to remove not refrenced
|
||||||
|
-- events.
|
||||||
|
setmetatable(e2d, { __mode = 'k' })
|
||||||
|
setmetatable(e2d2, { __mode = 'v' })
|
||||||
|
|
||||||
-----
|
-----
|
||||||
-- removes the trailing slash from a path
|
-- removes the trailing slash from a path
|
||||||
@ -782,58 +796,59 @@ local InletFactory = (function()
|
|||||||
end
|
end
|
||||||
}
|
}
|
||||||
|
|
||||||
----
|
-----
|
||||||
-- table of all inlets with their syncs
|
-- table of all inlets with their syncs
|
||||||
--
|
--
|
||||||
local inlets = {}
|
local inlets = {}
|
||||||
|
|
||||||
-- dont stop the garbage collector to remove entries.
|
-----
|
||||||
|
-- allows the garbage collector to remove entries.
|
||||||
|
-- TODO check memory use
|
||||||
setmetatable(inlets, { __mode = 'v' })
|
setmetatable(inlets, { __mode = 'v' })
|
||||||
|
|
||||||
-----
|
-----
|
||||||
-- Encapsulates a delay into an event for the user script.
|
-- Encapsulates a delay into an event for the user script.
|
||||||
--
|
--
|
||||||
local function d2e(sync, delay)
|
local function d2e(delay)
|
||||||
|
-- already created?
|
||||||
|
local eu = e2d2[delay]
|
||||||
|
|
||||||
if delay.etype ~= 'Move' then
|
if delay.etype ~= 'Move' then
|
||||||
if not delay.event then
|
if eu then return eu end
|
||||||
|
|
||||||
local event = {}
|
local event = {}
|
||||||
delay.event = event
|
|
||||||
setmetatable(event, eventMeta)
|
setmetatable(event, eventMeta)
|
||||||
e2d[event] = delay
|
e2d[event] = delay
|
||||||
end
|
e2d2[delay] = event
|
||||||
return delay.event
|
return event
|
||||||
else
|
else
|
||||||
-- moves have 2 events - origin and destination
|
-- moves have 2 events - origin and destination
|
||||||
if not delay.event then
|
if eu then return eu[1], eu[2] end
|
||||||
local event = {}
|
|
||||||
local event2 = {}
|
|
||||||
delay.event = event
|
|
||||||
delay.event2 = event2
|
|
||||||
|
|
||||||
|
local event = { move = 'Fr' }
|
||||||
|
local event2 = { move = 'To' }
|
||||||
setmetatable(event, eventMeta)
|
setmetatable(event, eventMeta)
|
||||||
setmetatable(event2, eventMeta)
|
setmetatable(event2, eventMeta)
|
||||||
e2d[delay.event] = delay
|
e2d[event] = delay
|
||||||
e2d[delay.event2] = delay
|
e2d[event2] = delay
|
||||||
|
e2d2[delay] = { event, event2 }
|
||||||
-- move events have a field 'move'
|
-- move events have a field 'move'
|
||||||
event.move = 'Fr'
|
return event, event2
|
||||||
event2.move = 'To'
|
|
||||||
end
|
|
||||||
return delay.event, delay.event2
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-----
|
-----
|
||||||
-- Encapsulates a delay list into an event list for the user script.
|
-- Encapsulates a delay list into an event list for the user script.
|
||||||
--
|
--
|
||||||
local function dl2el(sync, dlist)
|
local function dl2el(dlist)
|
||||||
if not dlist.elist then
|
local eu = e2d2[dlist]
|
||||||
|
if eu then return eu end
|
||||||
|
|
||||||
local elist = {}
|
local elist = {}
|
||||||
dlist.elist = elist
|
|
||||||
setmetatable(elist, eventListMeta)
|
setmetatable(elist, eventListMeta)
|
||||||
e2d[elist] = dlist
|
e2d[elist] = dlist
|
||||||
end
|
e2d2[dlist] = elist
|
||||||
return dlist.elist
|
return elist
|
||||||
end
|
end
|
||||||
|
|
||||||
-----
|
-----
|
||||||
@ -873,7 +888,7 @@ local InletFactory = (function()
|
|||||||
-- and is blocked by everything.
|
-- and is blocked by everything.
|
||||||
--
|
--
|
||||||
createBlanketEvent = function(sync)
|
createBlanketEvent = function(sync)
|
||||||
return d2e(sync, sync:addBlanketDelay())
|
return d2e(sync:addBlanketDelay())
|
||||||
end,
|
end,
|
||||||
|
|
||||||
-----
|
-----
|
||||||
@ -894,7 +909,7 @@ local InletFactory = (function()
|
|||||||
-- Gets the next not blocked event from queue.
|
-- Gets the next not blocked event from queue.
|
||||||
--
|
--
|
||||||
getEvent = function(sync)
|
getEvent = function(sync)
|
||||||
return d2e(sync, sync:getNextDelay(now()))
|
return d2e(sync:getNextDelay(now()))
|
||||||
end,
|
end,
|
||||||
|
|
||||||
-----
|
-----
|
||||||
@ -904,7 +919,7 @@ local InletFactory = (function()
|
|||||||
--
|
--
|
||||||
getEvents = function(sync, test)
|
getEvents = function(sync, test)
|
||||||
local dlist = sync:getDelays(test)
|
local dlist = sync:getDelays(test)
|
||||||
return dl2el(sync, dlist)
|
return dl2el(dlist)
|
||||||
end,
|
end,
|
||||||
|
|
||||||
-----
|
-----
|
||||||
@ -1166,7 +1181,7 @@ local Sync = (function()
|
|||||||
error('collecting a non-active process')
|
error('collecting a non-active process')
|
||||||
end
|
end
|
||||||
local rc = self.config.collect(
|
local rc = self.config.collect(
|
||||||
InletFactory.d2e(self, delay),
|
InletFactory.d2e(delay),
|
||||||
exitcode)
|
exitcode)
|
||||||
if rc == 'die' then
|
if rc == 'die' then
|
||||||
log('Error', 'Critical exitcode.');
|
log('Error', 'Critical exitcode.');
|
||||||
@ -1189,7 +1204,7 @@ local Sync = (function()
|
|||||||
else
|
else
|
||||||
log('Delay', 'collected a list')
|
log('Delay', 'collected a list')
|
||||||
local rc = self.config.collect(
|
local rc = self.config.collect(
|
||||||
InletFactory.dl2el(self, delay),
|
InletFactory.dl2el(delay),
|
||||||
exitcode)
|
exitcode)
|
||||||
if rc == 'die' then
|
if rc == 'die' then
|
||||||
log('Error', 'Critical exitcode.');
|
log('Error', 'Critical exitcode.');
|
||||||
@ -1398,7 +1413,7 @@ local Sync = (function()
|
|||||||
|
|
||||||
for i, d in Queue.qpairs(self.delays) do
|
for i, d in Queue.qpairs(self.delays) do
|
||||||
if d.status == 'active' or
|
if d.status == 'active' or
|
||||||
(test and not test(InletFactory.d2e(self, d)))
|
(test and not test(InletFactory.d2e(d)))
|
||||||
then
|
then
|
||||||
getBlocks(d)
|
getBlocks(d)
|
||||||
elseif not blocks[d] then
|
elseif not blocks[d] then
|
||||||
@ -1438,7 +1453,7 @@ local Sync = (function()
|
|||||||
if d.etype ~= 'Init' then
|
if d.etype ~= 'Init' then
|
||||||
self.config.action(self.inlet)
|
self.config.action(self.inlet)
|
||||||
else
|
else
|
||||||
self.config.init(InletFactory.d2e(self, d))
|
self.config.init(InletFactory.d2e(d))
|
||||||
end
|
end
|
||||||
if self.processes:size() >= self.config.maxProcesses then
|
if self.processes:size() >= self.config.maxProcesses then
|
||||||
-- no further processes
|
-- no further processes
|
||||||
|
Loading…
Reference in New Issue
Block a user