tiny changes

This commit is contained in:
Ryan Ward 2019-07-15 21:04:22 -04:00
parent 7126e28530
commit 3bbd63ba62
4 changed files with 44 additions and 20 deletions

View File

@ -1,13 +1,19 @@
#Changes # Changes
[TOC] [TOC]
Update 13.1.0 Bug fixes and some new features (Will upgrade version to 14.0.0 if significant changes are made) Update 13.1.0 Bug fixes and some new features (Will upgrade version to 14.0.0 if significant changes are made)
------------- -------------
Added: Added:
- Connections:Lock() -- Prevents a connection object form being fired - Connections:Lock() -- Prevents a connection object form being fired
- Connections:Unlock() -- Removes the restriction imposed by conn:Lock() - Connections:Unlock() -- Removes the restriction imposed by conn:Lock()
-
Fixed: Fixed:
- Minor bug with multi:newThread() in how names and functions were managed - Minor bug with multi:newThread() in how names and functions were managed
- Major bug with the system thread handler. Saw healthy threads as dead ones
-
Changed:
- getTasksDetails("t"), the table varaiant, formats threads, and system threads in the same way that tasks are formatted
- -
Update 13.0.0 Added some documentation, and some new features too check it out! Update 13.0.0 Added some documentation, and some new features too check it out!

View File

