From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTP id 19FAA2BFE6 for ; Thu, 11 Apr 2019 18:17:37 -0400 (EDT) Received: from turing.freelists.org ([127.0.0.1]) by localhost (turing.freelists.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id rk7EEf90SxBW for ; Thu, 11 Apr 2019 18:17:37 -0400 (EDT) Received: from mail-lj1-f172.google.com (mail-lj1-f172.google.com [209.85.208.172]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTPS id B86732BC63 for ; Thu, 11 Apr 2019 18:17:36 -0400 (EDT) Received: by mail-lj1-f172.google.com with SMTP id f23so7032403ljc.0 for ; Thu, 11 Apr 2019 15:17:36 -0700 (PDT) From: Cyrill Gorcunov Subject: [tarantool-patches] [PATCH 2/2] fiber: Define constants for reserved fids Date: Fri, 12 Apr 2019 01:17:09 +0300 Message-Id: <20190411221709.17340-3-gorcunov@gmail.com> In-Reply-To: <20190411221709.17340-1-gorcunov@gmail.com> References: <20190411221709.17340-1-gorcunov@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: tarantool-patches-bounce@freelists.org Errors-to: tarantool-patches-bounce@freelists.org Reply-To: tarantool-patches@freelists.org List-Help: List-Unsubscribe: List-software: Ecartis version 1.0.0 List-Id: tarantool-patches List-Subscribe: List-Owner: List-post: List-Archive: 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