Tarantool development patches archive
 help / color / mirror / Atom feed
* [tarantool-patches] [PATCH 0/2] fiber: A few cleanups
@ 2019-04-11 22:17 Cyrill Gorcunov
  2019-04-11 22:17 ` [tarantool-patches] [PATCH 1/2] fiber: Drop unused FIBER_CALL_STACK Cyrill Gorcunov
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Cyrill Gorcunov @ 2019-04-11 22:17 UTC (permalink / raw)
  To: tml; +Cc: Cyrill Gorcunov

While I'm researching fibers code I found a few things to cleanup:
 - dangling enum entry, which i think better to drop out
 - opencoded constants for fiber ids, which we should rather
   name with a meaning

Take a look once time permit.

Cyrill Gorcunov (2):
  fiber: Drop unused FIBER_CALL_STACK
  fiber: Define constants for reserved fids

 src/lib/core/fiber.c | 10 +++++-----
 src/lib/core/fiber.h | 12 +++++++++---
 src/lib/core/say.c   |  4 ++--
 3 files changed, 16 insertions(+), 10 deletions(-)

-- 
2.20.1

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [tarantool-patches] [PATCH 1/2] fiber: Drop unused FIBER_CALL_STACK
  2019-04-11 22:17 [tarantool-patches] [PATCH 0/2] fiber: A few cleanups Cyrill Gorcunov
@ 2019-04-11 22:17 ` Cyrill Gorcunov
  2019-04-11 22:17 ` [tarantool-patches] [PATCH 2/2] fiber: Define constants for reserved fids Cyrill Gorcunov
  2019-04-12 15:15 ` [tarantool-patches] [PATCH 0/2] fiber: A few cleanups Vladimir Davydov
  2 siblings, 0 replies; 4+ messages in thread
From: Cyrill Gorcunov @ 2019-04-11 22:17 UTC (permalink / raw)
  To: tml; +Cc: Cyrill Gorcunov

The constant is leftover from 0858590216ba36cd5e4f69be84f643fd00a85e87
---
 src/lib/core/fiber.h | 2 --
 1 file changed, 2 deletions(-)

diff --git a/src/lib/core/fiber.h b/src/lib/core/fiber.h
index 89fb04284..6cc51bda3 100644
--- a/src/lib/core/fiber.h
+++ b/src/lib/core/fiber.h
@@ -433,8 +433,6 @@ struct fiber {
 	char name[FIBER_NAME_MAX + 1];
 };
 
-enum { FIBER_CALL_STACK = 16 };
-
 struct cord_on_exit;
 
 /**
-- 
2.20.1

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [tarantool-patches] [PATCH 2/2] fiber: Define constants for reserved fids
  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
  2019-04-12 15:15 ` [tarantool-patches] [PATCH 0/2] fiber: A few cleanups Vladimir Davydov
  2 siblings, 0 replies; 4+ messages in thread
From: Cyrill Gorcunov @ 2019-04-11 22:17 UTC (permalink / raw)
  To: tml; +Cc: Cyrill Gorcunov

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [tarantool-patches] [PATCH 0/2] fiber: A few cleanups
  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 ` [tarantool-patches] [PATCH 2/2] fiber: Define constants for reserved fids Cyrill Gorcunov
@ 2019-04-12 15:15 ` Vladimir Davydov
  2 siblings, 0 replies; 4+ messages in thread
From: Vladimir Davydov @ 2019-04-12 15:15 UTC (permalink / raw)
  To: Cyrill Gorcunov; +Cc: tml

On Fri, Apr 12, 2019 at 01:17:07AM +0300, Cyrill Gorcunov wrote:
>   fiber: Drop unused FIBER_CALL_STACK
>   fiber: Define constants for reserved fids

Pushed to master.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2019-04-12 15:15 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 ` [tarantool-patches] [PATCH 2/2] fiber: Define constants for reserved fids Cyrill Gorcunov
2019-04-12 15:15 ` [tarantool-patches] [PATCH 0/2] fiber: A few cleanups Vladimir Davydov

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