Tarantool development patches archive
 help / color / mirror / Atom feed
From: Cyrill Gorcunov <gorcunov@gmail.com>
To: tml <tarantool-patches@freelists.org>
Cc: Cyrill Gorcunov <gorcunov@gmail.com>
Subject: [tarantool-patches] [PATCH 2/2] fiber: Define constants for reserved fids
Date: Fri, 12 Apr 2019 01:17:09 +0300	[thread overview]
Message-ID: <20190411221709.17340-3-gorcunov@gmail.com> (raw)
In-Reply-To: <20190411221709.17340-1-gorcunov@gmail.com>

Opencoded constants are not good for long time
support, make it named one. Moreover there was
a typo in comment, fid = 0 is reserved as well.
---
 src/lib/core/fiber.c | 10 +++++-----
 src/lib/core/fiber.h | 10 +++++++++-
 src/lib/core/say.c   |  4 ++--
 3 files changed, 16 insertions(+), 8 deletions(-)

diff --git a/src/lib/core/fiber.c b/src/lib/core/fiber.c
index c55b3ab39..38a3df511 100644
--- a/src/lib/core/fiber.c
+++ b/src/lib/core/fiber.c
@@ -975,9 +975,9 @@ fiber_new_ex(const char *name, const struct fiber_attr *fiber_attr,
 	}
 
 	fiber->f = f;
-	/* fids from 0 to 100 are reserved */
-	if (++cord->max_fid < 100)
-		cord->max_fid = 101;
+	/* Excluding reserved range */
+	if (++cord->max_fid < FIBER_ID_MAX_RESERVED)
+		cord->max_fid = FIBER_ID_MAX_RESERVED + 1;
 	fiber->fid = cord->max_fid;
 	fiber_set_name(fiber, name);
 	register_fid(fiber);
@@ -1056,14 +1056,14 @@ cord_create(struct cord *cord, const char *name)
 	cord->fiber_registry = mh_i32ptr_new();
 
 	/* sched fiber is not present in alive/ready/dead list. */
-	cord->sched.fid = 1;
+	cord->sched.fid = FIBER_ID_SCHED;
 	fiber_reset(&cord->sched);
 	diag_create(&cord->sched.diag);
 	region_create(&cord->sched.gc, &cord->slabc);
 	fiber_set_name(&cord->sched, "sched");
 	cord->fiber = &cord->sched;
 
-	cord->max_fid = 100;
+	cord->max_fid = FIBER_ID_MAX_RESERVED;
 	/*
 	 * No need to start this event since it's only used for
 	 * ev_feed_event(). Saves a few cycles on every
diff --git a/src/lib/core/fiber.h b/src/lib/core/fiber.h
index 6cc51bda3..fb168e25e 100644
--- a/src/lib/core/fiber.h
+++ b/src/lib/core/fiber.h
@@ -52,6 +52,14 @@ extern "C" {
 
 enum { FIBER_NAME_MAX = 32 };
 
+/**
+ * Fiber ids [0; 100] are reserved.
+ */
+enum {
+	FIBER_ID_SCHED		= 1,
+	FIBER_ID_MAX_RESERVED	= 100
+};
+
 enum {
 	/**
 	 * It's safe to resume (wakeup) this fiber
@@ -445,7 +453,7 @@ struct cord {
 	struct fiber *fiber;
 	struct ev_loop *loop;
 	/**
-	 * Every new fiber gets a new monotonic id. Ids 1-100 are
+	 * Every new fiber gets a new monotonic id. Ids 0 - 100 are
 	 * reserved.
 	 */
 	uint32_t max_fid;
diff --git a/src/lib/core/say.c b/src/lib/core/say.c
index 68aa92f61..3b13b766a 100644
--- a/src/lib/core/say.c
+++ b/src/lib/core/say.c
@@ -750,7 +750,7 @@ say_format_plain_tail(char *buf, int len, int level, const char *filename,
 	struct cord *cord = cord();
 	if (cord) {
 		SNPRINT(total, snprintf, buf, len, " %s", cord->name);
-		if (fiber() && fiber()->fid != 1) {
+		if (fiber() && fiber()->fid != FIBER_ID_SCHED) {
 			SNPRINT(total, snprintf, buf, len, "/%i/%s",
 				fiber()->fid, fiber_name(fiber()));
 		}
@@ -875,7 +875,7 @@ say_format_json(struct log *log, char *buf, int len, int level, const char *file
 		SNPRINT(total, snprintf, buf, len, ", \"cord_name\": \"");
 		SNPRINT(total, json_escape, buf, len, cord->name);
 		SNPRINT(total, snprintf, buf, len, "\"");
-		if (fiber() && fiber()->fid != 1) {
+		if (fiber() && fiber()->fid != FIBER_ID_SCHED) {
 			SNPRINT(total, snprintf, buf, len,
 				", \"fiber_id\": %i, ", fiber()->fid);
 			SNPRINT(total, snprintf, buf, len,
-- 
2.20.1

  parent reply	other threads:[~2019-04-11 22:17 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-11 22:17 [tarantool-patches] [PATCH 0/2] fiber: A few cleanups Cyrill Gorcunov
2019-04-11 22:17 ` [tarantool-patches] [PATCH 1/2] fiber: Drop unused FIBER_CALL_STACK Cyrill Gorcunov
2019-04-11 22:17 ` Cyrill Gorcunov [this message]
2019-04-12 15:15 ` [tarantool-patches] [PATCH 0/2] fiber: A few cleanups Vladimir Davydov

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=20190411221709.17340-3-gorcunov@gmail.com \
    --to=gorcunov@gmail.com \
    --cc=tarantool-patches@freelists.org \
    --subject='Re: [tarantool-patches] [PATCH 2/2] fiber: Define constants for reserved fids' \
    /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