Fixed broken threads for love
This commit is contained in:
parent
0994ee2d2a
commit
ef9267d8fc
57
init.lua
57
init.lua
@ -140,23 +140,7 @@ end
|
||||
function multi.ForEach(tab,func)
|
||||
for i=1,#tab do func(tab[i]) 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 ignoreconn = true
|
||||
function multi:newConnection(protect, func, kill)
|
||||
@ -901,23 +885,18 @@ end
|
||||
local tasks = {}
|
||||
local _tasks = 0
|
||||
|
||||
local function _task_handler()
|
||||
local function _task_handler(self, func)
|
||||
tasks[#tasks + 1] = func
|
||||
_tasks = _tasks + 1
|
||||
end
|
||||
|
||||
function multi:newTask(func)
|
||||
thread:newThread("Task Handler",function()
|
||||
while true do
|
||||
thread.hold(function()
|
||||
return _tasks > 0
|
||||
end)
|
||||
multi:newLoop(function(loop)
|
||||
for i=1,_tasks do
|
||||
tasks[i]()
|
||||
end
|
||||
_tasks = 0
|
||||
end
|
||||
end)
|
||||
end):setName("Task Handler")
|
||||
-- Re bind this method to use the one that doesn't init a thread!
|
||||
multi.newTask = _task_handler
|
||||
tasks[#tasks + 1] = func
|
||||
@ -989,7 +968,7 @@ function multi:newProcessor(name, nothread)
|
||||
c.startme = {}
|
||||
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
|
||||
c.process = self:newLoop(function()
|
||||
@ -1366,9 +1345,6 @@ function multi.setEnv(func,env)
|
||||
return chunk
|
||||
end
|
||||
|
||||
local threads = {}
|
||||
local startme = {}
|
||||
local startme_len = 0
|
||||
function thread:newThread(name, func, ...)
|
||||
multi.OnLoad:Fire() -- This was done incase a threaded function was called before mainloop/uManager was called
|
||||
local func = func or name
|
||||
@ -1376,7 +1352,6 @@ function thread:newThread(name,func,...)
|
||||
name = name or multi.randomString(16)
|
||||
end
|
||||
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.startArgs = {...}
|
||||
c.ref={}
|
||||
@ -1443,17 +1418,22 @@ function thread:newThread(name,func,...)
|
||||
end
|
||||
|
||||
c.Destroy = c.Kill
|
||||
|
||||
if thread.isThread() then
|
||||
multi:newLoop(function(loop)
|
||||
if self.Type == "process" then
|
||||
multi.print("Creating thread (" .. self.Name .."):", name)
|
||||
table.insert(self.startme, c)
|
||||
else
|
||||
multi.print("Creating thread (Global_Thread_Manager):", name)
|
||||
if type(name) == "function" then
|
||||
multi.print(debug.traceback())
|
||||
end
|
||||
table.insert(threadManager.startme, c)
|
||||
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
|
||||
threadid = threadid + 1
|
||||
@ -1631,15 +1611,16 @@ co_status = {
|
||||
end,
|
||||
}
|
||||
|
||||
function multi:createHandler(threads,startme)
|
||||
return coroutine.wrap(function(self)
|
||||
function multi:createHandler()
|
||||
local threads, startme = self.threads, self.startme
|
||||
return coroutine.wrap(function()
|
||||
local temp_start
|
||||
while true do
|
||||
for start = #startme, 1, -1 do
|
||||
temp_start = startme[start]
|
||||
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))
|
||||
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)
|
||||
yield()
|
||||
end
|
||||
|
||||
@ -25,7 +25,7 @@ require("love.timer")
|
||||
require("love.system")
|
||||
require("love.data")
|
||||
require("love.thread")
|
||||
local multi, thread = require("multi").init()
|
||||
local multi, thread = require("multi"):init()
|
||||
local threads = {}
|
||||
|
||||
function threads.loadDump(d)
|
||||
@ -180,21 +180,12 @@ function threads.getConsole()
|
||||
end
|
||||
|
||||
if not ISTHREAD then
|
||||
local clock = os.clock
|
||||
local lastproc = clock()
|
||||
local queue = love.thread.getChannel("__CONSOLE__")
|
||||
thread:newThread("consoleManager",function()
|
||||
while true do
|
||||
thread.yield()
|
||||
multi:newLoop(function(loop)
|
||||
dat = queue:pop()
|
||||
if dat then
|
||||
lastproc = clock()
|
||||
print(unpack(dat))
|
||||
end
|
||||
if clock()-lastproc>2 then
|
||||
thread.sleep(.1)
|
||||
end
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user