@ -158,7 +158,7 @@ function multi:getLoad()
bench = steps bench = steps
bb = steps bb = steps
end) end)
while not bench do while not bench do
multi:uManager() multi:uManager()
end end
bench = bench^1.5 bench = bench^1.5
@ -355,7 +355,7 @@ function multi:getTasksDetails(t)
dat2 = dat2.."<SystemThread: "..multi.SystemThreads[i].Name.." | "..os.clock()-multi.SystemThreads[i].creationTime..">\n" dat2 = dat2.."<SystemThread: "..multi.SystemThreads[i].Name.." | "..os.clock()-multi.SystemThreads[i].creationTime..">\n"
end end
end end
local load,steps = multi:getLoad() local load, steps = multi:getLoad()
if multi.scheduler then if multi.scheduler then
for i=1,#multi.scheduler.Threads do for i=1,#multi.scheduler.Threads do
dat = dat .. "<THREAD: "..multi.scheduler.Threads[i].Name.." | "..os.clock()-multi.scheduler.Threads[i].creationTime..">\n" dat = dat .. "<THREAD: "..multi.scheduler.Threads[i].Name.." | "..os.clock()-multi.scheduler.Threads[i].creationTime..">\n"
@ -373,19 +373,18 @@ function multi:getTasksDetails(t)
PriorityScheme = priorityTable[multi.defaultSettings.priority or 0], PriorityScheme = priorityTable[multi.defaultSettings.priority or 0],
SystemLoad = multi.Round(load,2), SystemLoad = multi.Round(load,2),
CyclesPerSecondPerTask = steps, CyclesPerSecondPerTask = steps,
SystemThreadCount = #multi.SystemThreads
} }
str.threads = {} str.Threads = {}
str.systemthreads = {} str.Systemthreads = {}
for i,v in pairs(self.Mainloop) do for i,v in pairs(self.Mainloop) do
str[#str+1]={Type=v.Type,Name=v.Name,Uptime=os.clock()-v.creationTime,Priority=self.PriorityResolve[v.Priority],TID = i} str[#str+1]={Type=v.Type,Name=v.Name,Uptime=os.clock()-v.creationTime,Priority=self.PriorityResolve[v.Priority],TID = i}
end end
for i=1,#multi.scheduler.Threads do for i=1,#multi.scheduler.Threads do
str.threads[multi.scheduler.Threads[i].Name]={Uptime = os.clock()-multi.scheduler.Threads[i].creationTime} table.insert(str.Threads,{Uptime = os.clock()-multi.scheduler.Threads[i].creationTime,Name = multi.scheduler.Threads[i].Name})
end end
if multi.canSystemThread then for i=1,#multi.SystemThreads do
for i=1,#multi.SystemThreads do table.insert(str.Systemthreads,{Uptime = os.clock()-multi.SystemThreads[i].creationTime,Name = multi.SystemThreads[i].Name})
str.systemthreads[multi.SystemThreads[i].Name]={Uptime = os.clock()-multi.SystemThreads[i].creationTime}
end
end end
return str return str
end end
@ -635,7 +634,7 @@ function multi:newProcessor(file)
c.Jobs={} c.Jobs={}
c.queue={} c.queue={}
c.jobUS=2 c.jobUS=2
c.l=self:newLoop(function(self,dt) c.l=self:newLoop(function(self,dt)
if self.link.Active then if self.link.Active then
c:uManager() c:uManager()
end end
@ -1055,9 +1054,9 @@ function multi:newFunction(func)
c.func=func c.func=func
mt={ mt={
__index=multi, __index=multi,
__call=function(self,...) __call=function(self,...)
if self.Active then if self.Active then
return self:func(...) return self:func(...)
end end
return nil,true return nil,true
end end
@ -1478,8 +1477,8 @@ function thread.waitFor(name)
return thread.get(name) return thread.get(name)
end end
function thread.testFor(name,_val,sym) function thread.testFor(name,_val,sym)
thread.hold(function() thread.hold(function()
local val = thread.get(name)~=nil local val = thread.get(name)~=nil
if val then if val then
if sym == "==" or sym == "=" then if sym == "==" or sym == "=" then
return _val==val return _val==val

View File

@ -135,6 +135,7 @@ function multi:newSystemThread(name,func,...)
count = count + 1 count = count + 1
c.Type="sthread" c.Type="sthread"
c.creationTime = os.clock() c.creationTime = os.clock()
c.alive = true
local THREAD_NAME=name local THREAD_NAME=name
local function func2(...) local function func2(...)
local multi = require("multi") local multi = require("multi")
@ -151,6 +152,7 @@ function multi:newSystemThread(name,func,...)
function c:kill() function c:kill()
self.thread:cancel() self.thread:cancel()
multi.print("Thread: '"..self.name.."' has been stopped!") multi.print("Thread: '"..self.name.."' has been stopped!")
self.alive = false
end end
table.insert(multi.SystemThreads,c) table.insert(multi.SystemThreads,c)
c.OnError = multi:newConnection() c.OnError = multi:newConnection()
@ -164,17 +166,21 @@ function multi.InitSystemThreadErrorHandler()
multi:newThread("ThreadErrorHandler",function() multi:newThread("ThreadErrorHandler",function()
local threads = multi.SystemThreads local threads = multi.SystemThreads
while true do while true do
thread.sleep(.5) -- switching states often takes a huge hit on performance. half a second to tell me there is an error is good enough. thread.sleep(.5) -- switching states often takes a huge hit on performance. half a second to tell me there is an error is good enough.
for i=#threads,1,-1 do for i=#threads,1,-1 do
local v,err,t=threads[i].thread:join(.001) local v,err,t=threads[i].thread:join(.001)
if err then if err then
if err:find("Thread was killed!") then if err:find("Thread was killed!") then
print(err)
livingThreads[threads[i].Id] = {false,threads[i].Name} livingThreads[threads[i].Id] = {false,threads[i].Name}
threads[i].alive = false
multi.OnSystemThreadDied:Fire(threads[i].Id) multi.OnSystemThreadDied:Fire(threads[i].Id)
GLOBAL["__THREADS__"]=livingThreads GLOBAL["__THREADS__"]=livingThreads
table.remove(threads,i) table.remove(threads,i)
else elseif err:find("stack traceback") then
print(err)
threads[i].OnError:Fire(threads[i],err,"Error in systemThread: '"..threads[i].name.."' <"..err..">") threads[i].OnError:Fire(threads[i],err,"Error in systemThread: '"..threads[i].name.."' <"..err..">")
threads[i].alive = false
livingThreads[threads[i].Id] = {false,threads[i].Name} livingThreads[threads[i].Id] = {false,threads[i].Name}
multi.OnSystemThreadDied:Fire(threads[i].Id) multi.OnSystemThreadDied:Fire(threads[i].Id)
GLOBAL["__THREADS__"]=livingThreads GLOBAL["__THREADS__"]=livingThreads

View File

@ -15,16 +15,29 @@ function table.print(tbl, indent)
end end
end end
end end
multi:newThread(function() print(#multi.SystemThreads)
multi:newThread("Detail Updater",function()
while true do while true do
thread.sleep(1) thread.sleep(1)
print(multi:getTasksDetails())
print("-----") print("-----")
multi:getTasksDetails("t") table.print(multi:getTasksDetails("t"))
io.read()
end end
end) end)
multi.OnSystemThreadDied(function(...)
print("why you say dead?",...)
end)
multi.OnError(function(...) multi.OnError(function(...)
print(...) print(...)
end) end)
multi:newSystemThread("TestSystem",function()
while true do
THREAD.sleep(1)
print("I'm alive")
end
end)
print(#multi.SystemThreads)
multi:mainloop{ multi:mainloop{
protect = false, protect = false,
print = true print = true