Working on 16.0.0 #53

Merged
rayaman merged 120 commits from v16.0.0 into master 2024-02-25 00:00:51 -05:00
3 changed files with 93 additions and 13 deletions
Showing only changes of commit 5cc18b04ae - Show all commits

View File

@ -62,12 +62,13 @@ Table of contents
## Added New Integration: **priorityManager** ## Added New Integration: **priorityManager**
Allows the user to have multi auto set priorities. Also adds the functionality to create your own runners (multi:mainloop(), multi:umanager()) that you can set using the priority manager. Even if you do not have `chronos` installed these features will still work! Allows the user to have multi auto set priorities (Requires chronos). Also adds the functionality to create your own runners (multi:mainloop(), multi:umanager()) that you can set using the priority manager. Even if you do not have `chronos` installed all other features will still work!
- Allows the creation of custom priorityManagers for example: - Allows the creation of custom priorityManagers for example:
Added Added
--- ---
- multi.Processors:getHandler() -- returns the thread handler for a process
- multi.OnPriorityChanged(self, priority) -- Connection is triggered whenever the priority of an object is changed!
- multi.setClock(clock_func) -- If you have access to a clock function that works like os.clock() you can set it using this function. The priorityManager if chronos is installed sets the clock to it's current version. - multi.setClock(clock_func) -- If you have access to a clock function that works like os.clock() you can set it using this function. The priorityManager if chronos is installed sets the clock to it's current version.
- multi:setCurrentTask() -- Used to set the current processor. Used in custom processors. - multi:setCurrentTask() -- Used to set the current processor. Used in custom processors.
- multi:setCurrentProcess() -- Used to set the current processor. It should only be called on a processor object - multi:setCurrentProcess() -- Used to set the current processor. It should only be called on a processor object
@ -160,6 +161,9 @@ Added
conn4:Fire(3,2,3) conn4:Fire(3,2,3)
-- This second one won't trigger the Hi's
conn4:Fire(1,2,3)
conn5(function() conn5(function()
print("Test 1") print("Test 1")
end) end)

View File

@ -633,6 +633,7 @@ function multi:newBase(ins)
c.funcTM={} c.funcTM={}
c.funcTMR={} c.funcTMR={}
c.OnBreak = multi:newConnection() c.OnBreak = multi:newConnection()
c.OnPriorityChanged = multi:newConnection()
c.TID = _tid c.TID = _tid
c.Act=function() end c.Act=function() end
c.Parent=self c.Parent=self
@ -1061,6 +1062,10 @@ function multi:newProcessor(name, nothread)
c.OnError(multi.error) c.OnError(multi.error)
function c:getHandler()
return handler
end
function c:getThreads() function c:getThreads()
return c.threads return c.threads
end end
@ -1412,6 +1417,38 @@ function thread:newFunction(func, holdme)
end, holdme)() end, holdme)()
end end
function thread:newProcessor(name)
-- Inactive proxy proc
local proc = multi:getCurrentProcess():newProcessor(name, true)
local thread_proc = multi:getCurrentProcess():newProcessor(name, true)
local handler = thread_proc:getHandler()
function proc:getThreads()
return thread_proc.threads
end
function proc:newThread(name, func,...)
return thread.newThread(thread_proc, name, func, ...)
end
function c:newFunction(func, holdme)
return thread:newFunctionBase(function(...)
return thread_proc:newThread("Threaded Function Handler", func, ...)
end, holdme)()
end
proc.OnObjectCreated(function(obj)
thread_proc:newThread(function()
while true do
thread.yield()
--
end
end)
end)
return proc
end
-- A cross version way to set enviroments, not the same as fenv though -- A cross version way to set enviroments, not the same as fenv though
function multi.setEnv(func,env) function multi.setEnv(func,env)
local f = string.dump(func) local f = string.dump(func)
@ -2102,6 +2139,7 @@ function multi:setPriority(s)
elseif s:lower()=='idle' or s:lower()=='i' then elseif s:lower()=='idle' or s:lower()=='i' then
self.Priority=self.Priority_Idle self.Priority=self.Priority_Idle
end end
self.OnPriorityChanged:Fire(self, self.Priority)
end end
if not self.PrioritySet then if not self.PrioritySet then
self.defPriority = self.Priority self.defPriority = self.Priority
@ -2225,7 +2263,6 @@ function multi:reallocate(processor, index)
index=index or #processor.Mainloop+1 index=index or #processor.Mainloop+1
local int=self.Parent local int=self.Parent
self.Parent=processor self.Parent=processor
print("Moving task to new processor!")
if index then if index then
table.insert(processor.Mainloop, index, self) table.insert(processor.Mainloop, index, self)
else else

View File

@ -2,19 +2,58 @@ package.path = "../?/init.lua;../?.lua;"..package.path
multi, thread = require("multi"):init{print=true,warn=true,error=true} multi, thread = require("multi"):init{print=true,warn=true,error=true}
require("multi.integration.priorityManager") require("multi.integration.priorityManager")
test = multi:newProcessor("Test") -- test = multi:newProcessor("Test")
test:setPriorityScheme(multi.priorityScheme.TimeBased) -- test:setPriorityScheme(multi.priorityScheme.TimeBased)
multi.OnObjectCreated(function(proc, obj)
print("MULTI",proc.Type,obj.Type) -- test:newUpdater(10000000):OnUpdate(function()
end) -- print("Print is slowish")
local a = 0 -- end)
test:newUpdater(100000):OnUpdate(function()
print("Print is slowish") -- print("Running...")
local conn1, conn2 = multi:newConnection(), multi:newConnection()
conn3 = conn1 + conn2
conn1(function()
print("Hi 1")
end) end)
print("Running...") conn2(function()
print("Hi 2")
end)
multi:mainloop() conn3(function()
print("Hi 3")
end)
function test(a,b,c)
print("I run before all and control if execution should continue!")
return a>b
end
conn4 = test .. conn1
conn5 = conn2 .. function() print("I run after it all!") end
conn4:Fire(3,2,3)
-- This second one won't trigger the Hi's
conn4:Fire(1,2,3)
conn5(function()
print("Test 1")
end)
conn5(function()
print("Test 2")
end)
conn5(function()
print("Test 3")
end)
conn5:Fire()
--multi:mainloop()
-- local conn1, conn2, conn3 = multi:newConnection(nil,nil,true), multi:newConnection(), multi:newConnection() -- local conn1, conn2, conn3 = multi:newConnection(nil,nil,true), multi:newConnection(), multi:newConnection()