THREAD_NAME set for main thread, connections break the rules for proxies

This commit is contained in:
2023-06-03 12:07:33 -04:00
parent 5e2ab9af3d
commit 257ed03728
7 changed files with 93 additions and 18 deletions
+3
View File
@@ -36,6 +36,9 @@ lanes = require("lanes").configure()
multi.SystemThreads = {}
multi.isMainThread = true
_G.THREAD_NAME = "MAIN_THREAD"
_G.THREAD_ID = 0
function multi:canSystemThread()
return true
end
+8 -10
View File
@@ -32,15 +32,13 @@ THREAD = require("multi.integration.loveManager.threads")
sThread = THREAD
__IMPORTS = {...}
__FUNC__=table.remove(__IMPORTS,1)
__THREADID__=table.remove(__IMPORTS,1)
__THREADNAME__=table.remove(__IMPORTS,1)
THREAD_NAME = __THREADNAME__
THREAD_ID = __THREADID__
math.randomseed(__THREADID__)
THREAD_ID=table.remove(__IMPORTS,1)
THREAD_NAME=table.remove(__IMPORTS,1)
math.randomseed(THREAD_ID)
math.random()
math.random()
math.random()
stab = THREAD.createStaticTable(__THREADNAME__ .. __THREADID__)
stab = THREAD.createStaticTable(THREAD_NAME .. THREAD_ID)
GLOBAL = THREAD.getGlobal()
if GLOBAL["__env"] then
local env = THREAD.unpackENV(GLOBAL["__env"])
@@ -60,15 +58,15 @@ stab["returns"] = {THREAD.loadDump(__FUNC__)(multi.unpack(__IMPORTS))}
local multi, thread = require("multi"):init()
local THREAD = {}
__THREADID__ = 0
__THREADNAME__ = "MainThread"
_G.THREAD_NAME = "MAIN_THREAD"
_G.THREAD_ID = 0
multi.integration = {}
local THREAD = require("multi.integration.loveManager.threads")
local GLOBAL = THREAD.getGlobal()
local THREAD_ID = 1
multi.isMainThread = true
function multi:newSystemThread(name, func, ...)
THREAD_ID = THREAD_ID + 1
local c = {}
c.name = name
c.ID = THREAD_ID
@@ -79,7 +77,7 @@ function multi:newSystemThread(name, func, ...)
c.OnError = multi:newConnection()
GLOBAL["__THREAD_" .. c.ID] = {ID = c.ID, Name = c.name, Thread = c.thread}
GLOBAL["__THREAD_COUNT"] = THREAD_ID
THREAD_ID = THREAD_ID + 1
function c:getName() return c.name end
thread:newThread(name .. "_System_Thread_Handler",function()
if name == "SystemThreaded Function Handler" then
+2
View File
@@ -42,6 +42,8 @@ local multi, thread = require("multi.compat.lovr2d"):init()
local THREAD = {}
__THREADID__ = 0
__THREADNAME__ = "MainThread"
_G.THREAD_NAME = "MAIN_THREAD"
_G.THREAD_ID = 0
multi.integration={}
multi.integration.lovr2d={}
local THREAD = require("multi.integration.lovrManager.threads")
+3
View File
@@ -35,6 +35,9 @@ multi.isMainThread = true
local activator = require("multi.integration.pseudoManager.threads")
local GLOBAL, THREAD = activator.init(thread)
_G.THREAD_NAME = "MAIN_THREAD"
_G.THREAD_ID = 0
function multi:canSystemThread() -- We are emulating system threading
return true
end
+12 -5
View File
@@ -67,7 +67,7 @@ function multi:newProxy(list)
function c:init()
local multi, thread = nil, nil
if THREAD_NAME then
if THREAD_ID>0 then
local multi, thread = require("multi"):init()
local function check()
return self.send:pop()
@@ -113,11 +113,19 @@ function multi:newProxy(list)
self.Type = multi.PROXY
for _,v in pairs(self.funcs) do
if type(v) == "table" then
-- We have a connection
v[2]:init()
self[v[1]] = v[2]
self["_"..v[1]] = v[2]
v[2].Parent = self
setmetatable(v[2],getmetatable(multi:newConnection()))
self[v[1]] = multi:newConnection()
thread:newThread(function()
while true do
self[v[1]]:Fire(thread.hold(alarm["_"..v[1]]))
end
end)
else
lastObj = self
self[v] = thread:newFunction(function(self,...)
if self == me then
me.send:push({v, true, ...})
@@ -146,8 +154,6 @@ function multi:newProxy(list)
return c
end
multi.PROXY = "proxy"
local targets = {}
local nFunc = 0
@@ -416,6 +422,7 @@ end
-- Modify thread.hold to handle proxies
local thread_ref = thread.hold
function thread.hold(n, opt)
--if type(n) == "table" then print(n.Type, n.isConnection()) end
if type(n) == "table" and n.Type == multi.PROXY and n.isConnection() then
local ready = false
local args