summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2020-02-20 23:20:45 +0800
committerruki <[email protected]>2020-02-20 14:04:31 +0800
commit8079f41e1a5143cc31780a8763bb83b6bcf3c1c9 (patch)
tree2c1b9f19ab32e937ae04ce57c4c425453aa7b60e
parenta584475a0edd286d04bdeef81db86f925a38b5a2 (diff)
disable scheduler for interactive mode
-rw-r--r--xmake/core/base/scheduler.lua12
-rw-r--r--xmake/core/sandbox/modules/import/core/sandbox/sandbox.lua7
2 files changed, 17 insertions, 2 deletions
diff --git a/xmake/core/base/scheduler.lua b/xmake/core/base/scheduler.lua
index 8f3a18730..3d16a6818 100644
--- a/xmake/core/base/scheduler.lua
+++ b/xmake/core/base/scheduler.lua
@@ -475,8 +475,10 @@ end
-- get the current running coroutine
function scheduler:co_running()
- local running = coroutine.running()
- return running and self:co_tasks()[running] or nil
+ if self._ENABLED then
+ local running = coroutine.running()
+ return running and self:co_tasks()[running] or nil
+ end
end
-- get all coroutine tasks
@@ -691,6 +693,11 @@ function scheduler:poller_cancel(obj)
return true
end
+-- enable or disable to scheduler
+function scheduler:enable(enabled)
+ self._ENABLED = enabled
+end
+
-- stop the scheduler loop
function scheduler:stop()
-- mark scheduler status as stopped and spank the poller:wait()
@@ -704,6 +711,7 @@ function scheduler:runloop()
-- start loop
self._STARTED = true
+ self._ENABLED = true
-- ensure poller has been initialized first (for windows/iocp) and check edge-trigger mode (for epoll/kqueue)
if poller:support(poller.EV_POLLER_CLEAR) then
diff --git a/xmake/core/sandbox/modules/import/core/sandbox/sandbox.lua b/xmake/core/sandbox/modules/import/core/sandbox/sandbox.lua
index db5b01a53..2440af74b 100644
--- a/xmake/core/sandbox/modules/import/core/sandbox/sandbox.lua
+++ b/xmake/core/sandbox/modules/import/core/sandbox/sandbox.lua
@@ -31,6 +31,7 @@ local table = require("base/table")
local history = require("project/history")
local dump = require("base/dump")
local option = require("base/option")
+local scheduler = require("base/scheduler")
-- print variables for interactive mode
function sandbox_core_sandbox._interactive_dump(...)
@@ -89,9 +90,15 @@ function sandbox_core_sandbox.interactive()
-- register dump function for interactive mode
instance._PUBLIC["$interactive_dump"] = sandbox_core_sandbox._interactive_dump
+ -- disable scheduler
+ scheduler:enable(false)
+
-- enter interactive mode with this new sandbox
sandbox.interactive(instance._PUBLIC)
+ -- enable scheduler
+ scheduler:enable(true)
+
-- save repl history if readline is enabled
if readline then