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 = {}
return function(f, ...)
local thread = coroutine.running()
if ref == 0 then
current_thread = thread
elseif current_thread ~= thread then
if current_thread and current_thread ~= thread then
table.insert(thread_queue, thread)
skynet.wait()
assert(ref == 0)
assert(ref == 0) -- current_thread == thread
end
current_thread = thread
ref = ref + 1
local ok, err = pcall(f, ...)
ref = ref - 1
if ref == 0 then
current_thread = nil
local co = table.remove(thread_queue,1)
if co then
skynet.wakeup(co)
current_thread = table.remove(thread_queue,1)
if current_thread then
skynet.wakeup(current_thread)
end
end
assert(ok,err)