From 68908f093bd95686fa48cd6bfc64236b08bdce5e Mon Sep 17 00:00:00 2001 From: Ryan Ward Date: Wed, 1 Apr 2020 10:10:11 -0400 Subject: [PATCH] cleaned up thread files --- multi/integration/lanesManager/threads.lua | 16 +++------- multi/integration/loveManager/threads.lua | 9 ++++-- multi/integration/pesudoManager/threads.lua | 35 ++++++--------------- 3 files changed, 21 insertions(+), 39 deletions(-) diff --git a/multi/integration/lanesManager/threads.lua b/multi/integration/lanesManager/threads.lua index d038f1e..19485b5 100644 --- a/multi/integration/lanesManager/threads.lua +++ b/multi/integration/lanesManager/threads.lua @@ -53,11 +53,6 @@ local function INIT(__GlobalLinda,__SleepingLinda) until __GlobalLinda:get(name) return __GlobalLinda:get(name) end - if getOS() == "windows" then - THREAD.__CORES = tonumber(os.getenv("NUMBER_OF_PROCESSORS")) - else - THREAD.__CORES = tonumber(io.popen("nproc --all"):read("*n")) - end function THREAD.getCores() return THREAD.__CORES end @@ -92,17 +87,16 @@ local function INIT(__GlobalLinda,__SleepingLinda) end _G.THREAD_ID = 0 function THREAD.sleep(n) - math.randomseed(os.time()) __SleepingLinda:receive(n, "__non_existing_variable") end function THREAD.hold(n) - local function wait() - math.randomseed(os.time()) + while true do __SleepingLinda:receive(.001, "__non_existing_variable") + local tab = {n()} + if tab[1] then + return unpack(tab) + end end - repeat - wait() - until n() end local GLOBAL = {} setmetatable(GLOBAL, { diff --git a/multi/integration/loveManager/threads.lua b/multi/integration/loveManager/threads.lua index be04fa2..a5b2dd5 100644 --- a/multi/integration/loveManager/threads.lua +++ b/multi/integration/loveManager/threads.lua @@ -213,9 +213,12 @@ function threads.createStaticTable(n) ) end function threads.hold(n) - local dat - while not(dat) do - dat = n() + while true do + love.timer.sleep(.001) + local tab = {n()} + if tab[1] then + return unpack(tab) + end end end return threads \ No newline at end of file diff --git a/multi/integration/pesudoManager/threads.lua b/multi/integration/pesudoManager/threads.lua index 0c4f802..0a2d459 100644 --- a/multi/integration/pesudoManager/threads.lua +++ b/multi/integration/pesudoManager/threads.lua @@ -47,48 +47,33 @@ local function INIT() function THREAD.waitFor(name) return thread.hold(function() return GLOBAL[name] end) end - if getOS() == "windows" then - THREAD.__CORES = tonumber(os.getenv("NUMBER_OF_PROCESSORS")) - else - THREAD.__CORES = tonumber(io.popen("nproc --all"):read("*n")) - end function THREAD.getCores() return THREAD.__CORES end function THREAD.getConsole() local c = {} - function c.print(...) - print(...) - end + c.print = print function c.error(err) error("ERROR in <"..__THREADNAME__..">: "..err) end return c end function THREAD.getThreads() - return {}--GLOBAL.__THREADS__ - end - if os.getOS() == "windows" then - THREAD.__CORES = tonumber(os.getenv("NUMBER_OF_PROCESSORS")) - else - THREAD.__CORES = tonumber(io.popen("nproc --all"):read("*n")) - end - function THREAD.kill() - error("Thread was killed!") + return {} --GLOBAL.__THREADS__ end + THREAD.__CORES = thread.__CORES function THREAD.getName() - return THREAD_NAME + local t = thread.getRunningThread() + return t.Name end function THREAD.getID() - return THREAD_ID + local t = thread.getRunningThread() + return t.TID end _G.THREAD_ID = 0 - function THREAD.sleep(n) - thread.sleep(n) - end - function THREAD.hold(n) - return thread.hold(n) - end + THREAD.kill = thread.kill + THREAD.sleep = thread.sleep + THREAD.hold = thread.hold return GLOBAL, THREAD end return {init = function()