VirtualBox

Changeset 7 in kStuff for trunk/include/k/kAvlTmpl/kAvlDestroy.h


Ignore:
Timestamp:
Feb 4, 2008 2:08:02 AM (17 years ago)
Author:
bird
Message:

kAVL: Implemented locking, root node and a direct cache.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/k/kAvlTmpl/kAvlDestroy.h

    r2 r7  
    4141 *          made on it. Note that the node we fail on will be considered dead and
    4242 *          no action is taken to link it back into the tree.
    43  * @param   ppTree          Pointer to the AVL-tree root node pointer.
     43 * @param   pRoot           Pointer to the AVL-tree root structure.
    4444 * @param   pfnCallBack     Pointer to callback function.
    4545 * @param   pvUser          User parameter passed on to the callback function.
    4646 */
    47 KAVL_DECL(int) KAVL_FN(Destroy)(KAVLTREEPTR *ppTree, KAVL_TYPE(PFN,CALLBACK) pfnCallBack, void *pvUser)
     47KAVL_DECL(int) KAVL_FN(Destroy)(KAVLROOT *pRoot, KAVL_TYPE(PFN,CALLBACK) pfnCallBack, void *pvUser)
    4848{
     49#ifdef KAVL_LOOKTHRU
     50    unsigned    i;
     51#endif
    4952    unsigned    cEntries;
    5053    KAVLNODE   *apEntries[KAVL_MAX_STACK];
    5154    int         rc;
    5255
    53     if (*ppTree == KAVL_NULL)
     56    KAVL_WRITE_LOCK(pRoot);
     57    if (pRoot->mpRoot == KAVL_NULL)
     58    {
     59        KAVL_WRITE_UNLOCK(pRoot);
    5460        return 0;
     61    }
     62
     63#ifdef KAVL_LOOKTHRU
     64    /*
     65     * Kill the lookthru cache.
     66     */
     67    for (i = 0; i < (KAVL_LOOKTHRU); i++)
     68        pRoot->maLookthru[i] = KAVL_NULL;
     69#endif
    5570
    5671    cEntries = 1;
    57     apEntries[0] = KAVL_GET_POINTER(ppTree);
     72    apEntries[0] = KAVL_GET_POINTER(&pRoot->mpRoot);
    5873    while (cEntries > 0)
    5974    {
     
    8095                rc = pfnCallBack(pEqual, pvUser);
    8196                if (rc)
     97                {
     98                    KAVL_WRITE_UNLOCK(pRoot);
    8299                    return rc;
     100                }
    83101            }
    84102#endif
     
    96114            }
    97115            else
    98                 *ppTree = KAVL_NULL;
     116                pRoot->mpRoot = KAVL_NULL;
    99117
    100118            kHlpAssert(pNode->mpLeft == KAVL_NULL);
     
    102120            rc = pfnCallBack(pNode, pvUser);
    103121            if (rc)
     122            {
     123                KAVL_WRITE_UNLOCK(pRoot);
    104124                return rc;
     125            }
    105126        }
    106127    } /* while */
    107     kHlpAssert(*ppTree == KAVL_NULL);
     128    kHlpAssert(pRoot->mpRoot == KAVL_NULL);
    108129
     130    KAVL_WRITE_UNLOCK(pRoot);
    109131    return 0;
    110132}
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette