* [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