bugfix: skynet.queue

This commit is contained in:
Cloud Wu
2014-10-17 11:22:49 +08:00
parent 1ef5430e0a
commit 3b95ecd9b2

View File

@@ -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)