Some changes to extensions, working on STC
This commit is contained in:
parent
bb7fab0857
commit
772095431f
@ -21,6 +21,8 @@ Added
|
|||||||
|
|
||||||
Loops through the table and calls callback_function with each element of the array.
|
Loops through the table and calls callback_function with each element of the array.
|
||||||
|
|
||||||
|
- If a name is not supplied when creating threads; a name is randomly generated. Unless sending through an established channel/queue you might not be able to easily init the object.
|
||||||
|
|
||||||
Changed
|
Changed
|
||||||
---
|
---
|
||||||
- `Connection:[connect, hasConnections, getConnection]` changed to be `Connection:[Connect, HasConnections, getConnections]`. This was done in an attempt to follow a consistent naming scheme. The old methods still will work to prevent old code breaking.
|
- `Connection:[connect, hasConnections, getConnection]` changed to be `Connection:[Connect, HasConnections, getConnections]`. This was done in an attempt to follow a consistent naming scheme. The old methods still will work to prevent old code breaking.
|
||||||
@ -32,7 +34,7 @@ Removed
|
|||||||
|
|
||||||
Fixed
|
Fixed
|
||||||
---
|
---
|
||||||
-
|
- SystemThreaded Objects variables weren't consistent.
|
||||||
|
|
||||||
ToDo
|
ToDo
|
||||||
---
|
---
|
||||||
|
|||||||
@ -1254,9 +1254,8 @@ local startme_len = 0
|
|||||||
function thread:newThread(name,func,...)
|
function thread:newThread(name,func,...)
|
||||||
multi.OnLoad:Fire() -- This was done incase a threaded function was called before mainloop/uManager was called
|
multi.OnLoad:Fire() -- This was done incase a threaded function was called before mainloop/uManager was called
|
||||||
local func = func or name
|
local func = func or name
|
||||||
|
if func == name then
|
||||||
if type(name) == "function" then
|
name = name or multi.randomString(16)
|
||||||
name = "Thread#"..threadCount
|
|
||||||
end
|
end
|
||||||
local c={nil,nil,nil,nil,nil,nil,nil}
|
local c={nil,nil,nil,nil,nil,nil,nil}
|
||||||
local env = {self=c}
|
local env = {self=c}
|
||||||
|
|||||||
@ -24,7 +24,9 @@ SOFTWARE.
|
|||||||
local multi, thread = require("multi"):init()
|
local multi, thread = require("multi"):init()
|
||||||
local GLOBAL, THREAD = multi.integration.GLOBAL,multi.integration.THREAD
|
local GLOBAL, THREAD = multi.integration.GLOBAL,multi.integration.THREAD
|
||||||
function multi:newSystemThreadedQueue(name)
|
function multi:newSystemThreadedQueue(name)
|
||||||
|
local name = name or multi.randomString(16)
|
||||||
local c = {}
|
local c = {}
|
||||||
|
c.Name = name
|
||||||
c.linda = lanes.linda()
|
c.linda = lanes.linda()
|
||||||
function c:push(v)
|
function c:push(v)
|
||||||
self.linda:send("Q", v)
|
self.linda:send("Q", v)
|
||||||
@ -43,8 +45,10 @@ function multi:newSystemThreadedQueue(name)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function multi:newSystemThreadedTable(name)
|
function multi:newSystemThreadedTable(name)
|
||||||
|
local name = name or multi.randomString(16)
|
||||||
local c = {}
|
local c = {}
|
||||||
c.link = lanes.linda()
|
c.link = lanes.linda()
|
||||||
|
c.Name = name
|
||||||
setmetatable(c,{
|
setmetatable(c,{
|
||||||
__index = function(t,k)
|
__index = function(t,k)
|
||||||
return c.link:get(k)
|
return c.link:get(k)
|
||||||
|
|||||||
@ -62,6 +62,7 @@ function THREAD:newFunction(func,holdme)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function multi:newSystemThread(name, func, ...)
|
function multi:newSystemThread(name, func, ...)
|
||||||
|
local name = name or multi.randomString(16)
|
||||||
multi.InitSystemThreadErrorHandler()
|
multi.InitSystemThreadErrorHandler()
|
||||||
local rand = math.random(1, 10000000)
|
local rand = math.random(1, 10000000)
|
||||||
local return_linda = lanes.linda()
|
local return_linda = lanes.linda()
|
||||||
|
|||||||
@ -27,6 +27,7 @@ local multi, thread = require("multi").init()
|
|||||||
GLOBAL = multi.integration.GLOBAL
|
GLOBAL = multi.integration.GLOBAL
|
||||||
THREAD = multi.integration.THREAD
|
THREAD = multi.integration.THREAD
|
||||||
function multi:newSystemThreadedQueue(name)
|
function multi:newSystemThreadedQueue(name)
|
||||||
|
local name = name or multi.randomString(16)
|
||||||
local c = {}
|
local c = {}
|
||||||
c.Name = name
|
c.Name = name
|
||||||
local fRef = {"func",nil}
|
local fRef = {"func",nil}
|
||||||
@ -64,10 +65,11 @@ function multi:newSystemThreadedQueue(name)
|
|||||||
return c
|
return c
|
||||||
end
|
end
|
||||||
function multi:newSystemThreadedTable(name)
|
function multi:newSystemThreadedTable(name)
|
||||||
|
local name = name or multi.randomString(16)
|
||||||
local c = {}
|
local c = {}
|
||||||
c.name = name
|
c.Name = name
|
||||||
function c:init()
|
function c:init()
|
||||||
return THREAD.createTable(self.name)
|
return THREAD.createTable(self.Name)
|
||||||
end
|
end
|
||||||
THREAD.package(name,c)
|
THREAD.package(name,c)
|
||||||
return c
|
return c
|
||||||
|
|||||||
@ -25,6 +25,7 @@ local multi, thread = require("multi").init()
|
|||||||
GLOBAL = multi.integration.GLOBAL
|
GLOBAL = multi.integration.GLOBAL
|
||||||
THREAD = multi.integration.THREAD
|
THREAD = multi.integration.THREAD
|
||||||
function multi:newSystemThreadedQueue(name)
|
function multi:newSystemThreadedQueue(name)
|
||||||
|
local name = name or multi.randomString(16)
|
||||||
local c = {}
|
local c = {}
|
||||||
c.Name = name
|
c.Name = name
|
||||||
local fRef = {"func",nil}
|
local fRef = {"func",nil}
|
||||||
@ -62,10 +63,11 @@ function multi:newSystemThreadedQueue(name)
|
|||||||
return c
|
return c
|
||||||
end
|
end
|
||||||
function multi:newSystemThreadedTable(name)
|
function multi:newSystemThreadedTable(name)
|
||||||
|
local name = name or multi.randomString(16)
|
||||||
local c = {}
|
local c = {}
|
||||||
c.name = name
|
c.Name = name
|
||||||
function c:init()
|
function c:init()
|
||||||
return THREAD.createTable(self.name)
|
return THREAD.createTable(self.Name)
|
||||||
end
|
end
|
||||||
THREAD.package(name,c)
|
THREAD.package(name,c)
|
||||||
return c
|
return c
|
||||||
|
|||||||
74
test.lua
74
test.lua
@ -3,59 +3,89 @@ package.cpath = "lua5.4/lib/lua/?/core.dll;"..package.cpath
|
|||||||
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 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
|
||||||
local proxy_conn = multi:newConnection(...)
|
c.proxy_conn = multi:newConnection(...)
|
||||||
|
local function remove(a, b)
|
||||||
|
local ai = {}
|
||||||
|
local r = {}
|
||||||
|
for k,v in pairs(a) do ai[v]=true end
|
||||||
|
for k,v in pairs(b) do
|
||||||
|
if ai[v]==nil then table.insert(r,a[k]) end
|
||||||
|
end
|
||||||
|
return r
|
||||||
|
end
|
||||||
local name = name or multi.randomString(16)
|
local name = name or multi.randomString(16)
|
||||||
|
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.
|
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.
|
||||||
local funcs = {}
|
local funcs = {}
|
||||||
setmetatable(c,master_conn) -- A different approach will be taken for the non main connection objects
|
setmetatable(c,master_conn) -- A different approach will be taken for the non main connection objects
|
||||||
c.subscribe = multi:newSystemThreadedQueue("Subscribe_"..name):init() -- Incoming subscriptions
|
c.subscribe = multi:newSystemThreadedQueue("SUB_STC_"..name):init() -- Incoming subscriptions
|
||||||
multi:newThread("STC_"..name,function()
|
multi:newThread("STC_SUB_MAN"..name,function()
|
||||||
|
local item
|
||||||
while true do
|
while true do
|
||||||
thread.yield()
|
thread.yield()
|
||||||
local item = c.subscribe:pop()
|
|
||||||
-- We need to check on broken connections
|
-- We need to check on broken connections
|
||||||
-- c:Ping()
|
c:Ping() -- Should return instantlly and process this in another thread
|
||||||
--
|
thread.hold(function()
|
||||||
if item ~= nil then
|
item = c.subscribe:peek()
|
||||||
connections[#connections+1] = item
|
if item ~= nil and item[1] == c.CONN then
|
||||||
multi.ForEach(funcs, function(link) -- Sync new connections
|
c.subscribe:pop()
|
||||||
item:push{c.CONN, link}
|
connections[#connections+1] = item
|
||||||
end)
|
multi.ForEach(funcs, function(link) -- Sync new connections
|
||||||
thread.skip(multi.Priority_Normal) -- Usually a bunch of threads subscribe close to the same time. Process those by ensuring that they come alive around the same time
|
item:push{c.CONN, link}
|
||||||
-- I'm using these "Constants" since they may change with other releases and this should allow these functions to adjust with them.
|
end)
|
||||||
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
|
||||||
end)
|
end)
|
||||||
function c:Ping() -- Threaded Function call, can use thread.*
|
c.Ping = thread:newFunction(function(self)
|
||||||
--
|
c.Ping:Pause() -- Don't allow this function to be called more than once
|
||||||
end
|
local pings = {}
|
||||||
|
multi.ForEach(funcs, function(link) -- Sync new connections
|
||||||
|
link:push{self.PING}
|
||||||
|
end)
|
||||||
|
thread.hold(function()
|
||||||
|
item = self.subscribe:peek()
|
||||||
|
if item ~= nil and item[1] == self.PONG then
|
||||||
|
table.insert(pings,item[2])
|
||||||
|
end
|
||||||
|
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
|
||||||
|
remove(funcs, pings)
|
||||||
|
c.Ping:Resume()
|
||||||
|
end,false)
|
||||||
function c:Fire(...)
|
function c:Fire(...)
|
||||||
--
|
master_conn:Fire(...)
|
||||||
|
multi.ForEach(funcs, function(link) -- Sync new connections
|
||||||
|
link:push{self.TRIG,{...}}
|
||||||
|
end)
|
||||||
end
|
end
|
||||||
function c:Sync(link)
|
function c:Sync(link)
|
||||||
--
|
--
|
||||||
end
|
end
|
||||||
function c:Connect(func)
|
function c:Connect(func)
|
||||||
local conn_func = func
|
local conn_func = func
|
||||||
|
self.proxy_conn(func)
|
||||||
proxy_conn(function()
|
proxy_conn(function()
|
||||||
funcs[#funcs+1] = func -- Used for syncing new connections to this connection later on
|
funcs[#funcs+1] = func -- Used for syncing new connections to this connection later on
|
||||||
multi.ForEach(c.connections, function(link)
|
multi.ForEach(self.connections, function(link)
|
||||||
link:push{CONN, func}
|
link:push{CONN, func}
|
||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
function c:init()
|
function c:init()
|
||||||
|
self.proxy_conn
|
||||||
return self
|
return self
|
||||||
end
|
end
|
||||||
GLOBAL[name or "_"] = c
|
GLOBAL[name] = c
|
||||||
return c
|
return c
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
33
test2.lua
Normal file
33
test2.lua
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
function difference(a, b)
|
||||||
|
local ai = {}
|
||||||
|
local r = {}
|
||||||
|
local rr = {}
|
||||||
|
for k,v in pairs(a) do r[k] = v; ai[v]=true end
|
||||||
|
for k,v in pairs(b) do
|
||||||
|
if ai[v]==nil then table.insert(rr,r[k]) end
|
||||||
|
end
|
||||||
|
return rr
|
||||||
|
end
|
||||||
|
function remove(a, b)
|
||||||
|
local ai = {}
|
||||||
|
local r = {}
|
||||||
|
for k,v in pairs(a) do ai[v]=true end
|
||||||
|
for k,v in pairs(b) do
|
||||||
|
if ai[v]==nil then table.insert(r,a[k]) end
|
||||||
|
end
|
||||||
|
return r
|
||||||
|
end
|
||||||
|
|
||||||
|
function printtab(tab,msg)
|
||||||
|
print(msg or "TABLE")
|
||||||
|
for i,v in pairs(tab) do
|
||||||
|
print(i, v)
|
||||||
|
end
|
||||||
|
print("")
|
||||||
|
end
|
||||||
|
|
||||||
|
local tab1 = {1,2,3,4,5}
|
||||||
|
local tab2 = {3,4,5,6,7}
|
||||||
|
tab1 = remove(tab1,tab2)
|
||||||
|
printtab(tab1, "Table 1")
|
||||||
|
printtab(tab2, "Table 2")
|
||||||
Loading…
x
Reference in New Issue
Block a user