Fixed some issues with threads
This commit is contained in:
parent
ef9267d8fc
commit
7da192e8dc
@ -148,11 +148,34 @@ Changed
|
|||||||
|
|
||||||
Removed
|
Removed
|
||||||
---
|
---
|
||||||
- conn:SetHelper(func) -- With the removal of old Connect this function is nolonger needed
|
- conn:SetHelper(func) -- With the removal of old Connect this function is no longer needed
|
||||||
- connection events can nolonger can be chained with connect. Connect only takes a function that you want to connect
|
- connection events can no longer can be chained with connect. Connect only takes a function that you want to connect
|
||||||
|
|
||||||
Fixed
|
Fixed
|
||||||
---
|
---
|
||||||
|
- Oversight with how pushStatus worked with nesting threaded functions, connections and forwarding events
|
||||||
|
```lua
|
||||||
|
func = thread:newFunction(function()
|
||||||
|
for i=1,10 do
|
||||||
|
thread.sleep(1)
|
||||||
|
thread.pushStatus(i)
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
|
||||||
|
func2 = thread:newFunction(function()
|
||||||
|
local ref = func()
|
||||||
|
ref.OnStatus(function(num)
|
||||||
|
-- do stuff with this data
|
||||||
|
|
||||||
|
thread.pushStatus(num*2) -- Technically this is not ran within a thread. This is ran outside of a thread inside the thread handler.
|
||||||
|
end)
|
||||||
|
end)
|
||||||
|
|
||||||
|
local handler = func2()
|
||||||
|
handler.OnStatus(function(num)
|
||||||
|
print(num)
|
||||||
|
end)
|
||||||
|
```
|
||||||
|
|
||||||
ToDo
|
ToDo
|
||||||
---
|
---
|
||||||
|
|||||||
20
init.lua
20
init.lua
@ -30,6 +30,7 @@ local thread = {}
|
|||||||
local processes = {}
|
local processes = {}
|
||||||
local find_optimization = false
|
local find_optimization = false
|
||||||
local threadManager
|
local threadManager
|
||||||
|
local __CurrentConnectionThread
|
||||||
|
|
||||||
if not _G["$multi"] then
|
if not _G["$multi"] then
|
||||||
_G["$multi"] = {multi = multi, thread = thread}
|
_G["$multi"] = {multi = multi, thread = thread}
|
||||||
@ -305,7 +306,7 @@ function multi:newConnection(protect, func, kill)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function c:Fire(...)
|
function c:Fire(...)
|
||||||
for i=1,#call_funcs do
|
for i=1, #call_funcs do
|
||||||
call_funcs[i](...)
|
call_funcs[i](...)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -314,6 +315,17 @@ function multi:newConnection(protect, func, kill)
|
|||||||
function c:fastMode() return self end
|
function c:fastMode() return self end
|
||||||
|
|
||||||
function c:Connect(func)
|
function c:Connect(func)
|
||||||
|
local th
|
||||||
|
if thread.getRunningThread then
|
||||||
|
th = thread.getRunningThread()
|
||||||
|
end
|
||||||
|
if th then
|
||||||
|
local fref = func
|
||||||
|
func = function(...)
|
||||||
|
__CurrentConnectionThread = th
|
||||||
|
fref(...)
|
||||||
|
end
|
||||||
|
end
|
||||||
table.insert(call_funcs, func)
|
table.insert(call_funcs, func)
|
||||||
local temp = {fast = true}
|
local temp = {fast = true}
|
||||||
setmetatable(temp,{
|
setmetatable(temp,{
|
||||||
@ -1244,7 +1256,7 @@ local function cleanReturns(...)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function thread.pushStatus(...)
|
function thread.pushStatus(...)
|
||||||
local t = thread.getRunningThread()
|
local t = thread.getRunningThread() or __CurrentConnectionThread
|
||||||
t.statusconnector:Fire(...)
|
t.statusconnector:Fire(...)
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -1286,8 +1298,8 @@ function thread:newFunctionBase(generator, holdme)
|
|||||||
return cleanReturns(rets[1],rets[2],rets[3],rets[4],rets[5],rets[6],rets[7],rets[8],rets[9],rets[10],rets[11],rets[12],rets[13],rets[14],rets[15],rets[16])
|
return cleanReturns(rets[1],rets[2],rets[3],rets[4],rets[5],rets[6],rets[7],rets[8],rets[9],rets[10],rets[11],rets[12],rets[13],rets[14],rets[15],rets[16])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
tfunc.__call = function(t,...)
|
tfunc.__call = function(th,...)
|
||||||
if t.Active == false then
|
if th.Active == false then
|
||||||
if holdme then
|
if holdme then
|
||||||
return nil, "Function is paused"
|
return nil, "Function is paused"
|
||||||
end
|
end
|
||||||
|
|||||||
@ -47,7 +47,14 @@ multi.integration.THREAD = THREAD
|
|||||||
pcall(require,"multi.integration.loveManager.extensions")
|
pcall(require,"multi.integration.loveManager.extensions")
|
||||||
stab["returns"] = {THREAD.loadDump(__FUNC__)(unpack(__IMPORTS))}
|
stab["returns"] = {THREAD.loadDump(__FUNC__)(unpack(__IMPORTS))}
|
||||||
]]
|
]]
|
||||||
|
|
||||||
local multi, thread = require("multi"):init()
|
local multi, thread = require("multi"):init()
|
||||||
|
|
||||||
|
-- We do not want to load this module twice
|
||||||
|
if multi.integration and multi.integration.THREAD then
|
||||||
|
return multi.integration.GLOBAL, multi.integration.THREAD
|
||||||
|
end
|
||||||
|
|
||||||
local THREAD = {}
|
local THREAD = {}
|
||||||
__THREADID__ = 0
|
__THREADID__ = 0
|
||||||
__THREADNAME__ = "MainThread"
|
__THREADNAME__ = "MainThread"
|
||||||
@ -55,8 +62,6 @@ multi.integration = {}
|
|||||||
local THREAD = require("multi.integration.loveManager.threads")
|
local THREAD = require("multi.integration.loveManager.threads")
|
||||||
local GLOBAL = THREAD.getGlobal()
|
local GLOBAL = THREAD.getGlobal()
|
||||||
local THREAD_ID = 1
|
local THREAD_ID = 1
|
||||||
local OBJECT_ID = 0
|
|
||||||
local stf = 0
|
|
||||||
|
|
||||||
function multi:newSystemThread(name, func, ...)
|
function multi:newSystemThread(name, func, ...)
|
||||||
local c = {}
|
local c = {}
|
||||||
@ -72,7 +77,7 @@ function multi:newSystemThread(name, func, ...)
|
|||||||
THREAD_ID = THREAD_ID + 1
|
THREAD_ID = THREAD_ID + 1
|
||||||
function c:getName() return c.name end
|
function c:getName() return c.name end
|
||||||
thread:newThread(name .. "_System_Thread_Handler",function()
|
thread:newThread(name .. "_System_Thread_Handler",function()
|
||||||
if name == "TempSystemThread" then
|
if name == "SystemThreaded Function Handler" then
|
||||||
local status_channel = love.thread.getChannel("STATCHAN_" .. c.ID)
|
local status_channel = love.thread.getChannel("STATCHAN_" .. c.ID)
|
||||||
thread.hold(function()
|
thread.hold(function()
|
||||||
-- While the thread is running we might as well do something in the loop
|
-- While the thread is running we might as well do something in the loop
|
||||||
|
|||||||
@ -97,9 +97,9 @@ function threads.kill()
|
|||||||
end
|
end
|
||||||
|
|
||||||
function threads.pushStatus(...)
|
function threads.pushStatus(...)
|
||||||
local status_channel = love.thread.getChannel("__"..__THREADID__.."__MULTI__STATUS_CHANNEL__")
|
local status_channel = love.thread.getChannel("STATCHAN_" ..__THREADID__)
|
||||||
local args = {...}
|
local args = {...}
|
||||||
status_channel:push(__THREADID__, args)
|
status_channel:push(args)
|
||||||
end
|
end
|
||||||
|
|
||||||
function threads.getThreads()
|
function threads.getThreads()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user