[Tarantool-patches] [PATCH v2 3/3] swim: use fiber._internal.schedule_task() for GC

Vladislav Shpilevoy v.shpilevoy at tarantool.org
Tue Mar 3 02:29:53 MSK 2020


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)



More information about the Tarantool-patches mailing list