Working on 16.0.0 #53
57
init.lua
57
init.lua
@ -140,23 +140,7 @@ end
|
|||||||
function multi.ForEach(tab,func)
|
function multi.ForEach(tab,func)
|
||||||
for i=1,#tab do func(tab[i]) end
|
for i=1,#tab do func(tab[i]) end
|
||||||
end
|
end
|
||||||
local CRef = {
|
|
||||||
Fire = function() end
|
|
||||||
}
|
|
||||||
|
|
||||||
--[[
|
|
||||||
cn(function(...)
|
|
||||||
local data = pack(obj1(...))
|
|
||||||
local len = #data
|
|
||||||
if len ~= 0 then
|
|
||||||
if data[1] == true then
|
|
||||||
obj2:Fire(...)
|
|
||||||
else
|
|
||||||
obj2:Fire(unpack(data))
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
]]
|
|
||||||
local optimization_stats = {}
|
local optimization_stats = {}
|
||||||
local ignoreconn = true
|
local ignoreconn = true
|
||||||
function multi:newConnection(protect, func, kill)
|
function multi:newConnection(protect, func, kill)
|
||||||
@ -901,23 +885,18 @@ end
|
|||||||
local tasks = {}
|
local tasks = {}
|
||||||
local _tasks = 0
|
local _tasks = 0
|
||||||
|
|
||||||
local function _task_handler()
|
local function _task_handler(self, func)
|
||||||
tasks[#tasks + 1] = func
|
tasks[#tasks + 1] = func
|
||||||
_tasks = _tasks + 1
|
_tasks = _tasks + 1
|
||||||
end
|
end
|
||||||
|
|
||||||
function multi:newTask(func)
|
function multi:newTask(func)
|
||||||
thread:newThread("Task Handler",function()
|
multi:newLoop(function(loop)
|
||||||
while true do
|
|
||||||
thread.hold(function()
|
|
||||||
return _tasks > 0
|
|
||||||
end)
|
|
||||||
for i=1,_tasks do
|
for i=1,_tasks do
|
||||||
tasks[i]()
|
tasks[i]()
|
||||||
end
|
end
|
||||||
_tasks = 0
|
_tasks = 0
|
||||||
end
|
end):setName("Task Handler")
|
||||||
end)
|
|
||||||
-- Re bind this method to use the one that doesn't init a thread!
|
-- Re bind this method to use the one that doesn't init a thread!
|
||||||
multi.newTask = _task_handler
|
multi.newTask = _task_handler
|
||||||
tasks[#tasks + 1] = func
|
tasks[#tasks + 1] = func
|
||||||
@ -989,7 +968,7 @@ function multi:newProcessor(name, nothread)
|
|||||||
c.startme = {}
|
c.startme = {}
|
||||||
c.parent = self
|
c.parent = self
|
||||||
|
|
||||||
local handler = c:createHandler(c.threads, c.startme)
|
local handler = c:createHandler(c)
|
||||||
|
|
||||||
if not nothread then -- Don't create a loop if we are triggering this manually
|
if not nothread then -- Don't create a loop if we are triggering this manually
|
||||||
c.process = self:newLoop(function()
|
c.process = self:newLoop(function()
|
||||||
@ -1366,9 +1345,6 @@ function multi.setEnv(func,env)
|
|||||||
return chunk
|
return chunk
|
||||||
end
|
end
|
||||||
|
|
||||||
local threads = {}
|
|
||||||
local startme = {}
|
|
||||||
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
|
||||||
@ -1376,7 +1352,6 @@ function thread:newThread(name,func,...)
|
|||||||
name = name or multi.randomString(16)
|
name = name or multi.randomString(16)
|
||||||
end
|
end
|
||||||
local c={nil,nil,nil,nil,nil,nil,nil}
|
local c={nil,nil,nil,nil,nil,nil,nil}
|
||||||
local env = {self=c}
|
|
||||||
c.TempRets = {nil,nil,nil,nil,nil,nil,nil,nil,nil,nil}
|
c.TempRets = {nil,nil,nil,nil,nil,nil,nil,nil,nil,nil}
|
||||||
c.startArgs = {...}
|
c.startArgs = {...}
|
||||||
c.ref={}
|
c.ref={}
|
||||||
@ -1443,17 +1418,22 @@ function thread:newThread(name,func,...)
|
|||||||
end
|
end
|
||||||
|
|
||||||
c.Destroy = c.Kill
|
c.Destroy = c.Kill
|
||||||
|
if thread.isThread() then
|
||||||
|
multi:newLoop(function(loop)
|
||||||
if self.Type == "process" then
|
if self.Type == "process" then
|
||||||
multi.print("Creating thread (" .. self.Name .."):", name)
|
|
||||||
table.insert(self.startme, c)
|
table.insert(self.startme, c)
|
||||||
else
|
else
|
||||||
multi.print("Creating thread (Global_Thread_Manager):", name)
|
|
||||||
if type(name) == "function" then
|
|
||||||
multi.print(debug.traceback())
|
|
||||||
end
|
|
||||||
table.insert(threadManager.startme, c)
|
table.insert(threadManager.startme, c)
|
||||||
end
|
end
|
||||||
|
loop:Break()
|
||||||
|
end)
|
||||||
|
else
|
||||||
|
if self.Type == "process" then
|
||||||
|
table.insert(self.startme, c)
|
||||||
|
else
|
||||||
|
table.insert(threadManager.startme, c)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
globalThreads[c] = multi
|
globalThreads[c] = multi
|
||||||
threadid = threadid + 1
|
threadid = threadid + 1
|
||||||
@ -1631,15 +1611,16 @@ co_status = {
|
|||||||
end,
|
end,
|
||||||
}
|
}
|
||||||
|
|
||||||
function multi:createHandler(threads,startme)
|
function multi:createHandler()
|
||||||
return coroutine.wrap(function(self)
|
local threads, startme = self.threads, self.startme
|
||||||
|
return coroutine.wrap(function()
|
||||||
local temp_start
|
local temp_start
|
||||||
while true do
|
while true do
|
||||||
for start = #startme, 1, -1 do
|
for start = #startme, 1, -1 do
|
||||||
temp_start = startme[start]
|
temp_start = startme[start]
|
||||||
table.remove(startme)
|
table.remove(startme)
|
||||||
_, ret, r1, r2, r3, r4, r5, r6, r7, r8, r9, r10, r11, r12, r13, r14, r15, r16 = resume(temp_start.thread, unpack(temp_start.startArgs))
|
_, ret, r1, r2, r3, r4, r5, r6, r7, r8, r9, r10, r11, r12, r13, r14, r15, r16 = resume(temp_start.thread, unpack(temp_start.startArgs))
|
||||||
co_status[status(temp_start.thread)](temp_start.thread,temp_start,t_none,nil,threads) -- Make sure there was no error
|
co_status[status(temp_start.thread)](temp_start.thread, temp_start, t_none, nil, threads)
|
||||||
table.insert(threads, temp_start)
|
table.insert(threads, temp_start)
|
||||||
yield()
|
yield()
|
||||||
end
|
end
|
||||||
|
|||||||
@ -25,7 +25,7 @@ require("love.timer")
|
|||||||
require("love.system")
|
require("love.system")
|
||||||
require("love.data")
|
require("love.data")
|
||||||
require("love.thread")
|
require("love.thread")
|
||||||
local multi, thread = require("multi").init()
|
local multi, thread = require("multi"):init()
|
||||||
local threads = {}
|
local threads = {}
|
||||||
|
|
||||||
function threads.loadDump(d)
|
function threads.loadDump(d)
|
||||||
@ -180,21 +180,12 @@ function threads.getConsole()
|
|||||||
end
|
end
|
||||||
|
|
||||||
if not ISTHREAD then
|
if not ISTHREAD then
|
||||||
local clock = os.clock
|
|
||||||
local lastproc = clock()
|
|
||||||
local queue = love.thread.getChannel("__CONSOLE__")
|
local queue = love.thread.getChannel("__CONSOLE__")
|
||||||
thread:newThread("consoleManager",function()
|
multi:newLoop(function(loop)
|
||||||
while true do
|
|
||||||
thread.yield()
|
|
||||||
dat = queue:pop()
|
dat = queue:pop()
|
||||||
if dat then
|
if dat then
|
||||||
lastproc = clock()
|
|
||||||
print(unpack(dat))
|
print(unpack(dat))
|
||||||
end
|
end
|
||||||
if clock()-lastproc>2 then
|
|
||||||
thread.sleep(.1)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user