Working on STC
This commit is contained in:
parent
772095431f
commit
62e05788d2
10
makeENV.lua
10
makeENV.lua
@ -1,9 +1,9 @@
|
|||||||
commands = [[
|
commands = [[
|
||||||
mkdir luajit && python -m hererocks -j 2.1.0-beta3 -r latest --patch --compat all ./luajit && set "PATH=G:\VSCWorkspace\multi\luajit\bin;%PATH%" && lua -v && luarocks install multi
|
mkdir luajit && python -m hererocks -j 2.1.0-beta3 -r latest --patch --compat all ./luajit && set "PATH=G:\VSCWorkspace\multi\luajit\bin;%PATH%" && lua -v && luarocks install multi && luarocks install lanes
|
||||||
mkdir lua5.1 && python -m hererocks -l 5.1 -r latest --patch --compat all ./lua5.1 && set "PATH=G:\VSCWorkspace\multi\luajit\bin;%PATH%" && lua -v && luarocks install multi
|
mkdir lua5.1 && python -m hererocks -l 5.1 -r latest --patch --compat all ./lua5.1 && set "PATH=G:\VSCWorkspace\multi\luajit\bin;%PATH%" && lua -v && luarocks install multi && luarocks install lanes
|
||||||
mkdir lua5.2 && python -m hererocks -l 5.2 -r latest --patch --compat all ./lua5.2 && set "PATH=G:\VSCWorkspace\multi\luajit\bin;%PATH%" && lua -v && luarocks install multi
|
mkdir lua5.2 && python -m hererocks -l 5.2 -r latest --patch --compat all ./lua5.2 && set "PATH=G:\VSCWorkspace\multi\luajit\bin;%PATH%" && lua -v && luarocks install multi && luarocks install lanes
|
||||||
mkdir lua5.3 && python -m hererocks -l 5.3 -r latest --patch --compat all ./lua5.3 && set "PATH=G:\VSCWorkspace\multi\luajit\bin;%PATH%" && lua -v && luarocks install multi
|
mkdir lua5.3 && python -m hererocks -l 5.3 -r latest --patch --compat all ./lua5.3 && set "PATH=G:\VSCWorkspace\multi\luajit\bin;%PATH%" && lua -v && luarocks install multi && luarocks install lanes
|
||||||
mkdir lua5.4 && python -m hererocks -l 5.4 -r latest --patch --compat all ./lua5.4 && set "PATH=G:\VSCWorkspace\multi\luajit\bin;%PATH%" && lua -v && luarocks install multi
|
mkdir lua5.4 && python -m hererocks -l 5.4 -r latest --patch --compat all ./lua5.4 && set "PATH=G:\VSCWorkspace\multi\luajit\bin;%PATH%" && lua -v && luarocks install multi && luarocks install lanes
|
||||||
]]
|
]]
|
||||||
function string.split (inputstr, sep)
|
function string.split (inputstr, sep)
|
||||||
local sep = sep or "\n"
|
local sep = sep or "\n"
|
||||||
|
|||||||
@ -328,7 +328,7 @@ function multi:newConnection(protect,func,kill)
|
|||||||
conn_helper = func
|
conn_helper = func
|
||||||
end
|
end
|
||||||
|
|
||||||
c.Connect=c.connect
|
c.connect=c.Connect
|
||||||
c.GetConnection=c.getConnection
|
c.GetConnection=c.getConnection
|
||||||
c.HasConnections = c.hasConnections
|
c.HasConnections = c.hasConnections
|
||||||
c.GetConnection = c.getConnection
|
c.GetConnection = c.getConnection
|
||||||
|
|||||||
142
test.lua
142
test.lua
@ -1,15 +1,15 @@
|
|||||||
package.path = "./?/init.lua;?.lua;lua5.4/share/lua/?/init.lua;lua5.4/share/lua/?.lua;"..package.path
|
package.path = "./?/init.lua;?.lua;lua5.2/share/lua/5.2/?/init.lua;lua5.2/share/lua/5.2/?.lua;"
|
||||||
package.cpath = "lua5.4/lib/lua/?/core.dll;"..package.cpath
|
package.cpath = "lua5.2/lib/lua/5.2/?/core.dll;"
|
||||||
multi, thread = require("multi"):init{print=true}
|
multi, thread = require("multi"):init{print=true}
|
||||||
GLOBAL, THREAD = require("multi.integration.lanesManager"):init()
|
GLOBAL, THREAD = require("multi.integration.lanesManager"):init()
|
||||||
|
|
||||||
function multi:newSystemThreadedConnection(name,...)
|
function multi:newSystemThreadedConnection(name)
|
||||||
|
local name = name or multi.randomString(16)
|
||||||
local c = {}
|
local c = {}
|
||||||
c.CONN = 0x00
|
c.CONN = 0x00
|
||||||
c.TRIG = 0x01
|
c.TRIG = 0x01
|
||||||
c.PING = 0x02
|
c.PING = 0x02
|
||||||
c.PONG = 0x03
|
c.PONG = 0x03
|
||||||
c.proxy_conn = multi:newConnection(...)
|
|
||||||
local function remove(a, b)
|
local function remove(a, b)
|
||||||
local ai = {}
|
local ai = {}
|
||||||
local r = {}
|
local r = {}
|
||||||
@ -19,37 +19,14 @@ function multi:newSystemThreadedConnection(name,...)
|
|||||||
end
|
end
|
||||||
return r
|
return r
|
||||||
end
|
end
|
||||||
local name = name or multi.randomString(16)
|
|
||||||
c.Name = name
|
c.Name = name
|
||||||
local connections = {} -- All triggers sent from main connection. When a connection is triggered on another thread, they speak to the main then send stuff out.
|
c.links = {} -- All triggers sent from main connection. When a connection is triggered on another thread, they speak to the main then send stuff out.
|
||||||
local funcs = {}
|
local ping
|
||||||
setmetatable(c,master_conn) -- A different approach will be taken for the non main connection objects
|
ping = thread:newFunction(function(self)
|
||||||
c.subscribe = multi:newSystemThreadedQueue("SUB_STC_"..name):init() -- Incoming subscriptions
|
ping:Pause() -- Don't allow this function to be called until the first instance is done
|
||||||
multi:newThread("STC_SUB_MAN"..name,function()
|
|
||||||
local item
|
|
||||||
while true do
|
|
||||||
thread.yield()
|
|
||||||
-- We need to check on broken connections
|
|
||||||
c:Ping() -- Should return instantlly and process this in another thread
|
|
||||||
thread.hold(function()
|
|
||||||
item = c.subscribe:peek()
|
|
||||||
if item ~= nil and item[1] == c.CONN then
|
|
||||||
c.subscribe:pop()
|
|
||||||
connections[#connections+1] = item
|
|
||||||
multi.ForEach(funcs, function(link) -- Sync new connections
|
|
||||||
item:push{c.CONN, link}
|
|
||||||
end)
|
|
||||||
end
|
|
||||||
-- Nil return keeps this hold going until timeout
|
|
||||||
end,{cycles=multi.Priority_Normal})
|
|
||||||
-- Usually a bunch of threads subscribe close to the same time.
|
|
||||||
-- Give those threads some time to ready up.
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
c.Ping = thread:newFunction(function(self)
|
|
||||||
c.Ping:Pause() -- Don't allow this function to be called more than once
|
|
||||||
local pings = {}
|
local pings = {}
|
||||||
multi.ForEach(funcs, function(link) -- Sync new connections
|
local count = #self.links
|
||||||
|
multi.ForEach(self.links, function(link) -- Sync new connections
|
||||||
link:push{self.PING}
|
link:push{self.PING}
|
||||||
end)
|
end)
|
||||||
thread.hold(function()
|
thread.hold(function()
|
||||||
@ -57,36 +34,97 @@ function multi:newSystemThreadedConnection(name,...)
|
|||||||
if item ~= nil and item[1] == self.PONG then
|
if item ~= nil and item[1] == self.PONG then
|
||||||
table.insert(pings,item[2])
|
table.insert(pings,item[2])
|
||||||
end
|
end
|
||||||
|
if #pings==count then
|
||||||
|
return true -- If we get all pings give control back
|
||||||
|
end
|
||||||
end,{sleep=3}) -- Give all threads time to respond to the ping
|
end,{sleep=3}) -- Give all threads time to respond to the ping
|
||||||
-- We waited long enough for a response, anything that did not respond gets removed
|
-- We waited long enough for a response, anything that did not respond gets removed
|
||||||
remove(funcs, pings)
|
self.links = remove(self.links, pings)
|
||||||
c.Ping:Resume()
|
ping:Resume()
|
||||||
end,false)
|
end,false)
|
||||||
|
|
||||||
|
thread:newThread("STC_SUB_MAN"..name,function()
|
||||||
|
local item
|
||||||
|
while true do
|
||||||
|
thread.yield()
|
||||||
|
-- We need to check on broken connections
|
||||||
|
ping() -- Should return instantlly and process this in another thread
|
||||||
|
thread.hold(function()
|
||||||
|
item = c.subscribe:peek()
|
||||||
|
if item ~= nil and item[1] == c.CONN then
|
||||||
|
c.subscribe:pop()
|
||||||
|
multi.ForEach(c.links, function(link) -- Sync new connections
|
||||||
|
item[2]:push{c.CONN, link}
|
||||||
|
end)
|
||||||
|
c.links[#c.links+1] = item
|
||||||
|
end
|
||||||
|
-- Nil return keeps this hold going until timeout
|
||||||
|
end,{cycles=multi.Priority_Normal})
|
||||||
|
-- Usually a bunch of threads subscribe close to the same time.
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
|
||||||
function c:Fire(...)
|
function c:Fire(...)
|
||||||
master_conn:Fire(...)
|
self.proxy_conn:Fire(...)
|
||||||
multi.ForEach(funcs, function(link) -- Sync new connections
|
local args = {...}
|
||||||
link:push{self.TRIG,{...}}
|
multi.ForEach(self.links, function(link) -- Sync new connections
|
||||||
end)
|
print(link[2]) -- Bugs everywhere
|
||||||
end
|
for i,v in pairs(link[2]) do print(i,v) end
|
||||||
function c:Sync(link)
|
link[2]:push{self.TRIG, args}
|
||||||
--
|
|
||||||
end
|
|
||||||
function c:Connect(func)
|
|
||||||
local conn_func = func
|
|
||||||
self.proxy_conn(func)
|
|
||||||
proxy_conn(function()
|
|
||||||
funcs[#funcs+1] = func -- Used for syncing new connections to this connection later on
|
|
||||||
multi.ForEach(self.connections, function(link)
|
|
||||||
link:push{CONN, func}
|
|
||||||
end)
|
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
function c:init()
|
function c:init()
|
||||||
self.proxy_conn
|
self.links = {}
|
||||||
|
self.proxy_conn = multi:newConnection()
|
||||||
|
setmetatable(self, {__index = self.proxy_conn})
|
||||||
|
self.subscribe = multi:newSystemThreadedQueue("SUB_STC_"..self.Name):init() -- Incoming subscriptions
|
||||||
|
thread:newThread("STC_CONN_MAN"..name,function()
|
||||||
|
local item
|
||||||
|
local link_self_ref = multi:newSystemThreadedQueue()
|
||||||
|
self.subscribe:push{self.CONN,link_self_ref}
|
||||||
|
while true do
|
||||||
|
item = thread.hold(function()
|
||||||
|
return self.subscribe:peek()
|
||||||
|
end)
|
||||||
|
if item[1] == self.PING then
|
||||||
|
self.subscribe:push{self.PONG, link_self_ref}
|
||||||
|
elseif item[1] == self.CONN then
|
||||||
|
if item[2] ~= link_self_ref then
|
||||||
|
table.insert(self.links, item[2])
|
||||||
|
end
|
||||||
|
elseif item[1] == self.TRIG then
|
||||||
|
self.proxy_conn:Fire(unpack(item[2]))
|
||||||
|
else
|
||||||
|
-- This shouldn't be the case
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end)
|
||||||
return self
|
return self
|
||||||
end
|
end
|
||||||
|
|
||||||
GLOBAL[name] = c
|
GLOBAL[name] = c
|
||||||
|
|
||||||
return c
|
return c
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local conn = multi:newSystemThreadedConnection("conn"):init()
|
||||||
|
multi:newSystemThread("Test",function()
|
||||||
|
local multi, thread = require("multi"):init()
|
||||||
|
local conn = THREAD.waitFor("conn"):init()
|
||||||
|
conn(function()
|
||||||
|
print("Thread was triggered!")
|
||||||
|
end)
|
||||||
|
multi:mainloop()
|
||||||
|
end)
|
||||||
|
-- conn(function()
|
||||||
|
-- print("Mainloop conn got triggered!")
|
||||||
|
-- end)
|
||||||
|
|
||||||
|
alarm = multi:newAlarm(1)
|
||||||
|
alarm:OnRing(function()
|
||||||
|
print("Ring")
|
||||||
|
conn:Fire()
|
||||||
|
end)
|
||||||
|
|
||||||
multi:mainloop()
|
multi:mainloop()
|
||||||
Loading…
x
Reference in New Issue
Block a user