public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Michael Kubacki" <michael.kubacki@outlook.com>
To: devel@edk2.groups.io
Cc: Dandan Bi <dandan.bi@intel.com>, Hao A Wu <hao.a.wu@intel.com>,
	Jian J Wang <jian.j.wang@intel.com>,
	Liming Gao <liming.gao@intel.com>,
	Michael D Kinney <michael.d.kinney@intel.com>,
	Sean Brogan <sean.brogan@microsoft.com>
Subject: [PATCH v2 1/7] MdePkg/BaseLib: Add linked list iteration macros
Date: Fri, 10 Apr 2020 13:02:12 -0700	[thread overview]
Message-ID: <MWHPR07MB34400F72A2002503B6177648E9DE0@MWHPR07MB3440.namprd07.prod.outlook.com> (raw)
In-Reply-To: <20200410200218.24992-1-michael.kubacki@outlook.com>

From: Michael Kubacki <michael.kubacki@microsoft.com>

REF:https://bugzilla.tianocore.org/show_bug.cgi?id=1959

The macros EFI_LIST_FOR_EACH and EFI_LIST_FOR_EACH_SAFE have been
duplicated across several drivers. These macros have proven useful and
established a commonly used pattern for linked list iteration.

This change defines the macros in BaseLib.h alongside other generic linked
list macros and functions.

Cc: Dandan Bi <dandan.bi@intel.com>
Cc: Hao A Wu <hao.a.wu@intel.com>
Cc: Jian J Wang <jian.j.wang@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
Cc: Michael D Kinney <michael.d.kinney@intel.com>
Cc: Sean Brogan <sean.brogan@microsoft.com>
Signed-off-by: Michael Kubacki <michael.kubacki@microsoft.com>
Reviewed-by: Guomin Jiang <guomin.jiang@intel.com>
---
 MdePkg/Include/Library/BaseLib.h | 27 ++++++++++++++++++++
 1 file changed, 27 insertions(+)

diff --git a/MdePkg/Include/Library/BaseLib.h b/MdePkg/Include/Library/BaseLib.h
index ecadff8b235e..d066f1be2495 100644
--- a/MdePkg/Include/Library/BaseLib.h
+++ b/MdePkg/Include/Library/BaseLib.h
@@ -4,6 +4,7 @@
 
 Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.<BR>
 Portions copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
+Copyright (c) Microsoft Corporation.<BR>
 SPDX-License-Identifier: BSD-2-Clause-Patent
 
 **/
@@ -2972,6 +2973,32 @@ PathCleanUpDirectories(
 **/
 #define INITIALIZE_LIST_HEAD_VARIABLE(ListHead)  {&(ListHead), &(ListHead)}
 
+/**
+  Iterates over each node in a doubly linked list using each node's forward link.
+
+  @param  Entry     A pointer to a list node used as a loop cursor during iteration
+  @param  ListHead  The head node of the doubly linked list
+
+**/
+#define BASE_LIST_FOR_EACH(Entry, ListHead)    \
+  for(Entry = (ListHead)->ForwardLink; Entry != (ListHead); Entry = Entry->ForwardLink)
+
+/**
+  Iterates over each node in a doubly linked list using each node's forward link
+  with safety against node removal.
+
+  This macro uses NextEntry to temporarily store the next list node so the node
+  pointed to by Entry may be deleted in the current loop iteration step and
+  iteration can continue from the node pointed to by NextEntry.
+
+  @param  Entry     A pointer to a list node used as a loop cursor during iteration
+  @param  NextEntry A pointer to a list node used to temporarily store the next node
+  @param  ListHead  The head node of the doubly linked list
+
+**/
+#define BASE_LIST_FOR_EACH_SAFE(Entry, NextEntry, ListHead)            \
+  for(Entry = (ListHead)->ForwardLink, NextEntry = Entry->ForwardLink;\
+      Entry != (ListHead); Entry = NextEntry, NextEntry = Entry->ForwardLink)
 
 /**
   Checks whether FirstEntry and SecondEntry are part of the same doubly-linked
-- 
2.16.3.windows.1


       reply	other threads:[~2020-04-10 20:02 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20200410200218.24992-1-michael.kubacki@outlook.com>
2020-04-10 20:02 ` Michael Kubacki [this message]
2020-04-10 23:43   ` [EXTERNAL] [edk2-devel] [PATCH v2 1/7] MdePkg/BaseLib: Add linked list iteration macros Bret Barkelew
2020-04-17  1:44   ` Zhiguang Liu
2020-04-10 20:02 ` [PATCH v2 2/7] MdeModulePkg/EhciDxe: Use BaseLib " Michael Kubacki
2020-04-10 23:42   ` [EXTERNAL] [edk2-devel] " Bret Barkelew
2020-04-10 20:02 ` [PATCH v2 3/7] MdeModulePkg/EhciPei: " Michael Kubacki
2020-04-10 23:38   ` [EXTERNAL] [edk2-devel] " Bret Barkelew
2020-04-10 20:02 ` [PATCH v2 4/7] MdeModulePkg/XhciDxe: " Michael Kubacki
2020-04-10 23:37   ` [EXTERNAL] [edk2-devel] " Bret Barkelew
2020-04-10 20:02 ` [PATCH v2 5/7] MdeModulePkg/UfsPassThruDxe: " Michael Kubacki
2020-04-10 23:37   ` [EXTERNAL] [edk2-devel] " Bret Barkelew
2020-04-10 20:02 ` [PATCH v2 6/7] MdeModulePkg/RamDiskDxe: " Michael Kubacki
2020-04-10 23:37   ` [EXTERNAL] [edk2-devel] " Bret Barkelew
2020-04-10 20:02 ` [PATCH v2 7/7] SecurityPkg/HddPassword: " Michael Kubacki
2020-04-10 23:36   ` [EXTERNAL] [edk2-devel] " Bret Barkelew

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=MWHPR07MB34400F72A2002503B6177648E9DE0@MWHPR07MB3440.namprd07.prod.outlook.com \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox