* Fixed spelling, started ideaing for 16.0.0 * Updated files * Updated readme * Updated version * Concat conns now properly transfer events * Testing types * Connections can be % with functions * Updated connections * Fixed issue with double thread activations (Looking for another solution) * Working on issue with love threaded functions not waiting when in a thread * Working on issue where threads created in threads don't work * Fixed broken threads for love * Fixed some issues with threads * removed test * Updated changes.md * Plan on testing parity between the threading modules * Writing tests for system threading * Added test cases for threading, fixed issues. Todo test love2d * Fixed love2d to succeed with tests * All tests working * Updated files for testing * Modified tests to make it more seamless * removed extra __cores in lanes/pseudo * Working on new priority scheme * Working on priority management * Working on custom prioritySchemes * Fixed issues with missing code * Threaded processors * THREAD.exposeENV(), thread:newProcessor() * Typo in changes.md * Fixed typo in pseudoManager * fixing * Trying to fix exposeENV with pseudoThreading * Changes to threads * updated changes.md * Working on systemthreadedprocess, and experimental newProxy for threading * newProxy and STP work * newProxy implemented * Proxies work with connections now :D * Added tstep to STP, updated changes.md * thread.hold(proxy.conn) * Clean up connection events when holding, working on scheduling tasks/threads to system threaded processors * Getting loads of processors implemented * Finished getLoad(type) * Fixed some bugs * Added an easy way to share a table, found some limitations with lanes threading. * THREAD_NAME set for main thread, connections break the rules for proxies * Testing * Really close to portable proxies, currently extreamly unstable! * Debugging what is going on... * Fixed critical issue with coroutine based threads * Removed extra bloat, proxies are portable now! * Started work on the debugManager * Testing actions, fixing bugs with lanes * Testing... * fixing actions * typo fixed * Throw an error when things break * fixing stuff * Fixed issue with errors not going through * Removed system threaded connections, soon to be replaced by proxies * Testing love2d tests * Test love2d * Use later love-build * Use ubuntu for build * Fixed path * Use appimage * use sudo * No window for love2d * Fixed love2d tests * Testing love2d * Use workspace * Moved other tests while testing * actually pull the repo * packagepath set * Fixed pull * Update multi * Removed link * Edited symlink * Added timeout to build * Rewriting loveManager, too much outdated code * Still implementing new love2d threading code * Rewriting love2d threading binding * Working on adding a Hold method to all objects. Will document how they all work when done. * jobqueues having isues with stp * new pack/unpack for tables, current issue is things being turned into strings * Fixed packing of values into threads, need to fix system proxies and system threaded processors * testing... * Not hard crashing when error is encountered * Should now push non 0 exit codes * Push error when an error happens * Closer to getting things working... * Working on new type system, planning out debugmanager * Fixed error code issue * Test for 5.1 * Planning out debugManager * Some work on the debug manager, proxies working on lanes, todo get pseudo manager and love2d working * Working on getting pseudoThreading tests to work * Added function / connection * Added boost method * Document new features to conns, todo fix newTask * Fixed newTask() * Updated changes.md and fixed some bugs * Added thread.defer(func) * Fixed tests on lanes and pseudo threading, todo fix love2d threading * Fixed paths * Working on paths * Testing paths * Add test for rockspec * Fixed issues * Fixed typo * Added test for defer * Threading working in love2d * Fixed, conf * lanes uses a threaded function like waitfor function * Cleaned up changes.md * added priorityManager to rockspec
244 lines
5.8 KiB
Lua
244 lines
5.8 KiB
Lua
if not ISTHREAD then
|
|
multi, thread = require("multi").init()
|
|
GLOBAL = multi.integration.GLOBAL
|
|
THREAD = multi.integration.THREAD
|
|
end
|
|
|
|
function multi:newSystemThreadedQueue(name)
|
|
local name = name or multi.randomString(16)
|
|
|
|
local c = {}
|
|
|
|
c.Name = name
|
|
c.Type = multi.registerType("s_queue")
|
|
c.chan = love.thread.getChannel(name)
|
|
|
|
function c:push(dat)
|
|
self.chan:push(THREAD.packValue(dat))
|
|
end
|
|
|
|
function c:pop()
|
|
return THREAD.unpackValue(self.chan:pop())
|
|
end
|
|
|
|
function c:peek()
|
|
return THREAD.unpackValue(self.chan:peek())
|
|
end
|
|
|
|
function c:init()
|
|
self.chan = love.thread.getChannel(self.Name)
|
|
return self
|
|
end
|
|
|
|
function c:Hold(opt)
|
|
local multi, thread = require("multi"):init()
|
|
if opt.peek then
|
|
return thread.hold(function()
|
|
return self:peek()
|
|
end)
|
|
else
|
|
return thread.hold(function()
|
|
return self:pop()
|
|
end)
|
|
end
|
|
end
|
|
|
|
GLOBAL[name] = c
|
|
|
|
self:create(c)
|
|
|
|
return c
|
|
end
|
|
|
|
function multi:newSystemThreadedTable(name)
|
|
local name = name or multi.randomString(16)
|
|
|
|
local c = {}
|
|
|
|
c.Name = name
|
|
c.Type = multi.registerType("s_table")
|
|
c.tab = THREAD.createTable(name)
|
|
|
|
function c:init()
|
|
self.tab = THREAD.createTable(self.Name)
|
|
setmetatable(self,{
|
|
__index = function(t, k)
|
|
return self.tab[k]
|
|
end,
|
|
__newindex = function(t,k,v)
|
|
self.tab[k] = v
|
|
end
|
|
})
|
|
return self
|
|
end
|
|
|
|
c.__init = c.init
|
|
|
|
function c:Hold(opt)
|
|
local multi, thread = require("multi"):init()
|
|
if opt.key then
|
|
return thread.hold(function()
|
|
return self.tab[opt.key]
|
|
end)
|
|
else
|
|
multi.error("Must provide a key to check opt.key = 'key'")
|
|
end
|
|
end
|
|
|
|
setmetatable(c,{
|
|
__index = function(t, k)
|
|
return c.tab[k]
|
|
end,
|
|
__newindex = function(t,k,v)
|
|
c.tab[k] = v
|
|
end
|
|
})
|
|
|
|
GLOBAL[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.registerType("s_jobqueue")
|
|
c.funcs = THREAD.createTable("__JobQueue_"..jqc.."_table")
|
|
c.queue = multi:newSystemThreadedQueue("__JobQueue_"..jqc.."_queue")
|
|
c.queueReturn = multi:newSystemThreadedQueue("__JobQueue_"..jqc.."_queueReturn")
|
|
c.queueAll = multi:newSystemThreadedQueue("__JobQueue_"..jqc.."_queueAll")
|
|
c.id = 0
|
|
c.OnJobCompleted = multi:newConnection()
|
|
|
|
local allfunc = 0
|
|
|
|
function c:doToAll(func)
|
|
for i = 1, self.cores do
|
|
self.queueAll:push({allfunc, func})
|
|
end
|
|
allfunc = allfunc + 1
|
|
end
|
|
function c:registerFunction(name, func)
|
|
if self.funcs[name] then
|
|
multi.error("A function by the name "..name.." has already been registered!")
|
|
end
|
|
self.funcs[name] = func
|
|
end
|
|
function c:pushJob(name,...)
|
|
self.id = self.id + 1
|
|
self.queue:push{name,self.id,...}
|
|
return self.id
|
|
end
|
|
function c:isEmpty()
|
|
return queueJob:peek()==nil
|
|
end
|
|
local nFunc = 0
|
|
function c:newFunction(name,func,holup) -- This registers with the queue
|
|
if type(name)=="function" then
|
|
holup = func
|
|
func = name
|
|
name = "JQ_Function_"..nFunc
|
|
end
|
|
nFunc = nFunc + 1
|
|
c:registerFunction(name,func)
|
|
return thread:newFunction(function(...)
|
|
local id = c:pushJob(name,...)
|
|
local link
|
|
local rets
|
|
link = c.OnJobCompleted(function(jid,...)
|
|
if id==jid then
|
|
rets = multi.pack(...)
|
|
end
|
|
end)
|
|
return thread.hold(function()
|
|
if rets then
|
|
return multi.unpack(rets) or multi.NIL
|
|
end
|
|
end)
|
|
end,holup),name
|
|
end
|
|
thread:newThread("jobManager",function()
|
|
while true do
|
|
thread.yield()
|
|
local dat = c.queueReturn:pop()
|
|
if dat then
|
|
c.OnJobCompleted:Fire(multi.unpack(dat))
|
|
end
|
|
end
|
|
end)
|
|
for i=1,c.cores do
|
|
multi:newSystemThread("JobQueue_"..jqc.."_worker_"..i,function(jqc)
|
|
local multi, thread = require("multi"):init()
|
|
require("love.timer")
|
|
love.timer.sleep(1)
|
|
local clock = os.clock
|
|
local funcs = THREAD.createTable("__JobQueue_"..jqc.."_table")
|
|
local queue = THREAD.waitFor("__JobQueue_"..jqc.."_queue")
|
|
local queueReturn = THREAD.waitFor("__JobQueue_"..jqc.."_queueReturn")
|
|
local lastProc = clock()
|
|
local queueAll = THREAD.waitFor("__JobQueue_"..jqc.."_queueAll")
|
|
local registry = {}
|
|
_G["__QR"] = queueReturn
|
|
setmetatable(_G,{__index = funcs})
|
|
thread:newThread("startUp",function()
|
|
while true do
|
|
thread.yield()
|
|
local all = queueAll:peek()
|
|
if all and not registry[all[1]] then
|
|
lastProc = os.clock()
|
|
queueAll:pop()[2]()
|
|
end
|
|
end
|
|
end)
|
|
thread:newThread("runner",function()
|
|
thread.sleep(.1)
|
|
while true do
|
|
thread.yield()
|
|
local all = queueAll:peek()
|
|
if all and not registry[all[1]] then
|
|
lastProc = os.clock()
|
|
queueAll:pop()[2]()
|
|
end
|
|
local dat = thread.hold(queue)
|
|
if dat then
|
|
multi:newThread("Test",function()
|
|
lastProc = os.clock()
|
|
local name = table.remove(dat,1)
|
|
local id = table.remove(dat,1)
|
|
local tab = {funcs[name](multi.unpack(dat))}
|
|
table.insert(tab,1,id)
|
|
--local test = queueReturn.push
|
|
queueReturn:push(tab)
|
|
end)
|
|
end
|
|
end
|
|
end)
|
|
thread:newThread("Idler",function()
|
|
while true do
|
|
thread.yield()
|
|
if clock()-lastProc> 2 then
|
|
THREAD.sleep(.05)
|
|
else
|
|
THREAD.sleep(.001)
|
|
end
|
|
end
|
|
end)
|
|
multi:mainloop()
|
|
end,jqc)
|
|
end
|
|
|
|
function c:Hold(opt)
|
|
return thread.hold(self.OnJobCompleted)
|
|
end
|
|
|
|
jqc = jqc + 1
|
|
|
|
self:create(c)
|
|
|
|
return c
|
|
end |