Changes to threads

This commit is contained in:
2023-05-07 23:03:15 -04:00
parent ec9f7dec61
commit a5add93747
12 changed files with 63 additions and 67 deletions
+3 -3
View File
@@ -196,7 +196,7 @@ function multi:newSystemThreadedConnection(name)
end
return r
end
c.CID = THREAD.getID()
c.CID = THREAD_ID
c.subscribe = multi:newSystemThreadedQueue("SUB_STC_"..self.Name):init()
c.Name = name
c.links = {} -- All triggers sent from main connection. When a connection is triggered on another thread, they speak to the main then send stuff out.
@@ -262,7 +262,7 @@ function multi:newSystemThreadedConnection(name)
function c:Fire(...)
local args = {...}
if self.CID == THREAD.getID() then -- Host Call
if self.CID == THREAD_ID then -- Host Call
for _, link in pairs(self.links) do
link:push {self.TRIG, args}
end
@@ -284,7 +284,7 @@ function multi:newSystemThreadedConnection(name)
tempMT.__index = self.proxy_conn
tempMT.__call = function(t,func) self.proxy_conn(func) end
setmetatable(self, tempMT)
if self.CID == THREAD.getID() then return self end
if self.CID == THREAD_ID then return self end
thread:newThread("STC_CONN_MAN"..name,function()
local item
local link_self_ref = multi:newSystemThreadedQueue()
-8
View File
@@ -88,14 +88,6 @@ local function INIT(__GlobalLinda, __SleepingLinda, __StatusLinda, __Console)
function THREAD.kill() -- trigger the lane destruction
error("Thread was killed!\1")
end
function THREAD.getName()
return THREAD_NAME
end
function THREAD.getID()
return THREAD_ID
end
function THREAD.pushStatus(...)
local args = {...}
+2
View File
@@ -34,6 +34,8 @@ __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__)
math.random()
math.random()
-8
View File
@@ -114,14 +114,6 @@ function threads.getThread(n)
return GLOBAL["__THREAD_"..n]
end
function threads.getName()
return __THREADNAME__
end
function threads.getID()
return __THREADID__
end
function threads.sleep(n)
love.timer.sleep(n)
end
+11 -2
View File
@@ -50,6 +50,7 @@ function multi:newSystemThreadedQueue(name)
GLOBAL[name or "_"] = c
return c
end
function multi:newSystemThreadedTable(name)
local c = {}
function c:init()
@@ -58,6 +59,7 @@ function multi:newSystemThreadedTable(name)
GLOBAL[name or "_"] = c
return c
end
local setfenv = setfenv
if not setfenv then
if not debug then
@@ -68,6 +70,7 @@ if not setfenv then
end
end
end
function multi:newSystemThreadedJobQueue(n)
local c = {}
c.cores = n or THREAD.getCores()*2
@@ -76,26 +79,32 @@ function multi:newSystemThreadedJobQueue(n)
local ID=1
local jid = 1
local env = {}
setmetatable(env,{
__index = _G
})
local funcs = {}
function c:doToAll(func)
setfenv(func,env)()
return self
end
function c:registerFunction(name,func)
funcs[name] = setfenv(func,env)
return self
end
function c:pushJob(name,...)
table.insert(jobs,{name,jid,{...}})
jid = jid + 1
return jid-1
end
function c:isEmpty()
return #jobs == 0
end
local nFunc = 0
function c:newFunction(name,func,holup) -- This registers with the queue
local func = stripUpValues(func)
@@ -120,7 +129,7 @@ function multi:newSystemThreadedJobQueue(n)
return unpack(rets) or multi.NIL
end
end)
end,holup),name
end, holup), name
end
for i=1,c.cores do
thread:newThread("PesudoThreadedJobQueue_"..i,function()
@@ -133,7 +142,7 @@ function multi:newSystemThreadedJobQueue(n)
thread.sleep(.05)
end
end
end).OnError(print)
end).OnError(multi.error)
end
return c
end
+21 -15
View File
@@ -31,8 +31,8 @@ if multi.integration then
end
}
end
local GLOBAL, THREAD = require("multi.integration.pseudoManager.threads").init(thread)
local activator = require("multi.integration.pseudoManager.threads")
local GLOBAL, THREAD = activator.init(thread)
function multi:canSystemThread() -- We are emulating system threading
return true
@@ -55,22 +55,28 @@ tab = split(tab)
local id = 0
function multi:newSystemThread(name,func,...)
GLOBAL["$THREAD_NAME"] = name
GLOBAL["$__THREADNAME__"] = name
GLOBAL["$THREAD_ID"] = id
GLOBAL["$thread"] = thread
print("Outerglobal",_G)
local env = {
function multi:newSystemThread(name, func, ...)
local env
env = {
GLOBAL = GLOBAL,
THREAD = THREAD,
THREAD_NAME = name,
__THREADNAME__ = name,
THREAD_NAME = tostring(name),
__THREADNAME__ = tostring(name),
test = "testing",
THREAD_ID = id,
thread = thread,
multi = multi,
}
env.__env = env
for i, v in pairs(_G) do
if not(env[i]) and not(i == "_G") and not(i == "local_global") then
env[i] = v
else
multi.warn("skipping:",i)
end
end
if GLOBAL["__env"] then
for i,v in pairs(GLOBAL["__env"]) do
@@ -78,11 +84,11 @@ function multi:newSystemThread(name,func,...)
end
end
for i = 1,#tab do
env[tab[i]] = _G[tab[i]]
end
env._G = env
local GLOBAL, THREAD = activator.init(thread, env)
local th = thread:newISOThread(name,func,env,...)
local th = thread:newISOThread(name, func, env, ...)
id = id + 1
+4 -12
View File
@@ -33,6 +33,7 @@ end
local function INIT(thread)
local THREAD = {}
local GLOBAL = {}
THREAD.Priority_Core = 3
THREAD.Priority_High = 2
THREAD.Priority_Above_Normal = 1
@@ -84,14 +85,6 @@ local function INIT(thread)
error("Thread was killed!")
end
function THREAD.getName()
return GLOBAL["$THREAD_NAME"]
end
function THREAD.getID()
return GLOBAL["$THREAD_ID"]
end
THREAD.sleep = thread.sleep
THREAD.hold = thread.hold
@@ -107,18 +100,17 @@ local function INIT(thread)
end
function THREAD.exposeENV(name)
print("env",__env)
name = name or "__env"
local env = THREAD.getENV(name)
for i,v in pairs(env) do
-- This may need to be reworked!
_G[i] = v
local_global[i] = v
end
end
return GLOBAL, THREAD
end
return {init = function(thread)
return INIT(thread)
return {init = function(thread, global)
return INIT(thread, global)
end}