mirror of
https://github.com/rayaman/multi.git
synced 2026-09-05 07:27:35 -04:00
SystemThreadedExecute (1.8.5)
Added: SystemThreadedExecute
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
require("core.Library")
|
||||
GLOBAL,sThread=require("multi.integration.loveManager").init() -- load the love2d version of the lanesManager and requires the entire multi library
|
||||
require("core.GuiManager")
|
||||
gui.ff.Color=Color.Black
|
||||
cmd=multi:newSystemThreadedExecute("C:/SystemThreadedExecuteTest.lua")
|
||||
cmd.OnCMDFinished(function(code)
|
||||
print("Got Code: "..code)
|
||||
end)
|
||||
multi:newTLoop(function()
|
||||
print("...")
|
||||
end,1)
|
||||
t=gui:newTextLabel("no done yet!",0,0,300,100)
|
||||
t:centerX()
|
||||
t:centerY()
|
||||
@@ -45,9 +45,9 @@ function print(...)
|
||||
end
|
||||
end
|
||||
multi = {}
|
||||
multi.Version="1.8.4"
|
||||
multi._VERSION="1.8.4"
|
||||
multi.stage='stable'
|
||||
multi.Version="1.8.5"
|
||||
multi._VERSION="1.8.5"
|
||||
multi.stage='mostly-stable'
|
||||
multi.__index = multi
|
||||
multi.Mainloop={}
|
||||
multi.Tasks={}
|
||||
|
||||
@@ -5,7 +5,9 @@ end
|
||||
multi.integration={}
|
||||
multi.integration.love2d={}
|
||||
multi.integration.love2d.ThreadBase=[[
|
||||
__THREADNAME__=({...})[1]
|
||||
tab={...}
|
||||
__THREADNAME__=tab[2]
|
||||
__THREADID__=tab[1]
|
||||
require("love.filesystem")
|
||||
require("love.system")
|
||||
require("love.timer")
|
||||
@@ -32,8 +34,8 @@ function __sync__()
|
||||
love.timer.sleep(.001)
|
||||
if type(data)=="string" then
|
||||
local cmd,tp,name,d=data:match("(%S-) (%S-) (%S-) (.+)")
|
||||
if name=="__DIEPLZ"..__THREADNAME__.."__" then
|
||||
error("Thread: "..__THREADNAME__.." has been stopped!")
|
||||
if name=="__DIEPLZ"..__THREADID__.."__" then
|
||||
error("Thread: "..__THREADID__.." has been stopped!")
|
||||
end
|
||||
if cmd=="SYNC" then
|
||||
__proxy__[name]=resolveType(tp,d)
|
||||
@@ -268,7 +270,7 @@ function multi:newSystemThread(name,func) -- the main method
|
||||
c.name=name
|
||||
c.ID=c.name.."<ID|"..randomString(8)..">"
|
||||
c.thread=love.thread.newThread(multi.integration.love2d.ThreadBase:gsub("INSERT_USER_CODE",dump(func)))
|
||||
c.thread:start(c.ID)
|
||||
c.thread:start(c.ID,c.name)
|
||||
function c:kill()
|
||||
multi.integration.GLOBAL["__DIEPLZ"..self.ID.."__"]="__DIEPLZ"..self.ID.."__"
|
||||
end
|
||||
|
||||
@@ -21,6 +21,14 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
]]
|
||||
function multi.randomString(n)
|
||||
local str = ''
|
||||
local strings = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','1','2','3','4','5','6','7','8','9','0','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'}
|
||||
for i=1,n do
|
||||
str = str..''..strings[math.random(1,#strings)]
|
||||
end
|
||||
return str
|
||||
end
|
||||
function multi:newSystemThreadedQueue(name) -- in love2d this will spawn a channel on both ends
|
||||
local c={} -- where we will store our object
|
||||
c.name=name -- set the name this is important for the love2d side
|
||||
@@ -262,8 +270,8 @@ if love then
|
||||
self.queueOUT:push({self.jobnum,name,...})
|
||||
self.jobnum=self.jobnum+1
|
||||
end
|
||||
local GLOBAL=multi.integration.GLOBAL -- set up locals incase we are using lanes
|
||||
local sThread=multi.integration.THREAD -- set up locals incase we are using lanes
|
||||
local GLOBAL=multi.integration.GLOBAL
|
||||
local sThread=multi.integration.THREAD
|
||||
GLOBAL["__JQ_COUNT__"]=c.cores
|
||||
for i=1,c.cores do
|
||||
multi:newSystemThread("System Threaded Job Queue Worker Thread #"..i,function()
|
||||
@@ -305,3 +313,31 @@ if love then
|
||||
end
|
||||
end
|
||||
end
|
||||
function multi:newSystemThreadedExecute(cmd)
|
||||
local c={}
|
||||
local GLOBAL=multi.integration.GLOBAL -- set up locals incase we are using lanes
|
||||
local sThread=multi.integration.THREAD -- set up locals incase we are using lanes
|
||||
local name="Execute_Thread"..multi.randomString(16)
|
||||
c.name=name
|
||||
GLOBAL[name.."CMD"]=cmd
|
||||
multi:newSystemThread(name,function()
|
||||
if love then -- lets make sure we don't reference upvalues if using love2d
|
||||
GLOBAL=_G.GLOBAL
|
||||
sThread=_G.sThread
|
||||
name=__THREADNAME__ -- global data same as the name we used in this functions creation
|
||||
end -- Lanes should take the local upvalues ^^^
|
||||
cmd=sThread.waitFor(name.."CMD")
|
||||
local ret=os.execute(cmd)
|
||||
GLOBAL[name.."R"]=ret
|
||||
end)
|
||||
c.OnCMDFinished=multi:newConnection()
|
||||
c.looper=multi:newLoop(function(self)
|
||||
local ret=GLOBAL[self.link.name.."R"]
|
||||
if ret then
|
||||
self.link.OnCMDFinished:Fire(ret)
|
||||
self:Destroy()
|
||||
end
|
||||
end)
|
||||
c.looper.link=c
|
||||
return c
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user