Threading working in love2d

This commit is contained in:
2024-02-24 23:05:05 -05:00
parent 42b4e0fcf4
commit e3ac0951ab
18 changed files with 210 additions and 999 deletions
+5 -14
View File
@@ -85,7 +85,8 @@ function multi:newSystemThread(name, func, ...)
THREAD_ID = count,
THREAD = THREAD,
GLOBAL = GLOBAL,
_Console = __ConsoleLinda
_Console = __ConsoleLinda,
_DEFER = {}
}
if GLOBAL["__env"] then
for i,v in pairs(GLOBAL["__env"]) do
@@ -97,26 +98,16 @@ function multi:newSystemThread(name, func, ...)
globals = globe,
priority = c.priority
},function(...)
local profi
if multi_settings.debug then
profi = require("proFI")
profi:start()
end
multi, thread = require("multi"):init(multi_settings)
require("multi.integration.lanesManager.extensions")
require("multi.integration.sharedExtensions")
local has_error = true
returns = {pcall(func, ...)}
return_linda:set("returns", returns)
has_error = false
if profi then
multi.OnExit(function(...)
profi:stop()
profi:writeReport("Profiling Report [".. THREAD_NAME .."].txt")
end)
for i,v in pairs(_DEFER) do
pcall(v)
end
has_error = false
end)(...)
count = count + 1
function c:getName()
+5 -7
View File
@@ -88,6 +88,10 @@ local function INIT(__GlobalLinda, __SleepingLinda, __StatusLinda, __Console)
function THREAD.kill() -- trigger the lane destruction
error("Thread was killed!\1")
end
function THREAD.sync()
-- Maybe do something...
end
function THREAD.pushStatus(...)
local args = multi.pack(...)
@@ -138,13 +142,7 @@ local function INIT(__GlobalLinda, __SleepingLinda, __StatusLinda, __Console)
end
function THREAD.defer(func)
local m = {onexit = function() func() end}
if _VERSION >= "Lua 5.2" then
setmetatable(m, {__gc = m.onexit})
else
m.sentinel = newproxy(true)
getmetatable(m.sentinel).__gc = m.onexit
end
table.insert(_DEFER, func)
end
return GLOBAL, THREAD