[RTL/NTOSKRNL]

Rename AVL tree functions with macros when included from Mm. This is necessary since the compiler might chose to not inline these functions (and does so on MSVC debug builds) yet only generate one instance of the function, where 2 different versions are required. This caused RtlAvlTree functions to fail on MSVC builds, since they were calling the functions compiled for Mm AVL trees!

svn path=/trunk/; revision=64664
This commit is contained in:
Timo Kreuzer 2014-10-11 12:40:24 +00:00
parent a747a1b3f5
commit 56af6d9a25
2 changed files with 38 additions and 24 deletions

View file

@ -96,7 +96,7 @@ RtlpFindAvlTableNodeOrParent(IN PRTL_AVL_TABLE Table,
FORCEINLINE FORCEINLINE
VOID VOID
RtlPromoteAvlTreeNode(IN PRTL_BALANCED_LINKS Node) RtlpPromoteAvlTreeNode(IN PRTL_BALANCED_LINKS Node)
{ {
PRTL_BALANCED_LINKS ParentNode, SuperParentNode; PRTL_BALANCED_LINKS ParentNode, SuperParentNode;
PRTL_BALANCED_LINKS *SwapNode1, *SwapNode2; PRTL_BALANCED_LINKS *SwapNode1, *SwapNode2;
@ -139,7 +139,7 @@ RtlpRebalanceAvlTreeNode(IN PRTL_BALANCED_LINKS Node)
if (RtlBalance(ChildNode) == Balance) if (RtlBalance(ChildNode) == Balance)
{ {
/* This performs the rotation described in Knuth A8-A10 for Case 1 */ /* This performs the rotation described in Knuth A8-A10 for Case 1 */
RtlPromoteAvlTreeNode(ChildNode); RtlpPromoteAvlTreeNode(ChildNode);
/* The nodes are now balanced */ /* The nodes are now balanced */
RtlSetBalance(ChildNode, RtlBalancedAvlTree); RtlSetBalance(ChildNode, RtlBalancedAvlTree);
@ -155,8 +155,8 @@ RtlpRebalanceAvlTreeNode(IN PRTL_BALANCED_LINKS Node)
RtlLeftChildAvl(ChildNode) : RtlRightChildAvl(ChildNode); RtlLeftChildAvl(ChildNode) : RtlRightChildAvl(ChildNode);
/* Do the double-rotation described in Knuth A8-A10 for Case 2 */ /* Do the double-rotation described in Knuth A8-A10 for Case 2 */
RtlPromoteAvlTreeNode(SubChildNode); RtlpPromoteAvlTreeNode(SubChildNode);
RtlPromoteAvlTreeNode(SubChildNode); RtlpPromoteAvlTreeNode(SubChildNode);
/* Was the sub-child sharing the same balance as the node? */ /* Was the sub-child sharing the same balance as the node? */
if (RtlBalance(SubChildNode) == Balance) if (RtlBalance(SubChildNode) == Balance)
@ -194,7 +194,7 @@ RtlpRebalanceAvlTreeNode(IN PRTL_BALANCED_LINKS Node)
* The case that remains is that the child was already balanced, so this is * The case that remains is that the child was already balanced, so this is
* This is the rotation required for Case 3 in Knuth A8-A10 * This is the rotation required for Case 3 in Knuth A8-A10
*/ */
RtlPromoteAvlTreeNode(ChildNode); RtlpPromoteAvlTreeNode(ChildNode);
/* Now the child has the opposite weight of the node */ /* Now the child has the opposite weight of the node */
RtlSetBalance(ChildNode, -Balance); RtlSetBalance(ChildNode, -Balance);

View file

@ -28,9 +28,30 @@
#define PRTL_BALANCED_LINKS PMMADDRESS_NODE #define PRTL_BALANCED_LINKS PMMADDRESS_NODE
#define MI_ASSERT(x) ASSERT(x) #define MI_ASSERT(x) ASSERT(x)
/* We need to rename the functions to prevent conflicts when not inlined! */
#define RtlpFindAvlTableNodeOrParent MiFindAvlTableNodeOrParent
#define RtlpPromoteAvlTreeNode MiPromoteAvlTreeNode
#define RtlpRebalanceAvlTreeNode MiRebalanceAvlTreeNode
#define RtlpInsertAvlTreeNode MiInsertAvlTreeNode
#define RtlpDeleteAvlTreeNode MiDeleteAvlTreeNode
/* These are implementation specific */
#define RtlpCopyAvlNodeData MiCopyAvlNodeData
#define RtlpAvlCompareRoutine MiAvlCompareRoutine
#define RtlSetParent MiSetParent
#define RtlSetBalance MiSetBalance
#define RtlBalance MiBalance
#define RtlParentAvl MiParentAvl
#define RtlRightChildAvl MiRightChildAvl
#define RtlLeftChildAvl MiLeftChildAvl
#define RtlIsLeftChildAvl MiIsLeftChildAvl
#define RtlIsRightChildAvl MiIsRightChildAvl
#define RtlInsertAsLeftChildAvl MiInsertAsLeftChildAvl
#define RtlInsertAsRightChildAvl MiInsertAsRightChildAvl
FORCEINLINE FORCEINLINE
VOID VOID
RtlpCopyAvlNodeData(IN PRTL_BALANCED_LINKS Node1, MiCopyAvlNodeData(IN PRTL_BALANCED_LINKS Node1,
IN PRTL_BALANCED_LINKS Node2) IN PRTL_BALANCED_LINKS Node2)
{ {
Node1->u1.Parent = Node2->u1.Parent; Node1->u1.Parent = Node2->u1.Parent;
@ -40,7 +61,7 @@ RtlpCopyAvlNodeData(IN PRTL_BALANCED_LINKS Node1,
FORCEINLINE FORCEINLINE
RTL_GENERIC_COMPARE_RESULTS RTL_GENERIC_COMPARE_RESULTS
RtlpAvlCompareRoutine(IN PRTL_AVL_TABLE Table, MiAvlCompareRoutine(IN PRTL_AVL_TABLE Table,
IN PVOID Buffer, IN PVOID Buffer,
IN PVOID UserData) IN PVOID UserData)
{ {
@ -62,7 +83,7 @@ RtlpAvlCompareRoutine(IN PRTL_AVL_TABLE Table,
FORCEINLINE FORCEINLINE
VOID VOID
RtlSetParent(IN PRTL_BALANCED_LINKS Node, MiSetParent(IN PRTL_BALANCED_LINKS Node,
IN PRTL_BALANCED_LINKS Parent) IN PRTL_BALANCED_LINKS Parent)
{ {
Node->u1.Parent = (PRTL_BALANCED_LINKS)((ULONG_PTR)Parent | (Node->u1.Balance & 0x3)); Node->u1.Parent = (PRTL_BALANCED_LINKS)((ULONG_PTR)Parent | (Node->u1.Balance & 0x3));
@ -70,7 +91,7 @@ RtlSetParent(IN PRTL_BALANCED_LINKS Node,
FORCEINLINE FORCEINLINE
VOID VOID
RtlSetBalance(IN PRTL_BALANCED_LINKS Node, MiSetBalance(IN PRTL_BALANCED_LINKS Node,
IN SCHAR Balance) IN SCHAR Balance)
{ {
Node->u1.Balance = Balance; Node->u1.Balance = Balance;
@ -78,56 +99,49 @@ RtlSetBalance(IN PRTL_BALANCED_LINKS Node,
FORCEINLINE FORCEINLINE
SCHAR SCHAR
RtlBalance(IN PRTL_BALANCED_LINKS Node) MiBalance(IN PRTL_BALANCED_LINKS Node)
{ {
return (SCHAR)Node->u1.Balance; return (SCHAR)Node->u1.Balance;
} }
FORCEINLINE FORCEINLINE
PRTL_BALANCED_LINKS PRTL_BALANCED_LINKS
RtlParentAvl(IN PRTL_BALANCED_LINKS Node) MiParentAvl(IN PRTL_BALANCED_LINKS Node)
{ {
return (PRTL_BALANCED_LINKS)((ULONG_PTR)Node->u1.Parent & ~3); return (PRTL_BALANCED_LINKS)((ULONG_PTR)Node->u1.Parent & ~3);
} }
FORCEINLINE
BOOLEAN
RtlIsRootAvl(IN PRTL_BALANCED_LINKS Node)
{
return (RtlParentAvl(Node) == Node);
}
FORCEINLINE FORCEINLINE
PRTL_BALANCED_LINKS PRTL_BALANCED_LINKS
RtlRightChildAvl(IN PRTL_BALANCED_LINKS Node) MiRightChildAvl(IN PRTL_BALANCED_LINKS Node)
{ {
return Node->RightChild; return Node->RightChild;
} }
FORCEINLINE FORCEINLINE
PRTL_BALANCED_LINKS PRTL_BALANCED_LINKS
RtlLeftChildAvl(IN PRTL_BALANCED_LINKS Node) MiLeftChildAvl(IN PRTL_BALANCED_LINKS Node)
{ {
return Node->LeftChild; return Node->LeftChild;
} }
FORCEINLINE FORCEINLINE
BOOLEAN BOOLEAN
RtlIsLeftChildAvl(IN PRTL_BALANCED_LINKS Node) MiIsLeftChildAvl(IN PRTL_BALANCED_LINKS Node)
{ {
return (RtlLeftChildAvl(RtlParentAvl(Node)) == Node); return (RtlLeftChildAvl(RtlParentAvl(Node)) == Node);
} }
FORCEINLINE FORCEINLINE
BOOLEAN BOOLEAN
RtlIsRightChildAvl(IN PRTL_BALANCED_LINKS Node) MiIsRightChildAvl(IN PRTL_BALANCED_LINKS Node)
{ {
return (RtlRightChildAvl(RtlParentAvl(Node)) == Node); return (RtlRightChildAvl(RtlParentAvl(Node)) == Node);
} }
FORCEINLINE FORCEINLINE
VOID VOID
RtlInsertAsLeftChildAvl(IN PRTL_BALANCED_LINKS Parent, MiInsertAsLeftChildAvl(IN PRTL_BALANCED_LINKS Parent,
IN PRTL_BALANCED_LINKS Node) IN PRTL_BALANCED_LINKS Node)
{ {
Parent->LeftChild = Node; Parent->LeftChild = Node;
@ -136,7 +150,7 @@ RtlInsertAsLeftChildAvl(IN PRTL_BALANCED_LINKS Parent,
FORCEINLINE FORCEINLINE
VOID VOID
RtlInsertAsRightChildAvl(IN PRTL_BALANCED_LINKS Parent, MiInsertAsRightChildAvl(IN PRTL_BALANCED_LINKS Parent,
IN PRTL_BALANCED_LINKS Node) IN PRTL_BALANCED_LINKS Node)
{ {
Parent->RightChild = Node; Parent->RightChild = Node;