summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2024-01-25 00:48:30 +0800
committerruki <[email protected]>2024-01-25 12:10:23 +0800
commit69205c2166c14d131e1515c4fdc8c8fcdb24a101 (patch)
treeeefb443c689f3609f7d8058e2c2ce49d30d378b8
parentfce0864f0973d5ea72527c2f4fe9f16e142cde81 (diff)
improve lock
-rw-r--r--xmake/core/base/scheduler.lua17
1 files changed, 12 insertions, 5 deletions
diff --git a/xmake/core/base/scheduler.lua b/xmake/core/base/scheduler.lua
index ece889cfe..ab2d349d6 100644
--- a/xmake/core/base/scheduler.lua
+++ b/xmake/core/base/scheduler.lua
@@ -519,18 +519,20 @@ function scheduler:co_lock(lockname)
co_locked_tasks = {}
self._CO_LOCKED_TASKS = co_locked_tasks
end
+ local co_waiting_tasks = self._CO_WAITING_TASKS
+ if co_waiting_tasks == nil then
+ co_waiting_tasks = {}
+ self._CO_WAITING_TASKS = co_waiting_tasks
+ end
while true do
+
+ -- try to lock it
if co_locked_tasks[lockname] == nil then
co_locked_tasks[lockname] = running
return true
end
-- this lock has been occupied, we need to wait it
- local co_waiting_tasks = self._CO_WAITING_TASKS
- if co_waiting_tasks == nil then
- co_waiting_tasks = {}
- self._CO_WAITING_TASKS = co_waiting_tasks
- end
co_waiting_tasks[lockname] = co_waiting_tasks[lockname] or {}
table.insert(co_waiting_tasks[lockname], running)
@@ -549,6 +551,11 @@ function scheduler:co_unlock(lockname)
return false, "we must call co_unlock() in coroutine with scheduler!"
end
+ -- is stopped?
+ if not self._STARTED then
+ return false, "the scheduler is stopped!"
+ end
+
-- do unlock
local co_locked_tasks = self._CO_LOCKED_TASKS
if co_locked_tasks == nil then