mirror of
https://github.com/cloudwu/skynet.git
synced 2026-07-24 12:20:41 +00:00
bugfix: skynet.queue
This commit is contained in:
@@ -9,21 +9,20 @@ function skynet.queue()
|
|||||||
local thread_queue = {}
|
local thread_queue = {}
|
||||||
return function(f, ...)
|
return function(f, ...)
|
||||||
local thread = coroutine.running()
|
local thread = coroutine.running()
|
||||||
if ref == 0 then
|
if current_thread and current_thread ~= thread then
|
||||||
current_thread = thread
|
|
||||||
elseif current_thread ~= thread then
|
|
||||||
table.insert(thread_queue, thread)
|
table.insert(thread_queue, thread)
|
||||||
skynet.wait()
|
skynet.wait()
|
||||||
assert(ref == 0)
|
assert(ref == 0) -- current_thread == thread
|
||||||
end
|
end
|
||||||
|
current_thread = thread
|
||||||
|
|
||||||
ref = ref + 1
|
ref = ref + 1
|
||||||
local ok, err = pcall(f, ...)
|
local ok, err = pcall(f, ...)
|
||||||
ref = ref - 1
|
ref = ref - 1
|
||||||
if ref == 0 then
|
if ref == 0 then
|
||||||
current_thread = nil
|
current_thread = table.remove(thread_queue,1)
|
||||||
local co = table.remove(thread_queue,1)
|
if current_thread then
|
||||||
if co then
|
skynet.wakeup(current_thread)
|
||||||
skynet.wakeup(co)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
assert(ok,err)
|
assert(ok,err)
|
||||||
|
|||||||
Reference in New Issue
Block a user