Changeset 93695 in vbox for trunk/include/iprt/cpp
- Timestamp:
- Feb 11, 2022 12:07:23 PM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/iprt/cpp/hardavlrange.h
r93693 r93695 47 47 #ifdef RT_STRICT 48 48 # define RTHARDAVL_STRICT_CHECK_HEIGHTS(a_pNode, a_pAvlStack, a_cStackEntries) do { \ 49 NodeType * const pLeftNodeX = a_pAllocator->ptrFromInt( (a_pNode)->idxLeft); \49 NodeType * const pLeftNodeX = a_pAllocator->ptrFromInt(readIdx(&(a_pNode)->idxLeft)); \ 50 50 AssertReturnStmt(a_pAllocator->isPtrRetOkay(pLeftNodeX), m_cErrors++, a_pAllocator->ptrErrToStatus((a_pNode))); \ 51 NodeType * const pRightNodeX = a_pAllocator->ptrFromInt( (a_pNode)->idxRight); \51 NodeType * const pRightNodeX = a_pAllocator->ptrFromInt(readIdx(&(a_pNode)->idxRight)); \ 52 52 AssertReturnStmt(a_pAllocator->isPtrRetOkay(pRightNodeX), m_cErrors++, a_pAllocator->ptrErrToStatus((a_pNode))); \ 53 53 uint8_t const cLeftHeightX = pLeftNodeX ? pLeftNodeX->cHeight : 0; \ … … 125 125 /** @} */ 126 126 127 /** 128 * Read an index value trying to prevent the compiler from re-reading it. 129 */ 130 DECL_FORCE_INLINE(uint32_t) readIdx(uint32_t volatile *pidx) 131 { 132 uint32_t idx = *pidx; 133 ASMCompilerBarrier(); 134 return idx; 135 } 136 137 127 138 RTCHardAvlRangeTree() 128 139 : m_idxRoot(0) … … 170 181 for (;;) 171 182 { 172 NodeType *pCurNode = a_pAllocator->ptrFromInt( *pidxCurNode);183 NodeType *pCurNode = a_pAllocator->ptrFromInt(readIdx(pidxCurNode)); 173 184 AssertMsgReturnStmt(a_pAllocator->isPtrRetOkay(pCurNode), ("*pidxCurNode=%#x pCurNode=%p\n", *pidxCurNode, pCurNode), 174 185 m_cErrors++, a_pAllocator->ptrErrToStatus(pCurNode)); … … 271 282 for (;;) 272 283 { 273 pDeleteNode = a_pAllocator->ptrFromInt( *pidxDeleteNode);284 pDeleteNode = a_pAllocator->ptrFromInt(readIdx(pidxDeleteNode)); 274 285 AssertMsgReturnStmt(a_pAllocator->isPtrRetOkay(pDeleteNode), 275 286 ("*pidxCurNode=%#x pDeleteNode=%p\n", *pidxDeleteNode, pDeleteNode), … … 309 320 * Do the deletion. 310 321 */ 311 uint32_t const idxDeleteLeftNode = pDeleteNode->idxLeft;322 uint32_t const idxDeleteLeftNode = readIdx(&pDeleteNode->idxLeft); 312 323 if (idxDeleteLeftNode != a_pAllocator->kNilIndex) 313 324 { … … 320 331 m_cErrors++, a_pAllocator->ptrErrToStatus(pDeleteLeftNode)); 321 332 322 uint32_t const idxDeleteRightNode = pDeleteNode->idxRight;333 uint32_t const idxDeleteRightNode = readIdx(&pDeleteNode->idxRight); 323 334 AssertReturnStmt(a_pAllocator->isIntValid(idxDeleteRightNode), m_cErrors++, VERR_HARDAVL_INDEX_OUT_OF_BOUNDS); 324 335 … … 330 341 RTHARDAVL_STRICT_CHECK_HEIGHTS(pLeftBiggestNode, &AVLStack, AVLStack.cEntries); 331 342 332 while (pLeftBiggestNode->idxRight != a_pAllocator->kNilIndex) 343 uint32_t idxRightTmp; 344 while ((idxRightTmp = readIdx(&pLeftBiggestNode->idxRight)) != a_pAllocator->kNilIndex) 333 345 { 334 346 unsigned const cEntries = AVLStack.cEntries; … … 346 358 347 359 pidxLeftBiggest = &pLeftBiggestNode->idxRight; 348 idxLeftBiggestNode = pLeftBiggestNode->idxRight;349 pLeftBiggestNode = a_pAllocator->ptrFromInt(idx LeftBiggestNode);360 idxLeftBiggestNode = idxRightTmp; 361 pLeftBiggestNode = a_pAllocator->ptrFromInt(idxRightTmp); 350 362 AssertMsgReturnStmt(a_pAllocator->isPtrRetOkay(pLeftBiggestNode), 351 363 ("idxLeftBiggestNode=%#x pLeftBiggestNode=%p\n", idxLeftBiggestNode, pLeftBiggestNode), … … 354 366 } 355 367 356 uint32_t const idxLeftBiggestLeftNode = pLeftBiggestNode->idxLeft;368 uint32_t const idxLeftBiggestLeftNode = readIdx(&pLeftBiggestNode->idxLeft); 357 369 AssertReturnStmt(a_pAllocator->isIntValid(idxLeftBiggestLeftNode), m_cErrors++, VERR_HARDAVL_INDEX_OUT_OF_BOUNDS); 358 370 … … 374 386 { 375 387 /* No left node, just pull up the right one. */ 376 uint32_t const idxDeleteRightNode = pDeleteNode->idxRight;388 uint32_t const idxDeleteRightNode = readIdx(&pDeleteNode->idxRight); 377 389 AssertReturnStmt(a_pAllocator->isIntValid(idxDeleteRightNode), m_cErrors++, VERR_HARDAVL_INDEX_OUT_OF_BOUNDS); 378 390 *pidxDeleteNode = idxDeleteRightNode; … … 398 410 *a_ppFound = NULL; 399 411 400 NodeType *pNode = a_pAllocator->ptrFromInt( m_idxRoot);412 NodeType *pNode = a_pAllocator->ptrFromInt(readIdx(&m_idxRoot)); 401 413 AssertMsgReturnStmt(a_pAllocator->isPtrRetOkay(pNode), ("m_idxRoot=%#x pNode=%p\n", m_idxRoot, pNode), 402 414 m_cErrors++, a_pAllocator->ptrErrToStatus(pNode)); … … 423 435 AVLStack.apidxEntries[AVLStack.cEntries++] = &pNode->idxLeft; 424 436 #endif 425 uint32_t const idxLeft = pNode->idxLeft;437 uint32_t const idxLeft = readIdx(&pNode->idxLeft); 426 438 pNode = a_pAllocator->ptrFromInt(idxLeft); 427 439 AssertMsgReturnStmt(a_pAllocator->isPtrRetOkay(pNode), ("idxLeft=%#x pNode=%p\n", idxLeft, pNode), … … 433 445 AVLStack.apidxEntries[AVLStack.cEntries++] = &pNode->idxRight; 434 446 #endif 435 uint32_t const idxRight = pNode->idxRight;447 uint32_t const idxRight = readIdx(&pNode->idxRight); 436 448 pNode = a_pAllocator->ptrFromInt(idxRight); 437 449 AssertMsgReturnStmt(a_pAllocator->isPtrRetOkay(pNode), ("idxRight=%#x pNode=%p\n", idxRight, pNode), … … 466 478 int doWithAllFromLeft(RTCHardAvlTreeSlabAllocator<NodeType> *a_pAllocator, PFNCALLBACK a_pfnCallBack, void *a_pvUser) 467 479 { 468 NodeType *pNode = a_pAllocator->ptrFromInt( m_idxRoot);480 NodeType *pNode = a_pAllocator->ptrFromInt(readIdx(&m_idxRoot)); 469 481 AssertMsgReturnStmt(a_pAllocator->isPtrRetOkay(pNode), ("m_idxRoot=%#x pNode=%p\n", m_idxRoot, pNode), 470 482 m_cErrors++, a_pAllocator->ptrErrToStatus(pNode)); … … 492 504 abState[cEntries - 1] = 1; 493 505 494 NodeType * const pLeftNode = a_pAllocator->ptrFromInt( pNode->idxLeft);506 NodeType * const pLeftNode = a_pAllocator->ptrFromInt(readIdx(&pNode->idxLeft)); 495 507 AssertMsgReturnStmt(a_pAllocator->isPtrRetOkay(pLeftNode), 496 508 ("idxLeft=%#x pLeftNode=%p\n", pNode->idxLeft, pLeftNode), … … 528 540 return rc; 529 541 530 NodeType * const pRightNode = a_pAllocator->ptrFromInt( pNode->idxRight);542 NodeType * const pRightNode = a_pAllocator->ptrFromInt(readIdx(&pNode->idxRight)); 531 543 AssertMsgReturnStmt(a_pAllocator->isPtrRetOkay(pRightNode), 532 544 ("idxRight=%#x pRightNode=%p\n", pNode->idxRight, pRightNode), … … 589 601 int destroy(RTCHardAvlTreeSlabAllocator<NodeType> *a_pAllocator, PFNDESTROYCALLBACK a_pfnCallBack = NULL, void *a_pvUser = NULL) 590 602 { 591 NodeType *pNode = a_pAllocator->ptrFromInt( m_idxRoot);603 NodeType *pNode = a_pAllocator->ptrFromInt(readIdx(&m_idxRoot)); 592 604 AssertMsgReturnStmt(a_pAllocator->isPtrRetOkay(pNode), ("m_idxRoot=%#x pNode=%p\n", m_idxRoot, pNode), 593 605 m_cErrors++, a_pAllocator->ptrErrToStatus(pNode)); … … 615 627 abState[cEntries - 1] = 1; 616 628 617 NodeType * const pLeftNode = a_pAllocator->ptrFromInt( pNode->idxLeft);629 NodeType * const pLeftNode = a_pAllocator->ptrFromInt(readIdx(&pNode->idxLeft)); 618 630 AssertMsgReturnStmt(a_pAllocator->isPtrRetOkay(pLeftNode), 619 631 ("idxLeft=%#x pLeftNode=%p\n", pNode->idxLeft, pLeftNode), … … 645 657 abState[cEntries - 1] = 2; 646 658 647 NodeType * const pRightNode = a_pAllocator->ptrFromInt( pNode->idxRight);659 NodeType * const pRightNode = a_pAllocator->ptrFromInt(readIdx(&pNode->idxRight)); 648 660 AssertMsgReturnStmt(a_pAllocator->isPtrRetOkay(pRightNode), 649 661 ("idxRight=%#x pRightNode=%p\n", pNode->idxRight, pRightNode), … … 697 709 uint8_t getHeight(RTCHardAvlTreeSlabAllocator<NodeType> *a_pAllocator) 698 710 { 699 NodeType *pNode = a_pAllocator->ptrFromInt( m_idxRoot);711 NodeType *pNode = a_pAllocator->ptrFromInt(readIdx(&m_idxRoot)); 700 712 AssertMsgReturnStmt(a_pAllocator->isPtrRetOkay(pNode), ("m_idxRoot=%#x pNode=%p\n", m_idxRoot, pNode), 701 713 m_cErrors++, UINT8_MAX); … … 730 742 { 731 743 NodeType *pNode = a_pAllocator->ptrFromInt(a_idxRoot); 732 printTree(a_pAllocator, pNode->idxRight, a_uLevel + 1, a_uMaxLevel, "/ ");744 printTree(a_pAllocator, readIdx(&pNode->idxRight), a_uLevel + 1, a_uMaxLevel, "/ "); 733 745 RTAssertMsg2("%*s%#x/%u\n", a_uLevel * 6, a_pszDir, a_idxRoot, pNode->cHeight); 734 printTree(a_pAllocator, pNode->idxLeft, a_uLevel + 1, a_uMaxLevel, "\\ ");746 printTree(a_pAllocator, readIdx(&pNode->idxLeft), a_uLevel + 1, a_uMaxLevel, "\\ "); 735 747 } 736 748 else … … 807 819 /* pop */ 808 820 uint32_t * const pidxNode = a_pStack->apidxEntries[--a_pStack->cEntries]; 809 uint32_t const idxNode = *pidxNode;821 uint32_t const idxNode = readIdx(pidxNode); 810 822 NodeType * const pNode = a_pAllocator->ptrFromInt(idxNode); 811 823 AssertMsgReturnStmt(a_pAllocator->isPtrRetOkay(pNode), … … 814 826 815 827 /* Read node properties: */ 816 uint32_t const idxLeftNode = pNode->idxLeft;828 uint32_t const idxLeftNode = readIdx(&pNode->idxLeft); 817 829 NodeType * const pLeftNode = a_pAllocator->ptrFromInt(idxLeftNode); 818 830 AssertMsgReturnStmt(a_pAllocator->isPtrRetOkay(pLeftNode), … … 820 832 m_cErrors++, a_pAllocator->ptrErrToStatus(pLeftNode)); 821 833 822 uint32_t const idxRightNode = pNode->idxRight;834 uint32_t const idxRightNode = readIdx(&pNode->idxRight); 823 835 NodeType * const pRightNode = a_pAllocator->ptrFromInt(idxRightNode); 824 836 AssertMsgReturnStmt(a_pAllocator->isPtrRetOkay(pRightNode), … … 838 850 AssertReturnStmt(pLeftNode, m_cErrors++, VERR_HARDAVL_UNEXPECTED_NULL_LEFT); 839 851 840 uint32_t const idxLeftLeftNode = pLeftNode->idxLeft;852 uint32_t const idxLeftLeftNode = readIdx(&pLeftNode->idxLeft); 841 853 NodeType * const pLeftLeftNode = a_pAllocator->ptrFromInt(idxLeftLeftNode); 842 854 AssertMsgReturnStmt(a_pAllocator->isPtrRetOkay(pLeftLeftNode), … … 844 856 m_cErrors++, a_pAllocator->ptrErrToStatus(pLeftLeftNode)); 845 857 846 uint32_t const idxLeftRightNode = pLeftNode->idxRight;858 uint32_t const idxLeftRightNode = readIdx(&pLeftNode->idxRight); 847 859 NodeType * const pLeftRightNode = a_pAllocator->ptrFromInt(idxLeftRightNode); 848 860 AssertMsgReturnStmt(a_pAllocator->isPtrRetOkay(pLeftRightNode), … … 868 880 AssertReturnStmt(pLeftRightNode, m_cErrors++, VERR_HARDAVL_UNEXPECTED_NULL_RIGHT); 869 881 870 uint32_t const idxLeftRightLeftNode = pLeftRightNode->idxLeft;882 uint32_t const idxLeftRightLeftNode = readIdx(&pLeftRightNode->idxLeft); 871 883 AssertReturnStmt(a_pAllocator->isIntValid(idxLeftRightLeftNode), m_cErrors++, VERR_HARDAVL_INDEX_OUT_OF_BOUNDS); 872 uint32_t const idxLeftRightRightNode = pLeftRightNode->idxRight;884 uint32_t const idxLeftRightRightNode = readIdx(&pLeftRightNode->idxRight); 873 885 AssertReturnStmt(a_pAllocator->isIntValid(idxLeftRightRightNode), m_cErrors++, VERR_HARDAVL_INDEX_OUT_OF_BOUNDS); 874 886 pLeftNode->idxRight = idxLeftRightLeftNode; … … 891 903 AssertReturnStmt(pRightNode, m_cErrors++, VERR_HARDAVL_UNEXPECTED_NULL_RIGHT); 892 904 893 uint32_t const idxRightLeftNode = pRightNode->idxLeft;905 uint32_t const idxRightLeftNode = readIdx(&pRightNode->idxLeft); 894 906 NodeType * const pRightLeftNode = a_pAllocator->ptrFromInt(idxRightLeftNode); 895 907 AssertMsgReturnStmt(a_pAllocator->isPtrRetOkay(pRightLeftNode), … … 897 909 m_cErrors++, a_pAllocator->ptrErrToStatus(pRightLeftNode)); 898 910 899 uint32_t const idxRightRightNode = pRightNode->idxRight;911 uint32_t const idxRightRightNode = readIdx(&pRightNode->idxRight); 900 912 NodeType * const pRightRightNode = a_pAllocator->ptrFromInt(idxRightRightNode); 901 913 AssertMsgReturnStmt(a_pAllocator->isPtrRetOkay(pRightRightNode), … … 924 936 AssertReturnStmt(pRightLeftNode, m_cErrors++, VERR_HARDAVL_UNEXPECTED_NULL_LEFT); 925 937 926 uint32_t const idxRightLeftRightNode = pRightLeftNode->idxRight;938 uint32_t const idxRightLeftRightNode = readIdx(&pRightLeftNode->idxRight); 927 939 AssertReturnStmt(a_pAllocator->isIntValid(idxRightLeftRightNode), m_cErrors++, VERR_HARDAVL_INDEX_OUT_OF_BOUNDS); 928 uint32_t const idxRightLeftLeftNode = pRightLeftNode->idxLeft;940 uint32_t const idxRightLeftLeftNode = readIdx(&pRightLeftNode->idxLeft); 929 941 AssertReturnStmt(a_pAllocator->isIntValid(idxRightLeftLeftNode), m_cErrors++, VERR_HARDAVL_INDEX_OUT_OF_BOUNDS); 930 942 pRightNode->idxLeft = idxRightLeftRightNode;
Note:
See TracChangeset
for help on using the changeset viewer.