From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on gnuweeb.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=ALL_TRUSTED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NO_DNS_FOR_FROM,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.6 Received: from localhost.localdomain (unknown [180.246.144.41]) by gnuweeb.org (Postfix) with ESMTPSA id E8EC2809EA; Sun, 21 Aug 2022 11:25:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gnuweeb.org; s=default; t=1661081150; bh=mZC69DVAIiSy6n3RUkS0Wa+9niXhD77g6HLjaIRwnzs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=H4mCiKaWRM/Fl9eJErR1nWf0BJkoBmM9LRKChKE7v5x/5a1+U3zfiyG7iuf0XgtqD JCC59qbGeV84tw0UFO6VelL8zkjij3xA9rjO2d4MZmMW7ZLix7NFRpa0c8Bo9d8NmF woW8QFkqebO3vciIZXA/N8RR6q4Q4BbQfOXa9m2gVJIug0P8bM2sl8DNHQ1QC+OEee xamj1sV7v8Sg3RJRGsPJihiXn2Z8FJiAYOxyUrZgHV1fR/rGjwInZcbvDPvTgnyN7F ZAuEAXb1wJ4kr5Ql9MZYjirlIcape3y8ZE93nKfPfGsLJZxi4si/Rgv5mc9YItw/ej LXFyc+NBAV3EA== From: Ammar Faizi To: Alviro Iskandar Setiawan Cc: Ammar Faizi , Muhammad Rizki , Kanna Scarlet , GNU/Weeb Mailing List Subject: [PATCH v1 15/22] chnet: node: Don't use static counter for data ID Date: Sun, 21 Aug 2022 18:24:46 +0700 Message-Id: <20220821112453.3026255-16-ammarfaizi2@gnuweeb.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220821112453.3026255-1-ammarfaizi2@gnuweeb.org> References: <20220821112453.3026255-1-ammarfaizi2@gnuweeb.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: The calculation will be wrong if we have multiple rings. Just provide a counter for each ring, don't share it across multiple rings. Fixes: 34c16780ba00890faa7139092965537ef713d853 ("chnet: node: Add set_user_data support on SQE") Signed-off-by: Ammar Faizi --- chnet/chnet_node.cc | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/chnet/chnet_node.cc b/chnet/chnet_node.cc index 1269577..621d7aa 100644 --- a/chnet/chnet_node.cc +++ b/chnet/chnet_node.cc @@ -6,10 +6,12 @@ public: inline NodeCHNetRing(uint32_t entry): ring_(entry) { + ucount_.store(0, std::memory_order_relaxed); } CNRingCtx ring_; Napi::ObjectReference ref_; + std::atomic ucount_; }; class NodeCNRingSQE { @@ -122,7 +124,6 @@ static void CHN_SQEPrepRead(const Napi::CallbackInfo &info) static Napi::Value CHN_SQESetUserData(const Napi::CallbackInfo &info) { - static std::atomic count; Napi::Env env = info.Env(); struct NodeSQData *data; NodeCNRingSQE *nsqe; @@ -135,7 +136,7 @@ static Napi::Value CHN_SQESetUserData(const Napi::CallbackInfo &info) nsqe = (NodeCNRingSQE *)info.Data(); data = new struct NodeSQData; data->ring_ = nsqe->ring_; - data->id_ = count++ & nsqe->ring_->ring_.cq_mask_; + data->id_ = nsqe->ring_->ucount_++ & nsqe->ring_->ring_.cq_mask_; nsqe->ring_->ref_.Get("__udata") .As()[data->id_] = info[0]; nsqe->sqe_->SetUserDataPtr(data); -- Ammar Faizi