Tarantool development patches archive
 help / color / mirror / Atom feed
From: Oleg Babin via Tarantool-patches <tarantool-patches@dev.tarantool.org>
To: v.shpilevoy@tarantool.org, imun@tarantool.org
Cc: tarantool-patches@dev.tarantool.org
Subject: [Tarantool-patches] [PATCH v3 3/4] lua/utils: make LUA_NOREF value public
Date: Fri,  3 Sep 2021 23:49:17 +0300	[thread overview]
Message-ID: <1e90d3a90caed7259cec2fc117d6ff52a1d4a859.1630701714.git.babinoleg@mail.ru> (raw)
In-Reply-To: <cover.1630701714.git.babinoleg@mail.ru>

From: Oleg Babin <babinoleg@mail.ru>

Before this patch we used an assumption in lua fiber code that
all valid lua refs are positive numbers. However there are
special constants defined in lua header for such purpose LUA_NOREF
and LUA_REFNIL [1]. Previously there was introduced public value
for LUA_REFNIL - luaL_nil_ref. This patch introduces an analog
for LUA_NOREF - luaL_no_ref.

Also this patch introduces several usages of this value - let's
make fiber code more clearer and start to intialize ref values
with LUA_NOREF value. Also it will be needed for future changes.

  [1] https://pgl.yoyo.org/luai/i/luaL_ref
---
 src/lib/core/fiber.c        | 3 +++
 src/lua/fiber.c             | 3 +--
 src/lua/utils.c             | 1 +
 test/unit/core_test_utils.c | 2 ++
 4 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/src/lib/core/fiber.c b/src/lib/core/fiber.c
index 588b78504..21afde209 100644
--- a/src/lib/core/fiber.c
+++ b/src/lib/core/fiber.c
@@ -44,6 +44,7 @@
 #include "errinj.h"
 
 extern void cord_on_yield(void);
+extern int luaL_no_ref;
 
 #if ENABLE_FIBER_TOP
 #include <x86intrin.h> /* __rdtscp() */
@@ -895,6 +896,7 @@ fiber_recycle(struct fiber *fiber)
 	fiber->f = NULL;
 	fiber->wait_pad = NULL;
 	memset(&fiber->storage, 0, sizeof(fiber->storage));
+	fiber->storage.lua.storage_ref = luaL_no_ref;
 	unregister_fid(fiber);
 	fiber->fid = 0;
 	region_free(&fiber->gc);
@@ -1236,6 +1238,7 @@ fiber_new_ex(const char *name, const struct fiber_attr *fiber_attr,
 			return NULL;
 		}
 		memset(fiber, 0, sizeof(struct fiber));
+		fiber->storage.lua.storage_ref = luaL_no_ref;
 
 		if (fiber_stack_create(fiber, &cord()->slabc,
 				       fiber_attr->stack_size)) {
diff --git a/src/lua/fiber.c b/src/lua/fiber.c
index 5575f2079..6457a1428 100644
--- a/src/lua/fiber.c
+++ b/src/lua/fiber.c
@@ -683,7 +683,6 @@ lbox_fiber_on_stop(struct trigger *trigger, void *event)
 {
 	struct fiber *f = (struct fiber *) event;
 	int storage_ref = f->storage.lua.storage_ref;
-	assert(storage_ref > 0);
 	luaL_unref(tarantool_L, LUA_REGISTRYINDEX, storage_ref);
 	f->storage.lua.storage_ref = LUA_NOREF;
 	trigger_clear(trigger);
@@ -696,7 +695,7 @@ lbox_fiber_storage(struct lua_State *L)
 {
 	struct fiber *f = lbox_checkfiber(L, 1);
 	int storage_ref = f->storage.lua.storage_ref;
-	if (storage_ref <= 0) {
+	if (storage_ref == LUA_NOREF) {
 		struct trigger *t = (struct trigger *)
 			malloc(sizeof(*t));
 		if (t == NULL) {
diff --git a/src/lua/utils.c b/src/lua/utils.c
index c71cd4857..c252d7cdf 100644
--- a/src/lua/utils.c
+++ b/src/lua/utils.c
@@ -40,6 +40,7 @@
 #include "uuid/tt_uuid.h"
 
 int luaL_nil_ref = LUA_REFNIL;
+int luaL_no_ref = LUA_NOREF;
 
 static int luaT_newthread_ref = LUA_NOREF;
 
diff --git a/test/unit/core_test_utils.c b/test/unit/core_test_utils.c
index 23452bbfd..9b1789e75 100644
--- a/test/unit/core_test_utils.c
+++ b/test/unit/core_test_utils.c
@@ -35,3 +35,5 @@
 void cord_on_yield(void)
 {
 }
+
+int luaL_no_ref = -2;
-- 
2.32.0


  parent reply	other threads:[~2021-09-03 20:51 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-03 20:49 [Tarantool-patches] [PATCH v3 0/4] fiber: keep reference to userdata if fiber created once Oleg Babin via Tarantool-patches
2021-09-03 20:49 ` [Tarantool-patches] [PATCH v3 1/4] fiber: rename ref to storage_ref Oleg Babin via Tarantool-patches
2021-09-03 20:49 ` [Tarantool-patches] [PATCH v3 2/4] fiber: pass struct fiber into lbox_pushfiber instead of id Oleg Babin via Tarantool-patches
2021-09-03 20:49 ` Oleg Babin via Tarantool-patches [this message]
2021-09-03 20:49 ` [Tarantool-patches] [PATCH v3 4/4] fiber: keep reference to userdata if fiber created once Oleg Babin via Tarantool-patches
2021-09-07 21:43 ` [Tarantool-patches] [PATCH v3 0/4] " Vladislav Shpilevoy via Tarantool-patches
2021-09-08 12:54   ` Oleg Babin via Tarantool-patches

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1e90d3a90caed7259cec2fc117d6ff52a1d4a859.1630701714.git.babinoleg@mail.ru \
    --to=tarantool-patches@dev.tarantool.org \
    --cc=imun@tarantool.org \
    --cc=olegrok@tarantool.org \
    --cc=v.shpilevoy@tarantool.org \
    --subject='Re: [Tarantool-patches] [PATCH v3 3/4] lua/utils: make LUA_NOREF value public' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox