summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2019-12-15 11:36:13 +0800
committerruki <[email protected]>2019-12-15 11:36:13 +0800
commit9038508802af9aaf768de61c5191f087e9e18c88 (patch)
treecadc8af0e8c3ebebac5b8816f6add2c7874db6f4
parent4cd0150d5a8ced33c2414fa11e275c0c263d8095 (diff)
fix timeout task for scheduler
-rw-r--r--xmake/core/base/scheduler.lua16
1 files changed, 14 insertions, 2 deletions
diff --git a/xmake/core/base/scheduler.lua b/xmake/core/base/scheduler.lua
index 701d4ec04..525715d78 100644
--- a/xmake/core/base/scheduler.lua
+++ b/xmake/core/base/scheduler.lua
@@ -75,6 +75,16 @@ function _coroutine:is_suspended()
return self:status() == "suspended"
end
+-- get the current timer task
+function _coroutine:_timer_task()
+ return self._TIMER_TASK
+end
+
+-- set the timer task
+function _coroutine:_timer_task_set(task)
+ self._TIMER_TASK = task
+end
+
-- tostring(socket)
function _coroutine:__tostring()
return string.format("<co: %s/%s>", self:thread(), self:name())
@@ -180,7 +190,6 @@ function scheduler:sock_wait(sock, events, timeout)
end
-- the socket events callback
- local timer_task = nil
local function sockevents_cb(sockevents)
-- get the previous socket events
@@ -200,6 +209,7 @@ function scheduler:sock_wait(sock, events, timeout)
end
-- cancel timer task if exists
+ local timer_task = running:_timer_task()
if timer_task then
timer_task.cancel = true
end
@@ -252,13 +262,15 @@ function scheduler:sock_wait(sock, events, timeout)
end
-- register timeout task to timer
+ local timer_task = nil
if timeout > 0 then
timer_task = self:_timer():post(function (cancel)
- if running:is_suspended() then
+ if not cancel and running:is_suspended() then
self:co_resume(running, 0)
end
end, timeout)
end
+ running:_timer_task_set(timer_task)
-- save waiting events
self:_sockevents_set(sock:csock(), events)