From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.2 required=3.0 tests=ALL_TRUSTED,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id E91931F93C for ; Sun, 20 Nov 2022 09:14:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=80x24.org; s=selector1; t=1668935664; bh=bthpc1OGVCN121+SOkEz8mG9fVXxIGj2Er9KkCZ0pFU=; h=From:To:Subject:Date:In-Reply-To:References:From; b=PbWrPvh5nWxMuvG8RGwfIr3ueOREp/8i4beQ9uN1vpE+TwqLgX5j2YujM9Ue7RAPd BI4AKkwjQMUexJVGiZdONn3qsnvt/Vsei4jVAx2NyJuCW0I15ao1dPSyFFjLwSsym1 GuNUG8CFRs7qGgp31Rom0PAkSBj9B1EbSEA5wnPI= From: Eric Wong To: mwrap-perl@80x24.org Subject: [PATCH 1/3] totals_add_rcu: improve readability Date: Sun, 20 Nov 2022 09:14:22 +0000 Message-Id: <20221120091424.2420768-2-e@80x24.org> In-Reply-To: <20221120091424.2420768-1-e@80x24.org> References: <20221120091424.2420768-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: We no longer need to unlock in this function if it fails, and asserting rcu_read_ongoing() is a good idea to ensure cds_lfht_lookup() is used properly. --- mwrap_core.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mwrap_core.h b/mwrap_core.h index 09b7930..291a078 100644 --- a/mwrap_core.h +++ b/mwrap_core.h @@ -226,7 +226,8 @@ static struct src_loc *totals_add_rcu(struct src_loc *k) again: t = CMM_LOAD_SHARED(totals); - if (!t) goto out_unlock; + if (!t) return l; + assert(rcu_read_ongoing()); cds_lfht_lookup(t, k->hval, loc_eq, k, &iter); cur = cds_lfht_iter_get_node(&iter); if (cur) { @@ -236,7 +237,7 @@ again: } else { size_t n = loc_size(k); l = real_malloc(sizeof(*l) + n); - if (!l) goto out_unlock; + if (!l) return l; memcpy(l, k, sizeof(*l) + n); l->mtx = mutex_assign(); l->age_total = 0; @@ -252,7 +253,6 @@ again: goto again; } } -out_unlock: return l; }