cleaned up thread files

This commit is contained in:
Ryan Ward 2020-04-01 10:10:11 -04:00
parent 61dcb9da01
commit 68908f093b
3 changed files with 21 additions and 39 deletions

View File

@ -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, {

View File

@ -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

View File

@ -47,19 +47,12 @@ 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
@ -68,27 +61,19 @@ local function INIT()
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!")
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()