Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp4495226imm; Fri, 18 May 2018 06:08:35 -0700 (PDT) X-Google-Smtp-Source: AB8JxZr7sn9wAvM7B2hrDRI/9Nx3nm5m5aUs2LPwLt+mCja5t6YwFOjNcYwlbphHIjh+gaqH0uET X-Received: by 2002:a65:4789:: with SMTP id e9-v6mr7557280pgs.235.1526648915182; Fri, 18 May 2018 06:08:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526648915; cv=none; d=google.com; s=arc-20160816; b=NqTghk/jQ+ev5I6Z5apvOu8FPCVmGwHtcc/vZq42r+j+UaJlhKZu9b7/aWZ3rBJf3J g6xdh9mnZKNN4NZ7oWmbD69cO2XzTiJ95gIP0oYwCDQsFZX/qzdx4OkyqDb1tvzdIMTK yS9bCnZjjBdJAA52BYqd2bDhaLE793wQYZj674zxb6+kOWtMpj5OhCMoBVJtwYWjpNUs sJ+WWajipGobNcpGXekXwDo5R8TV6LRok3FD+BrLVYPQT+Q5K4plQEmlsm6a2thNlJH1 HmtD2DstOON5Wiy9gg//NLnlbDuECQT7xzPv6Nh5Uk9kXyoow8uucU61Vg9zAf2LU7PZ hGzA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=UD9ycGB1AdB2iWHLig1MDOmhC2Bw6On0cibjUFZbKyA=; b=u1QfOH4V3psmobz+HcnBP/EEpvMpYS+sqIsEoHq9zvtghQ+LtQ42kyWNUbymnIR1/2 GoJVfsHUO/vI2bGmMRArsPQxgTdnQfSffWyBr0hmxi9hsA+AFDYETMIdGH7rkKSHghqB vL5eRfB0paFPLQpwaR4wA7nrJK2OyvbpIQhPD/p1OwEHef41Gc27pMzc7afgVgdQWkll xU2T5hDJSBkShW7AkpYa8WonbHl64EC/VSUcy+QRtS6yVZbj49SPnCDqtP7rOuq6gnbL GOzCMZhmTJFTwE1EvCwAe6B31jvgapP38TFDkV+fFqoV35L54aGcO6hpC8RN7diaQFPo sevQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@profitbricks-com.20150623.gappssmtp.com header.s=20150623 header.b=T6rxnJIa; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n10-v6si5615640pgq.472.2018.05.18.06.08.16; Fri, 18 May 2018 06:08:35 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@profitbricks-com.20150623.gappssmtp.com header.s=20150623 header.b=T6rxnJIa; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752528AbeERNHm (ORCPT + 99 others); Fri, 18 May 2018 09:07:42 -0400 Received: from mail-wm0-f68.google.com ([74.125.82.68]:35453 "EHLO mail-wm0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752500AbeERNF3 (ORCPT ); Fri, 18 May 2018 09:05:29 -0400 Received: by mail-wm0-f68.google.com with SMTP id o78-v6so15140233wmg.0 for ; Fri, 18 May 2018 06:05:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=profitbricks-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=UD9ycGB1AdB2iWHLig1MDOmhC2Bw6On0cibjUFZbKyA=; b=T6rxnJIaNwgW73X63hmBUi9cRwZ+lsyXtokyhzUOL6xzzEZzecGR/K8h/gKEyT7r6v 1h0xdPOl+Z2cBQWVHDQf7jMh40SxOIoVeWkGY4EuHh+x8cnyooXXpI0Gr6hPI8bq5tj7 oCZI+dZsV0kIh0eWsy430UvRlZk6v//27pFYUwAARbpsY8U23u2ZxGOboUxgui0a2OfB OrAxcI6mGhqfNhpHo1GNmvL0M4X+CFIIghx0Wr1srA89t9nJKvIWYqYAKLnyB987Z3Ik ctLdWeY+qIBlqJ7waIpB9b+Xz3v/H0DP+hHO7vjh6DveRfhR4IbpWtI2YwdvqA+Cj5TK aG0w== 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; bh=UD9ycGB1AdB2iWHLig1MDOmhC2Bw6On0cibjUFZbKyA=; b=FWtHoQ0Xphs/GP6XYhVz6GP8idV9xHHRa/QHWVX5VtIwiEKhra9K6LQ5w5h+hPy58x +RHH34V+wXMQLYZFeqWAFvfmnhK6GbnLD5svOCfT5iZ4NLRP/eZG0hTl9LBOon6yszYG 65n0XxvN+p3AI6EQJDx22tLACrpKB6KecFWevy6mYRslwHRPtR9YoCZ4U4mt7YTsXJ/S PtoPsxwiPNAxWwShxF2QsFCikdxM7hkT3Lv3wWnYc/qnGLWU4cAQhF4aCwTVh5yILUqO 7dV223wY8wDWQH2bUd8nrXVn/VV3OLWAIeNB/reMw6b1rGtaH64a57tUxAQetikkuN4A mYDg== X-Gm-Message-State: ALKqPwe0XrZxaYfuOs5oeaMlTKALz/20PDa+TQkDCE6WGPqoDoZ1X8jJ yWOhImd42oAzKMzic3jbSQbYGg== X-Received: by 2002:a1c:7f0a:: with SMTP id a10-v6mr4931805wmd.97.1526648727114; Fri, 18 May 2018 06:05:27 -0700 (PDT) Received: from pb.pb.local ([62.217.45.26]) by smtp.gmail.com with ESMTPSA id m35-v6sm7639980wrm.51.2018.05.18.06.05.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 18 May 2018 06:05:26 -0700 (PDT) From: Roman Pen To: linux-block@vger.kernel.org, linux-rdma@vger.kernel.org Cc: Jens Axboe , Christoph Hellwig , Sagi Grimberg , Bart Van Assche , Or Gerlitz , Doug Ledford , Swapnil Ingle , Danil Kipnis , Jack Wang , Roman Pen , "Paul E . McKenney" , linux-kernel@vger.kernel.org Subject: [PATCH v2 01/26] rculist: introduce list_next_or_null_rr_rcu() Date: Fri, 18 May 2018 15:03:48 +0200 Message-Id: <20180518130413.16997-2-roman.penyaev@profitbricks.com> X-Mailer: git-send-email 2.13.1 In-Reply-To: <20180518130413.16997-1-roman.penyaev@profitbricks.com> References: <20180518130413.16997-1-roman.penyaev@profitbricks.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Function is going to be used in transport over RDMA module in subsequent patches. Function returns next element in round-robin fashion, i.e. head will be skipped. NULL will be returned if list is observed as empty. Signed-off-by: Roman Pen Cc: Paul E. McKenney Cc: linux-kernel@vger.kernel.org --- include/linux/rculist.h | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/include/linux/rculist.h b/include/linux/rculist.h index 127f534fec94..b0840d5ab25a 100644 --- a/include/linux/rculist.h +++ b/include/linux/rculist.h @@ -339,6 +339,25 @@ static inline void list_splice_tail_init_rcu(struct list_head *list, }) /** + * list_next_or_null_rr_rcu - get next list element in round-robin fashion. + * @head: the head for the list. + * @ptr: the list head to take the next element from. + * @type: the type of the struct this is embedded in. + * @memb: the name of the list_head within the struct. + * + * Next element returned in round-robin fashion, i.e. head will be skipped, + * but if list is observed as empty, NULL will be returned. + * + * This primitive may safely run concurrently with the _rcu list-mutation + * primitives such as list_add_rcu() as long as it's guarded by rcu_read_lock(). + */ +#define list_next_or_null_rr_rcu(head, ptr, type, memb) \ +({ \ + list_next_or_null_rcu(head, ptr, type, memb) ?: \ + list_next_or_null_rcu(head, READ_ONCE((ptr)->next), type, memb); \ +}) + +/** * list_for_each_entry_rcu - iterate over rcu list of given type * @pos: the type * to use as a loop cursor. * @head: the head for your list. -- 2.13.1