VirtualBox

Changeset 19865 in vbox


Ignore:
Timestamp:
May 20, 2009 1:33:14 PM (15 years ago)
Author:
vboxsync
Message:

IPRT: Made handletable.cpp and handletablectx.cpp build cleanly as C.

Location:
trunk/src/VBox/Runtime/common/misc
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/common/misc/handletable.cpp

    r10789 r19865  
    4848                                  PFNRTHANDLETABLERETAIN pfnRetain, void *pvUser)
    4949{
     50    PRTHANDLETABLEINT   pThis;
     51    uint32_t            cLevel1;
     52    size_t              cb;
     53
    5054    /*
    5155     * Validate input.
     
    6569    cMax = ((cMax + RTHT_LEVEL2_ENTRIES - 1) / RTHT_LEVEL2_ENTRIES) * RTHT_LEVEL2_ENTRIES;
    6670
    67     uint32_t const cLevel1 = cMax / RTHT_LEVEL2_ENTRIES;
     71    cLevel1 = cMax / RTHT_LEVEL2_ENTRIES;
    6872    Assert(cLevel1 * RTHT_LEVEL2_ENTRIES == cMax);
    6973
     
    7276     * if it's below the threshold size.
    7377     */
    74     size_t cb = sizeof(RTHANDLETABLEINT);
     78    cb = sizeof(RTHANDLETABLEINT);
    7579    if (cLevel1 < RTHT_LEVEL1_DYN_ALLOC_THRESHOLD)
    7680        cb = RT_ALIGN(cb, sizeof(void *)) + cLevel1 * sizeof(void *);
    77     PRTHANDLETABLEINT pThis = (PRTHANDLETABLEINT)RTMemAllocZ(cb);
     81    pThis = (PRTHANDLETABLEINT)RTMemAllocZ(cb);
    7882    if (!pThis)
    7983        return VERR_NO_MEMORY;
     
    121125RTDECL(int) RTHandleTableDestroy(RTHANDLETABLE hHandleTable, PFNRTHANDLETABLEDELETE pfnDelete, void *pvUser)
    122126{
     127    PRTHANDLETABLEINT   pThis;
     128    RTSPINLOCKTMP       Tmp;
     129    uint32_t            i1;
     130    uint32_t            i;
     131
    123132    /*
    124133     * Validate input, quitely ignore the NIL handle.
     
    126135    if (hHandleTable == NIL_RTHANDLETABLE)
    127136        return VINF_SUCCESS;
    128     PRTHANDLETABLEINT pThis = (PRTHANDLETABLEINT)hHandleTable;
     137    pThis = (PRTHANDLETABLEINT)hHandleTable;
    129138    AssertPtrReturn(pThis, VERR_INVALID_HANDLE);
    130139    AssertReturn(pThis->u32Magic == RTHANDLETABLE_MAGIC, VERR_INVALID_HANDLE);
     
    135144     * Then kill the lock.
    136145     */
    137     RTSPINLOCKTMP Tmp;
    138146    rtHandleTableLock(pThis, &Tmp);
    139147    ASMAtomicWriteU32(&pThis->u32Magic, ~RTHANDLETABLE_MAGIC);
     
    157165        if (pThis->fFlags & RTHANDLETABLE_FLAGS_CONTEXT)
    158166        {
    159             for (uint32_t i1 = 0; cLeft > 0 && i1 < pThis->cLevel1; i1++)
     167            for (i1 = 0; cLeft > 0 && i1 < pThis->cLevel1; i1++)
    160168            {
    161169                PRTHTENTRYCTX paTable = (PRTHTENTRYCTX)pThis->papvLevel1[i1];
    162170                if (paTable)
    163                     for (uint32_t i = 0; i < RTHT_LEVEL2_ENTRIES; i++)
     171                    for (i = 0; i < RTHT_LEVEL2_ENTRIES; i++)
    164172                        if (!RTHT_IS_FREE(paTable[i].pvObj))
    165173                        {
     
    173181        else
    174182        {
    175             for (uint32_t i1 = 0; cLeft > 0 && i1 < pThis->cLevel1; i1++)
     183            for (i1 = 0; cLeft > 0 && i1 < pThis->cLevel1; i1++)
    176184            {
    177185                PRTHTENTRY paTable = (PRTHTENTRY)pThis->papvLevel1[i1];
    178186                if (paTable)
    179                     for (uint32_t i = 0; i < RTHT_LEVEL2_ENTRIES; i++)
     187                    for (i = 0; i < RTHT_LEVEL2_ENTRIES; i++)
    180188                        if (!RTHT_IS_FREE(paTable[i].pvObj))
    181189                        {
     
    193201     * Free the memory.
    194202     */
    195     for (uint32_t i1 = 0; i1 < pThis->cLevel1; i1++)
     203    for (i1 = 0; i1 < pThis->cLevel1; i1++)
    196204        if (pThis->papvLevel1[i1])
    197205        {
  • trunk/src/VBox/Runtime/common/misc/handletablectx.cpp

    r10790 r19865  
    4646RTDECL(int)     RTHandleTableAllocWithCtx(RTHANDLETABLE hHandleTable, void *pvObj, void *pvCtx, uint32_t *ph)
    4747{
     48    PRTHANDLETABLEINT   pThis;
     49    RTSPINLOCKTMP       Tmp;
     50    int                 rc;
     51
    4852    /* validate the input */
    49     PRTHANDLETABLEINT pThis = (PRTHANDLETABLEINT)hHandleTable;
     53    pThis = (PRTHANDLETABLEINT)hHandleTable;
    5054    AssertPtrReturn(pThis, VERR_INVALID_HANDLE);
    5155    AssertReturn(pThis->u32Magic == RTHANDLETABLE_MAGIC, VERR_INVALID_HANDLE);
     
    5862     * Allocation loop.
    5963     */
    60     RTSPINLOCKTMP Tmp;
    6164    rtHandleTableLock(pThis, &Tmp);
    6265
    63     int rc;
    6466    do
    6567    {
     
    7072        if (i != NIL_RTHT_INDEX)
    7173        {
    72             PRTHTENTRYFREE pFree = (PRTHTENTRYFREE)rtHandleTableLookupWithCtxIdx(pThis, i);
     74            PRTHTENTRYCTX   pEntry;
     75            PRTHTENTRYFREE  pFree = (PRTHTENTRYFREE)rtHandleTableLookupWithCtxIdx(pThis, i);
    7376            Assert(pFree);
    7477            if (i == pThis->iFreeTail)
     
    8285             * Setup the entry and return.
    8386             */
    84             PRTHTENTRYCTX pEntry = (PRTHTENTRYCTX)pFree;
     87            pEntry = (PRTHTENTRYCTX)pFree;
    8588            pEntry->pvObj = pvObj;
    8689            pEntry->pvCtx = pvCtx;
     
    98101        else
    99102        {
     103            void          **papvLevel1;
     104            uint32_t        iLevel1New;
     105            PRTHTENTRYCTX   paTable;
     106
    100107            /*
    101108             * Do we have to expand the 1st level table too?
    102109             */
    103             uint32_t const iLevel1 = pThis->cCur / RTHT_LEVEL2_ENTRIES;
    104             uint32_t cLevel1 = iLevel1 >= pThis->cLevel1
    105                              ? pThis->cLevel1 + PAGE_SIZE / sizeof(void *)
    106                              : 0;
     110            uint32_t const  iLevel1 = pThis->cCur / RTHT_LEVEL2_ENTRIES;
     111            uint32_t        cLevel1 = iLevel1 >= pThis->cLevel1
     112                                    ? pThis->cLevel1 + PAGE_SIZE / sizeof(void *)
     113                                    : 0;
    107114            if (cLevel1 > pThis->cMax / RTHT_LEVEL2_ENTRIES)
    108115                cLevel1 = pThis->cMax / RTHT_LEVEL2_ENTRIES;
     
    116123             */
    117124            rc = VERR_TRY_AGAIN;
    118             void **papvLevel1 = NULL;
     125            papvLevel1 = NULL;
    119126            if (cLevel1)
    120127            {
     
    124131            }
    125132
    126             PRTHTENTRYCTX paTable = (PRTHTENTRYCTX)RTMemAlloc(sizeof(*paTable) * RTHT_LEVEL2_ENTRIES);
     133            paTable = (PRTHTENTRYCTX)RTMemAlloc(sizeof(*paTable) * RTHT_LEVEL2_ENTRIES);
    127134            if (!paTable)
    128135            {
     
    144151                if (cLevel1 > pThis->cLevel1)
    145152                {
     153                    void **papvTmp;
     154
    146155                    /* Replace the 1st level table. */
    147156                    memcpy(papvLevel1, pThis->papvLevel1, sizeof(void *) * pThis->cLevel1);
    148157                    memset(&papvLevel1[pThis->cLevel1], 0, sizeof(void *) * (cLevel1 - pThis->cLevel1));
    149158                    pThis->cLevel1 = cLevel1;
    150                     void **papvTmp = pThis->papvLevel1;
     159                    papvTmp = pThis->papvLevel1;
    151160                    pThis->papvLevel1 = papvLevel1;
    152161                    papvLevel1 = papvTmp;
     
    160169
    161170            /* insert the table we allocated. */
    162             uint32_t iLevel1New = pThis->cCur / RTHT_LEVEL2_ENTRIES;
     171            iLevel1New = pThis->cCur / RTHT_LEVEL2_ENTRIES;
    163172            if (    iLevel1New < pThis->cLevel1
    164173                &&  pThis->cCur < pThis->cMax)
    165174            {
     175                uint32_t i;
     176
    166177                pThis->papvLevel1[iLevel1New] = paTable;
    167178
    168179                /* link all entries into a free list. */
    169180                Assert(!(pThis->cCur % RTHT_LEVEL2_ENTRIES));
    170                 for (uint32_t i = 0; i < RTHT_LEVEL2_ENTRIES - 1; i++)
     181                for (i = 0; i < RTHT_LEVEL2_ENTRIES - 1; i++)
    171182                {
    172183                    RTHT_SET_FREE_IDX((PRTHTENTRYFREE)&paTable[i], i + 1 + pThis->cCur);
     
    209220RTDECL(void *)  RTHandleTableLookupWithCtx(RTHANDLETABLE hHandleTable, uint32_t h, void *pvCtx)
    210221{
     222    void               *pvObj = NULL;
     223    PRTHTENTRYCTX       pEntry;
     224    PRTHANDLETABLEINT   pThis;
     225    RTSPINLOCKTMP       Tmp;
     226
    211227    /* validate the input */
    212     PRTHANDLETABLEINT pThis = (PRTHANDLETABLEINT)hHandleTable;
     228    pThis = (PRTHANDLETABLEINT)hHandleTable;
    213229    AssertPtrReturn(pThis, NULL);
    214230    AssertReturn(pThis->u32Magic == RTHANDLETABLE_MAGIC, NULL);
    215231    AssertReturn(pThis->fFlags & RTHANDLETABLE_FLAGS_CONTEXT, NULL);
    216232
    217     void *pvObj = NULL;
    218233
    219234    /* acquire the lock */
    220     RTSPINLOCKTMP Tmp;
    221235    rtHandleTableLock(pThis, &Tmp);
    222236
     
    224238     * Perform the lookup and retaining.
    225239     */
    226     PRTHTENTRYCTX pEntry = rtHandleTableLookupWithCtx(pThis, h);
     240    pEntry = rtHandleTableLookupWithCtx(pThis, h);
    227241    if (pEntry && pEntry->pvCtx == pvCtx)
    228242    {
     
    249263RTDECL(void *)  RTHandleTableFreeWithCtx(RTHANDLETABLE hHandleTable, uint32_t h, void *pvCtx)
    250264{
     265    void               *pvObj = NULL;
     266    PRTHTENTRYCTX       pEntry;
     267    PRTHANDLETABLEINT   pThis;
     268    RTSPINLOCKTMP       Tmp;
     269
    251270    /* validate the input */
    252     PRTHANDLETABLEINT pThis = (PRTHANDLETABLEINT)hHandleTable;
     271    pThis = (PRTHANDLETABLEINT)hHandleTable;
    253272    AssertPtrReturn(pThis, NULL);
    254273    AssertReturn(pThis->u32Magic == RTHANDLETABLE_MAGIC, NULL);
    255274    AssertReturn(pThis->fFlags & RTHANDLETABLE_FLAGS_CONTEXT, NULL);
    256275
    257     void *pvObj = NULL;
    258276
    259277    /* acquire the lock */
    260     RTSPINLOCKTMP Tmp;
    261278    rtHandleTableLock(pThis, &Tmp);
    262279
     
    264281     * Perform the lookup and retaining.
    265282     */
    266     PRTHTENTRYCTX pEntry = rtHandleTableLookupWithCtx(pThis, h);
     283    pEntry = rtHandleTableLookupWithCtx(pThis, h);
    267284    if (pEntry && pEntry->pvCtx == pvCtx)
    268285    {
     
    282299            if (pvObj)
    283300            {
     301                PRTHTENTRYFREE  pFree;
     302                uint32_t        i;
     303
    284304                pEntry->pvCtx = (void *)~(uintptr_t)7;
    285305
    286                 PRTHTENTRYFREE pFree = (PRTHTENTRYFREE)pEntry;
     306                pFree = (PRTHTENTRYFREE)pEntry;
    287307                RTHT_SET_FREE_IDX(pFree, NIL_RTHT_INDEX);
    288308
    289                 uint32_t const i = h - pThis->uBase;
     309                i = h - pThis->uBase;
    290310                if (pThis->iFreeTail == NIL_RTHT_INDEX)
    291311                    pThis->iFreeHead = pThis->iFreeTail = i;
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