diff --git a/halyde/kernel/modules/tsched.lua b/halyde/kernel/modules/tsched.lua index c152d7b..c1f811a 100644 --- a/halyde/kernel/modules/tsched.lua +++ b/halyde/kernel/modules/tsched.lua @@ -16,7 +16,7 @@ function module.init() local gpu = component.gpu local log = require("log") - local idCounter = 1 + tsched.idCounter = 1 function _G._PUBLIC.tsched.runAsTask(path, ...) checkArg(1, path, "string") @@ -68,20 +68,27 @@ function module.init() checkArg(1, func, "function") checkArg(2, name, "string") local task = coroutine.create(func) - local taskInfo = { ["task"] = task, ["name"] = name, ["id"] = idCounter} + local taskInfo = { ["task"] = task, ["name"] = name, ["id"] = tsched.idCounter } if type(tsched.currentTask) == "table" and type(tsched.currentTask.id) == "number" then taskInfo.parent = tsched.currentTask.id taskInfo.user = tsched.currentTask.user end table.insert(tsched.tasks, taskInfo) - idCounter = idCounter + 1 + tsched.idCounter = tsched.idCounter + 1 if taskInfo.parent then log.kernel.info( - ("[tsched] Created task %s (PID %d) by parent PID %d as UID %d"):format(name, idCounter - 1, taskInfo.parent, taskInfo.user) + ("[tsched] Created task %s (PID %d) by parent PID %d as UID %d"):format( + name, + tsched.idCounter - 1, + taskInfo.parent, + taskInfo.user + ) ) else taskInfo.user = 1 -- It's probably being run from kernel level - log.kernel.info(string.format("[tsched] Created task %s (PID %d) as UID 1 (no parent found)", name, idCounter - 1)) + log.kernel.info( + string.format("[tsched] Created task %s (PID %d) as UID 1 (no parent found)", name, tsched.idCounter - 1) + ) end return task, taskInfo end diff --git a/halyde/kernel/modules/user.lua b/halyde/kernel/modules/user.lua index ba59d4d..23f2bb3 100644 --- a/halyde/kernel/modules/user.lua +++ b/halyde/kernel/modules/user.lua @@ -38,17 +38,32 @@ function module.init() end local task = coroutine.create(func) - local taskInfo = { ["task"] = task, ["name"] = name, ["id"] = #_PUBLIC.tsched.getTasks() + 1, ["user"] = userId} + local taskInfo = { ["task"] = task, ["name"] = name, ["id"] = tsched.idCounter, ["user"] = userId } if type(tsched.currentTask) == "table" and type(tsched.currentTask.id) == "number" then taskInfo.parent = tsched.currentTask.id + else + log.kernel.info("debug: tsched.currentTask is " .. require("serialize").table(tsched.currentTask)) end table.insert(tsched.tasks, taskInfo) if taskInfo.parent then log.kernel.info( - ("[tsched (user)] Created task %s (PID %d) by parent PID %d as UID %d"):format(name, #_PUBLIC.tsched.getTasks(), taskInfo.parent, taskInfo.user) + ("[tsched (user)] Created task %s (PID %d) by parent PID %d as UID %d"):format( + name, + #_PUBLIC.tsched.getTasks(), + taskInfo.parent, + taskInfo.user + ) + ) + log.kernel.info( + string.format( + "[tsched (user)] Created task %s (PID %d) as UID %d (no parent found)", + name, + #_PUBLIC.tsched.getTasks(), + taskInfo.user + ) ) - log.kernel.info(string.format("[tsched (user)] Created task %s (PID %d) as UID %d (no parent found)", name, #_PUBLIC.tsched.getTasks(), taskInfo.user)) end + tsched.idCounter = tsched.idCounter + 1 return task, taskInfo end end