mirror of
https://github.com/rayaman/multi.git
synced 2026-09-05 07:27:35 -04:00
Testing actions, fixing bugs with lanes
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
local multi, thread = require("multi"):init{error=true}
|
||||
multi.error("Currntly not supported!")
|
||||
os.exit()
|
||||
local effil = require("effil")
|
||||
|
||||
-- I like some of the things that this library offers.
|
||||
-- Current limitations prevent me from being able to use effil,
|
||||
-- but I might fork and work on it myself.
|
||||
|
||||
-- Configs
|
||||
effil.allow_table_upvalues(false)
|
||||
|
||||
local GLOBAL,THREAD = require("multi.integration.effilManager.threads").init()
|
||||
local count = 1
|
||||
local started = false
|
||||
local livingThreads = {}
|
||||
|
||||
function multi:newSystemThread(name, func, ...)
|
||||
local name = name or multi.randomString(16)
|
||||
local rand = math.random(1, 10000000)
|
||||
c = {}
|
||||
c.name = name
|
||||
c.Name = name
|
||||
c.Id = count
|
||||
end
|
||||
|
||||
function THREAD:newFunction(func, holdme)
|
||||
return thread:newFunctionBase(function(...)
|
||||
return multi:newSystemThread("TempSystemThread",func,...)
|
||||
end, holdme, multi.SFUNCTION)()
|
||||
end
|
||||
|
||||
THREAD.newSystemThread = function(...)
|
||||
multi:newSystemThread(...)
|
||||
end
|
||||
|
||||
multi.print("Integrated Effil Threading!")
|
||||
multi.integration = {} -- for module creators
|
||||
multi.integration.GLOBAL = GLOBAL
|
||||
multi.integration.THREAD = THREAD
|
||||
require("multi.integration.effilManager.extensions")
|
||||
return {
|
||||
init = function()
|
||||
return GLOBAL, THREAD
|
||||
end
|
||||
}
|
||||
@@ -34,6 +34,7 @@ function multi:newSystemThreadedQueue(name)
|
||||
local c = {}
|
||||
c.Name = name
|
||||
c.linda = lanes.linda()
|
||||
c.Type = multi.SQUEUE
|
||||
|
||||
function c:push(v)
|
||||
self.linda:send("Q", v)
|
||||
@@ -57,6 +58,8 @@ function multi:newSystemThreadedQueue(name)
|
||||
GLOBAL[name] = c
|
||||
end
|
||||
|
||||
self:create(c)
|
||||
|
||||
return c
|
||||
end
|
||||
|
||||
@@ -65,6 +68,7 @@ function multi:newSystemThreadedTable(name)
|
||||
local c = {}
|
||||
c.link = lanes.linda()
|
||||
c.Name = name
|
||||
c.Type = multi.STABLE
|
||||
|
||||
function c:init()
|
||||
return self
|
||||
@@ -85,12 +89,15 @@ function multi:newSystemThreadedTable(name)
|
||||
GLOBAL[name] = c
|
||||
end
|
||||
|
||||
self:create(c)
|
||||
|
||||
return c
|
||||
end
|
||||
|
||||
function multi:newSystemThreadedJobQueue(n)
|
||||
local c = {}
|
||||
c.cores = n or THREAD.getCores()*2
|
||||
c.Type = multi.SJOBQUEUE
|
||||
c.OnJobCompleted = multi:newConnection()
|
||||
local funcs = multi:newSystemThreadedTable():init()
|
||||
local queueJob = multi:newSystemThreadedQueue():init()
|
||||
@@ -133,7 +140,6 @@ function multi:newSystemThreadedJobQueue(n)
|
||||
link = c.OnJobCompleted(function(jid,...)
|
||||
if id==jid then
|
||||
rets = multi.pack(...)
|
||||
c.OnJobCompleted:Unconnect(link)
|
||||
end
|
||||
end)
|
||||
return thread.hold(function()
|
||||
@@ -207,12 +213,16 @@ function multi:newSystemThreadedJobQueue(n)
|
||||
multi:mainloop()
|
||||
end,i).OnError(multi.error)
|
||||
end
|
||||
|
||||
self:create(c)
|
||||
|
||||
return c
|
||||
end
|
||||
|
||||
function multi:newSystemThreadedConnection(name)
|
||||
local name = name or multi.randomString(16)
|
||||
local c = {}
|
||||
c.Type = multi.SCONNECTION
|
||||
c.CONN = 0x00
|
||||
c.TRIG = 0x01
|
||||
c.PING = 0x02
|
||||
@@ -348,6 +358,8 @@ function multi:newSystemThreadedConnection(name)
|
||||
GLOBAL[name] = c
|
||||
end
|
||||
|
||||
self:create(c)
|
||||
|
||||
return c
|
||||
end
|
||||
require("multi.integration.sharedExtensions")
|
||||
@@ -32,9 +32,7 @@ if multi.integration then -- This allows us to call the lanes manager from suppo
|
||||
}
|
||||
end
|
||||
-- Step 1 get lanes
|
||||
lanes = require("lanes").configure{
|
||||
nb_keepers = 4,
|
||||
}
|
||||
lanes = require("lanes").configure()
|
||||
multi.SystemThreads = {}
|
||||
multi.isMainThread = true
|
||||
|
||||
@@ -63,7 +61,7 @@ local livingThreads = {}
|
||||
function THREAD:newFunction(func, holdme)
|
||||
return thread:newFunctionBase(function(...)
|
||||
return multi:newSystemThread("TempSystemThread",func,...)
|
||||
end, holdme)()
|
||||
end, holdme, multi.SFUNCTION)()
|
||||
end
|
||||
|
||||
function multi:newSystemThread(name, func, ...)
|
||||
@@ -143,7 +141,9 @@ function multi:newSystemThread(name, func, ...)
|
||||
return c
|
||||
end
|
||||
|
||||
THREAD.newSystemThread = multi.newSystemThread
|
||||
THREAD.newSystemThread = function(...)
|
||||
multi:newSystemThread(...)
|
||||
end
|
||||
|
||||
function multi.InitSystemThreadErrorHandler()
|
||||
if started == true then
|
||||
|
||||
@@ -35,6 +35,7 @@ function multi:newSystemThreadedQueue(name)
|
||||
local name = name or multi.randomString(16)
|
||||
local c = {}
|
||||
c.Name = name
|
||||
c.Type = multi.SQUEUE
|
||||
local fRef = {"func",nil}
|
||||
function c:init()
|
||||
local q = {}
|
||||
@@ -66,33 +67,49 @@ function multi:newSystemThreadedQueue(name)
|
||||
end
|
||||
return q
|
||||
end
|
||||
|
||||
THREAD.package(name,c)
|
||||
|
||||
self:create(c)
|
||||
|
||||
return c
|
||||
end
|
||||
|
||||
function multi:newSystemThreadedTable(name)
|
||||
local name = name or multi.randomString(16)
|
||||
local c = {}
|
||||
|
||||
local c = {}
|
||||
|
||||
c.Name = name
|
||||
c.Type = multi.STABLE
|
||||
|
||||
function c:init()
|
||||
return THREAD.createTable(self.Name)
|
||||
end
|
||||
|
||||
THREAD.package(name,c)
|
||||
|
||||
self:create(c)
|
||||
|
||||
return c
|
||||
end
|
||||
|
||||
local jqc = 1
|
||||
function multi:newSystemThreadedJobQueue(n)
|
||||
local c = {}
|
||||
|
||||
c.cores = n or THREAD.getCores()
|
||||
c.registerQueue = {}
|
||||
c.Type = multi.SJOBQUEUE
|
||||
c.funcs = THREAD.createStaticTable("__JobQueue_"..jqc.."_table")
|
||||
c.queue = love.thread.getChannel("__JobQueue_"..jqc.."_queue")
|
||||
c.queueReturn = love.thread.getChannel("__JobQueue_"..jqc.."_queueReturn")
|
||||
c.queueAll = love.thread.getChannel("__JobQueue_"..jqc.."_queueAll")
|
||||
c.id = 0
|
||||
c.OnJobCompleted = multi:newConnection()
|
||||
|
||||
local allfunc = 0
|
||||
|
||||
function c:doToAll(func)
|
||||
local f = THREAD.dump(func)
|
||||
for i = 1, self.cores do
|
||||
@@ -211,13 +228,20 @@ function multi:newSystemThreadedJobQueue(n)
|
||||
multi:mainloop()
|
||||
end,jqc)
|
||||
end
|
||||
|
||||
jqc = jqc + 1
|
||||
|
||||
self:create(c)
|
||||
|
||||
return c
|
||||
end
|
||||
|
||||
function multi:newSystemThreadedConnection(name)
|
||||
local name = name or multi.randomString(16)
|
||||
|
||||
local c = {}
|
||||
|
||||
c.Type = multi.SCONNECTION
|
||||
c.CONN = 0x00
|
||||
c.TRIG = 0x01
|
||||
c.PING = 0x02
|
||||
@@ -284,9 +308,11 @@ function multi:newSystemThreadedConnection(name)
|
||||
end
|
||||
return r
|
||||
end
|
||||
|
||||
c.CID = THREAD_ID
|
||||
c.Name = name
|
||||
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.
|
||||
|
||||
-- Locals will only live in the thread that creates the original object
|
||||
local ping
|
||||
local pong = function(link, links)
|
||||
@@ -317,7 +343,7 @@ function multi:newSystemThreadedConnection(name)
|
||||
thread.sleep(3)
|
||||
|
||||
ping:Resume()
|
||||
end,false)
|
||||
end, false)
|
||||
|
||||
local function fire(...)
|
||||
for _, link in pairs(c.links) do
|
||||
@@ -351,5 +377,7 @@ function multi:newSystemThreadedConnection(name)
|
||||
|
||||
THREAD.package(name,c)
|
||||
|
||||
self:create(c)
|
||||
|
||||
return c
|
||||
end
|
||||
@@ -116,10 +116,12 @@ end
|
||||
function THREAD:newFunction(func, holdme)
|
||||
return thread:newFunctionBase(function(...)
|
||||
return multi:newSystemThread("SystemThreaded Function Handler", func, ...)
|
||||
end, holdme)()
|
||||
end, holdme, multi.SFUNCTION)()
|
||||
end
|
||||
|
||||
THREAD.newSystemThread = multi.newSystemThread
|
||||
THREAD.newSystemThread = function(...)
|
||||
multi:newSystemThread(...)
|
||||
end
|
||||
|
||||
function love.threaderror(thread, errorstr)
|
||||
multi.print("Thread error!\n" .. errorstr)
|
||||
|
||||
@@ -213,6 +213,7 @@ function multi:newSystemThreadedProcessor(cores)
|
||||
|
||||
setmetatable(c,{__index = multi})
|
||||
|
||||
c.Type = multi.SPROCESS
|
||||
c.threads = {}
|
||||
c.cores = cores or 8
|
||||
c.Name = name
|
||||
|
||||
Reference in New Issue
Block a user