From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp1.mail.ru (smtp1.mail.ru [94.100.179.111]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id DA2D24696C5 for ; Tue, 3 Mar 2020 02:29:58 +0300 (MSK) From: Vladislav Shpilevoy Date: Tue, 3 Mar 2020 00:29:53 +0100 Message-Id: <189a6d9e98ba6a3fa03cf0b544dd7b7e06892395.1583191602.git.v.shpilevoy@tarantool.org> In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [Tarantool-patches] [PATCH v2 3/3] swim: use fiber._internal.schedule_task() for GC List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: tarantool-patches@dev.tarantool.org, imun@tarantool.org, korablev@tarantool.org swim object created a new fiber in its GC function, because C function swim_delete() yields, and can't be called from an ffi.gc hook. It is not needed since the fiber module has a single worker exactly for such cases. The patch uses it. Follow up #4727 --- src/lua/swim.lua | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/lua/swim.lua b/src/lua/swim.lua index 01eeb7eae..0859915c9 100644 --- a/src/lua/swim.lua +++ b/src/lua/swim.lua @@ -5,6 +5,7 @@ local msgpack = require('msgpack') local crypto = require('crypto') local fiber = require('fiber') local internal = require('swim') +local schedule_task = fiber._internal.schedule_task ffi.cdef[[ struct swim; @@ -954,14 +955,12 @@ local cache_table_mt = { __mode = 'v' } -- instance immediately, because it is invoked by Lua GC. Firstly, -- it is not safe to yield in FFI - Jit can't survive a yield. -- Secondly, it is not safe to yield in any GC function, because --- it stops garbage collection. Instead, here a new fiber is --- created without yields, which works at the end of the event --- loop, and deletes the instance asynchronously. +-- it stops garbage collection. Instead, here GC is delayed, works +-- at the end of the event loop, and deletes the instance +-- asynchronously. -- local function swim_gc(ptr) - fiber.new(function() - internal.swim_delete(ptr) - end) + schedule_task(internal.swim_delete, ptr) end -- -- 2.21.1 (Apple Git-122.3)