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 v1 1/7] MdePkg/BaseLib: Add linked list iteration macros
Date: Thu, 9 Apr 2020 13:05:08 -0700 [thread overview]
Message-ID: <DM5PR07MB3435E23AA85B4C1EB9D39022E9C10@DM5PR07MB3435.namprd07.prod.outlook.com> (raw)
In-Reply-To: <20200409200514.32796-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>
---
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
next parent reply other threads:[~2020-04-09 20:06 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20200409200514.32796-1-michael.kubacki@outlook.com>
2020-04-09 20:05 ` Michael Kubacki [this message]
2020-04-10 1:45 ` [edk2-devel] [PATCH v1 1/7] MdePkg/BaseLib: Add linked list iteration macros Guomin Jiang
2020-04-09 20:05 ` [PATCH v1 2/7] MdeModulePkg/EhciDxe: Use BaseLib " Michael Kubacki
2020-04-10 1:46 ` [edk2-devel] " Guomin Jiang
2020-04-09 20:05 ` [PATCH v1 3/7] MdeModulePkg/EhciPei: " Michael Kubacki
2020-04-10 1:47 ` [edk2-devel] " Guomin Jiang
2020-04-09 20:05 ` [PATCH v1 4/7] MdeModulePkg/XhciDxe: " Michael Kubacki
2020-04-10 1:47 ` [edk2-devel] " Guomin Jiang
2020-04-09 20:05 ` [PATCH v1 5/7] MdeModulePkg/UfsPassThruDxe: " Michael Kubacki
2020-04-09 20:05 ` [PATCH v1 6/7] MdeModulePkg/RamDiskDxe: " Michael Kubacki
2020-04-09 20:05 ` [PATCH v1 7/7] SecurityPkg/HddPassword: " Michael Kubacki
2020-04-09 23:10 ` Yao, Jiewen
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=DM5PR07MB3435E23AA85B4C1EB9D39022E9C10@DM5PR07MB3435.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