summaryrefslogtreecommitdiff
path: root/xmake
diff options
context:
space:
mode:
authorruki <[email protected]>2019-12-14 00:46:15 +0800
committerruki <[email protected]>2019-12-13 22:37:35 +0800
commit26ea5a3e4a0a474366e879b529d6f0a2c918ef2d (patch)
treebb1964bc50281bf09f83c1eab44827fe01756a65 /xmake
parent4f171e9e2b1eb119b43f08db23c9e6f271f9021d (diff)
add file_server and file_client tests for scheduler/socket
Diffstat (limited to 'xmake')
-rw-r--r--xmake/core/base/scheduler.lua9
-rw-r--r--xmake/core/sandbox/modules/import/core/base/scheduler.lua5
2 files changed, 14 insertions, 0 deletions
diff --git a/xmake/core/base/scheduler.lua b/xmake/core/base/scheduler.lua
index 677b50409..5c916bdce 100644
--- a/xmake/core/base/scheduler.lua
+++ b/xmake/core/base/scheduler.lua
@@ -121,8 +121,12 @@ function scheduler:co_start_named(coname, cotask, ...)
co = _coroutine.new(coname, coroutine.create(function(...)
cotask(...)
self:co_tasks()[co:thread()] = nil
+ if self:co_count() > 0 then
+ self._CO_COUNT = self:co_count() - 1
+ end
end))
self:co_tasks()[co:thread()] = co
+ self._CO_COUNT = self:co_count() + 1
local ok, errors = scheduler:co_resume(co, ...)
if not ok then
return nil, errors
@@ -156,6 +160,11 @@ function scheduler:co_tasks()
return cotasks
end
+-- get all coroutine count
+function scheduler:co_count()
+ return self._CO_COUNT or 0
+end
+
-- wait socket events
function scheduler:waitsock(sock, events, timeout)
diff --git a/xmake/core/sandbox/modules/import/core/base/scheduler.lua b/xmake/core/sandbox/modules/import/core/base/scheduler.lua
index 0a1189459..ed375eb4f 100644
--- a/xmake/core/sandbox/modules/import/core/base/scheduler.lua
+++ b/xmake/core/sandbox/modules/import/core/base/scheduler.lua
@@ -58,6 +58,11 @@ function sandbox_core_base_scheduler.co_running()
return scheduler:co_running()
end
+-- get the all coroutine task count
+function sandbox_core_base_scheduler.co_count()
+ return scheduler:co_count()
+end
+
-- sleep some times (ms)
function sandbox_core_base_scheduler.sleep(ms)
local ok, errors = scheduler:sleep(ms)