From 3b95ecd9b22d736dbb65009c4a0d764f4e163aaf Mon Sep 17 00:00:00 2001 From: Cloud Wu Date: Fri, 17 Oct 2014 11:22:49 +0800 Subject: [PATCH] bugfix: skynet.queue --- lualib/skynet/queue.lua | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/lualib/skynet/queue.lua b/lualib/skynet/queue.lua index 9f40e247..b427da6b 100644 --- a/lualib/skynet/queue.lua +++ b/lualib/skynet/queue.lua @@ -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)