From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from [87.239.111.99] (localhost [127.0.0.1]) by dev.tarantool.org (Postfix) with ESMTP id 2BE956EC5B; Wed, 17 Feb 2021 23:17:31 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 2BE956EC5B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1613593051; bh=X4M/5g8LBGaohpE2JFTylQAkSBi5R53sYvoe7MYxsFY=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=adWMu6I3h21YIOddrLBC76cXY+eSfOPPIFCP8kPK9wB18CB4bG1WBN6e1xosouAWe mbg7mG4w6uhwsY9eeWM2bCJQZYAFHyCIx3+/t9zRa1iqg0kYYtEW7zU/juIrjWIjok /K/Lr0uigcrOH9esyxUJHiH3Ly8Wdsbjk2dtv/1g= Received: from mail-lj1-f182.google.com (mail-lj1-f182.google.com [209.85.208.182]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id DCC2F6EC5B for ; Wed, 17 Feb 2021 23:16:16 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org DCC2F6EC5B Received: by mail-lj1-f182.google.com with SMTP id j6so18023940ljo.5 for ; Wed, 17 Feb 2021 12:16:16 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=muZ9pAahzIXdLhCvp9F19Ro+p8UafEtZcHot2olhjKQ=; b=ZYObWWNqqKeiLmEnimYiaDGZ/9x+11nrdCe8KyqybAIlEOdletqQLb9t5BunjxDyRE QMVcdHpPkT1i8t5BVXFTcCQx4J4pSyLApflyCF/LSHd4Luyj7DjS0+24XEnpIvsnQCif pcL72JsxqaXYQwbLomA9w0EuzkLuJYQl0faJid8fXEL4MqzBMT6ZkjBpKY2LkzaN7Lss XXRnedioDpC0zZStYXKQBfkmHylJ38y649IJxDivPRHwtapMusSI3igB3p/g2pXKgdsf vTTqx9MWe81H2ADhBGKxO9RuFMtYkir4EmbErbvQ6F09R2h1/16IXVb8RmAIL8oD+DE1 p+rQ== X-Gm-Message-State: AOAM530gfC1tI2G3sd54DyrDfJCYudHV6WpLlSCh1zJ6kImOpCsQdpB+ drhaddXyDzlQt9UQSQqvqc0LOefRYzk= X-Google-Smtp-Source: ABdhPJyYPWvjtekkvxf0GIZYOvw3n5qRdQ8RCa1QBAbZZcX7qrqbgNvjVRqkqyxU37zJYiItN+srwA== X-Received: by 2002:a2e:6c0b:: with SMTP id h11mr513170ljc.151.1613592975854; Wed, 17 Feb 2021 12:16:15 -0800 (PST) Received: from grain.localdomain ([5.18.171.94]) by smtp.gmail.com with ESMTPSA id z7sm353813lfd.228.2021.02.17.12.16.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Feb 2021 12:16:15 -0800 (PST) Received: by grain.localdomain (Postfix, from userid 1000) id B83C4560262; Wed, 17 Feb 2021 23:15:25 +0300 (MSK) To: tml Date: Wed, 17 Feb 2021 23:15:21 +0300 Message-Id: <20210217201521.436951-5-gorcunov@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210217201521.436951-1-gorcunov@gmail.com> References: <20210217123945.396396-1-gorcunov@gmail.com> <20210217201521.436951-1-gorcunov@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [Tarantool-patches] [PATCH 4/4] box/func: simplify func_c_call X-BeenThere: tarantool-patches@dev.tarantool.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Cyrill Gorcunov via Tarantool-patches Reply-To: Cyrill Gorcunov Cc: Vladislav Shpilevoy Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" We can reuse cmod_call to eliminate code duplication. Moreover since cmod_call keeps a reference to cmod instance while executing a call, we no longer need module::calls counter (the module won't be unloaded unti execution is complete). Part-of #4642 Signed-off-by: Cyrill Gorcunov --- src/box/func.c | 28 ++-------------------------- 1 file changed, 2 insertions(+), 26 deletions(-) diff --git a/src/box/func.c b/src/box/func.c index 5757f7c25..942c7c3c1 100644 --- a/src/box/func.c +++ b/src/box/func.c @@ -200,7 +200,6 @@ module_new(struct cmod *cmod) } rlist_create(&module->funcs); - module->calls = 0; module->cmod = cmod; return module; @@ -254,7 +253,7 @@ module_delete(struct module *module) static void module_gc(struct module *module) { - if (rlist_empty(&module->funcs) && module->calls == 0) + if (rlist_empty(&module->funcs)) module_delete(module); } @@ -513,32 +512,9 @@ func_c_call(struct func *base, struct port *args, struct port *ret) return -1; } - struct region *region = &fiber()->gc; - size_t region_svp = region_used(region); - uint32_t data_sz; - const char *data = port_get_msgpack(args, &data_sz); - if (data == NULL) - return -1; - - port_c_create(ret); - box_function_ctx_t ctx = { ret }; - - /* Module can be changed after function reload. */ struct module *module = func->module; - assert(module != NULL); - ++module->calls; - int rc = func->func(&ctx, data, data + data_sz); - --module->calls; + int rc = cmod_call(module->cmod, func->func, args, ret); module_gc(module); - region_truncate(region, region_svp); - if (rc != 0) { - if (diag_last_error(&fiber()->diag) == NULL) { - /* Stored procedure forget to set diag */ - diag_set(ClientError, ER_PROC_C, "unknown error"); - } - port_destroy(ret); - return -1; - } return rc; } -- 2.29.2