VirtualBox

Changeset 30112 in vbox for trunk


Ignore:
Timestamp:
Jun 9, 2010 12:31:50 PM (15 years ago)
Author:
vboxsync
Message:

iprt/asm.h,*: Added ASMAtomicWriteNullPtr and ASMAtomicUoWriteNullPtr to better deal with NULL being 0 in C++.

Location:
trunk
Files:
15 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/iprt/asm.h

    r30111 r30112  
    24162416 * Atomically writes a pointer value, ordered.
    24172417 *
    2418  * @returns Current *pv value
    24192418 * @param   ppv     Pointer to the pointer variable.
    24202419 * @param   pv      The pointer value to assign to *ppv.
     
    24332432
    24342433/**
    2435  * Convenience macro for avoiding the annoying casting with ASMAtomicWritePtr.
    2436  *
    2437  * @returns Current *pv value
     2434 * Atomically writes a pointer value, ordered.
     2435 *
    24382436 * @param   ppv     Pointer to the pointer variable.
    2439  * @param   pv      The pointer value to assign to *ppv. If NULL, you may have
    2440  *                  to cast it to the right pointer type for GCC to be happy.
     2437 * @param   pv      The pointer value to assign to *ppv. If NULL use
     2438 *                  ASMAtomicWriteNullPtr or you'll land in trouble.
    24412439 *
    24422440 * @remarks This is relatively type safe on GCC platforms when @a pv isn't
     
    24702468
    24712469/**
    2472  * Convenience macro for avoiding the annoying casting involved when using
    2473  * ASMAtomicWritePtr.
     2470 * Atomically sets a pointer to NULL, ordered.
     2471 *
     2472 * @param   ppv     Pointer to the pointer variable that should be set to NULL.
     2473 *
     2474 * @remarks This is relatively type safe on GCC platforms.
     2475 */
     2476#ifdef __GNUC__
     2477# define ASMAtomicWriteNullPtr(ppv) \
     2478    do \
     2479    { \
     2480        __typeof__(*(ppv)) volatile * const ppvTypeChecked = (ppv); \
     2481        AssertCompile(sizeof(*ppv) == sizeof(void *)); \
     2482        Assert(!( (uintptr_t)ppv & ((ARCH_BITS / 8) - 1) )); \
     2483        ASMAtomicWritePtrVoid((void * volatile *)(ppvTypeChecked), NULL); \
     2484    } while (0)
     2485#else
     2486# define ASMAtomicWriteNullPtr(ppv) \
     2487    do \
     2488    { \
     2489        AssertCompile(sizeof(*ppv) == sizeof(void *)); \
     2490        Assert(!( (uintptr_t)ppv & ((ARCH_BITS / 8) - 1) )); \
     2491        ASMAtomicWritePtrVoid((void * volatile *)(ppv), NULL); \
     2492    } while (0)
     2493#endif
     2494
     2495
     2496/**
     2497 * Atomically writes a pointer value, unordered.
    24742498 *
    24752499 * @returns Current *pv value
    24762500 * @param   ppv     Pointer to the pointer variable.
    2477  * @param   pv      The pointer value to assign to *ppv.
     2501 * @param   pv      The pointer value to assign to *ppv. If NULL use
     2502 *                  ASMAtomicUoWriteNullPtr or you'll land in trouble.
    24782503 *
    24792504 * @remarks This is relatively type safe on GCC platforms when @a pv isn't
     
    25012526        Assert(!( (uintptr_t)ppv & ((ARCH_BITS / 8) - 1) )); \
    25022527        *(ppv) = pv; \
     2528    } while (0)
     2529#endif
     2530
     2531
     2532/**
     2533 * Atomically sets a pointer to NULL, unordered.
     2534 *
     2535 * @param   ppv     Pointer to the pointer variable that should be set to NULL.
     2536 *
     2537 * @remarks This is relatively type safe on GCC platforms.
     2538 */
     2539#ifdef __GNUC__
     2540# define ASMAtomicUoWriteNullPtr(ppv) \
     2541    do \
     2542    { \
     2543        __typeof__(*(ppv)) volatile * const ppvTypeChecked = (ppv); \
     2544        AssertCompile(sizeof(*ppv) == sizeof(void *)); \
     2545        Assert(!( (uintptr_t)ppv & ((ARCH_BITS / 8) - 1) )); \
     2546        *(ppvTypeChecked) = NULL; \
     2547    } while (0)
     2548#else
     2549# define ASMAtomicUoWriteNullPtr(ppv) \
     2550    do \
     2551    { \
     2552        AssertCompile(sizeof(*ppv) == sizeof(void *)); \
     2553        Assert(!( (uintptr_t)ppv & ((ARCH_BITS / 8) - 1) )); \
     2554        *(ppv) = NULL; \
    25032555    } while (0)
    25042556#endif
  • trunk/src/VBox/Devices/Storage/DrvDiskIntegrity.cpp

    r30111 r30112  
    490490    Assert(pReqActive->pIoReq == pIoReq);
    491491
    492     ASMAtomicWritePtr(&pReqActive->pIoReq, NULL);
     492    ASMAtomicWriteNullPtr(&pReqActive->pIoReq);
    493493}
    494494
  • trunk/src/VBox/HostDrivers/Support/SUPLib.cpp

    r30111 r30112  
    508508        if (g_pSUPGlobalInfoPage)
    509509        {
    510             ASMAtomicWritePtr((void * volatile *)&g_pSUPGlobalInfoPage, NULL);
    511             ASMAtomicWritePtr((void * volatile *)&g_pSUPGlobalInfoPageR0, NULL);
     510            ASMAtomicWriteNullPtr((void * volatile *)&g_pSUPGlobalInfoPage);
     511            ASMAtomicWriteNullPtr((void * volatile *)&g_pSUPGlobalInfoPageR0);
    512512            ASMAtomicWriteSize(&g_HCPhysSUPGlobalInfoPage, NIL_RTHCPHYS);
    513513            /* just a little safe guard against threads using the page. */
  • trunk/src/VBox/HostDrivers/Support/SUPSvcGrant.cpp

    r30111 r30112  
    975975    unsigned cSessions = 0;
    976976    for (PSUPSVCGRANTSESSION pCur = pThis->pSessionHead; pCur; pCur = pCur->pNext)
    977         ASMAtomicWritePtr(&pCur->pParent, NULL);
     977        ASMAtomicWriteNullPtr(&pCur->pParent);
    978978
    979979    RTCritSectLeave(&pThis->CritSect);
  • trunk/src/VBox/HostDrivers/VBoxNetFlt/darwin/VBoxNetFlt-darwin.cpp

    r30111 r30112  
    669669    int cPromisc = VALID_PTR(pIfNet) ? VBOX_GET_PCOUNT(pIfNet) : - 1;
    670670
    671     ASMAtomicUoWritePtr(&pThis->u.s.pIfNet, NULL);
    672     ASMAtomicUoWritePtr(&pThis->u.s.pIfFilter, NULL);
     671    ASMAtomicUoWriteNullPtr(&pThis->u.s.pIfNet);
     672    ASMAtomicUoWriteNullPtr(&pThis->u.s.pIfFilter);
    673673    ASMAtomicWriteBool(&pThis->u.s.fNeedSetPromiscuous, false);
    674674    pThis->u.s.fSetPromiscuous = false;
     
    11641164    pIfFilter = ASMAtomicUoReadPtrT(&pThis->u.s.pIfFilter, interface_filter_t);
    11651165    if (pIfFilter)
    1166         ASMAtomicUoWritePtr(&pThis->u.s.pIfFilter, NULL);
     1166        ASMAtomicUoWriteNullPtr(&pThis->u.s.pIfFilter);
    11671167    RTSpinlockReleaseNoInts(pThis->hSpinlock, &Tmp);
    11681168
  • trunk/src/VBox/HostDrivers/VBoxNetFlt/linux/VBoxNetFlt-linux.c

    r30111 r30112  
    651651    pPriv = qdisc_priv(pQdisc);
    652652    Assert(pPriv->pVBoxNetFlt == pThis);
    653     ASMAtomicWritePtr(&pPriv->pVBoxNetFlt, NULL);
     653    ASMAtomicWriteNullPtr(&pPriv->pVBoxNetFlt);
    654654
    655655    QDISC_LOG(("vboxNetFltLinuxQdiscRemove: refcnt=%d num_tx_queues=%d\n",
     
    19461946#endif /* VBOXNETFLT_WITH_QDISC */
    19471947        RTSpinlockAcquireNoInts(pThis->hSpinlock, &Tmp);
    1948         ASMAtomicUoWritePtr(&pThis->u.s.pDev, NULL);
     1948        ASMAtomicUoWriteNullPtr(&pThis->u.s.pDev);
    19491949        RTSpinlockReleaseNoInts(pThis->hSpinlock, &Tmp);
    19501950        dev_put(pDev);
     
    19731973    ASMAtomicWriteBool(&pThis->u.s.fRegistered, false);
    19741974    ASMAtomicWriteBool(&pThis->fDisconnectedFromHost, true);
    1975     ASMAtomicUoWritePtr(&pThis->u.s.pDev, NULL);
     1975    ASMAtomicUoWriteNullPtr(&pThis->u.s.pDev);
    19761976    RTSpinlockReleaseNoInts(pThis->hSpinlock, &Tmp);
    19771977
  • trunk/src/VBox/HostDrivers/VBoxNetFlt/solaris/VBoxNetFlt-solaris.c

    r30111 r30112  
    924924            RTTimerStop(pPromiscStream->pIp6Timer);
    925925            RTTimerDestroy(pPromiscStream->pIp6Timer);
    926             ASMAtomicUoWritePtr(&pPromiscStream->pIp6Timer, NULL);
     926            ASMAtomicUoWriteNullPtr(&pPromiscStream->pIp6Timer);
    927927        }
    928928#endif
     
    944944    switch (pStream->Type)
    945945    {
    946         case kIp4Stream:        ASMAtomicUoWritePtr(pStream->pThis->u.s.pvIp4Stream, NULL);     break;
    947         case kIp6Stream:        ASMAtomicUoWritePtr(pStream->pThis->u.s.pvIp6Stream, NULL);     break;
    948         case kArpStream:        ASMAtomicUoWritePtr(pStream->pThis->u.s.pvArpStream, NULL);     break;
    949         case kPromiscStream:    ASMAtomicUoWritePtr(pStream->pThis->u.s.pvPromiscStream, NULL); break;
     946        case kIp4Stream:        ASMAtomicUoWriteNullPtr(pStream->pThis->u.s.pvIp4Stream);     break;
     947        case kIp6Stream:        ASMAtomicUoWriteNullPtr(pStream->pThis->u.s.pvIp6Stream);     break;
     948        case kArpStream:        ASMAtomicUoWriteNullPtr(pStream->pThis->u.s.pvArpStream);     break;
     949        case kPromiscStream:    ASMAtomicUoWriteNullPtr(pStream->pThis->u.s.pvPromiscStream); break;
    950950        default:    /* Heh. */
    951951        {
     
    25782578        RTTimerStop(pPromiscStream->pIp6Timer);
    25792579        RTTimerDestroy(pPromiscStream->pIp6Timer);
    2580         ASMAtomicUoWritePtr(&pPromiscStream->pIp6Timer, NULL);
     2580        ASMAtomicUoWriteNullPtr(&pPromiscStream->pIp6Timer);
    25812581    }
    25822582#endif
  • trunk/src/VBox/Main/ConsoleImpl.cpp

    r30111 r30112  
    81238123        unsigned iLed = pData->iLastLUN - pData->iFirstLUN + 1;
    81248124        while (iLed-- > 0)
    8125             ASMAtomicWritePtr(&pData->papLeds[iLed], NULL);
     8125            ASMAtomicWriteNullPtr(&pData->papLeds[iLed]);
    81268126    }
    81278127}
  • trunk/src/VBox/Runtime/common/log/log.cpp

    r30111 r30112  
    19051905                ||  g_aPerThreadLoggers[i].uKey == uKey)
    19061906            {
    1907                 ASMAtomicWritePtr((void * volatile *)&g_aPerThreadLoggers[i].uKey, (void *)NULL);
    1908                 ASMAtomicWritePtr(&g_aPerThreadLoggers[i].pLogger, (PRTLOGGER)NULL);
     1907                ASMAtomicWriteNullPtr((void * volatile *)&g_aPerThreadLoggers[i].uKey);
     1908                ASMAtomicWriteNullPtr(&g_aPerThreadLoggers[i].pLogger);
    19091909                ASMAtomicWriteHandle(&g_aPerThreadLoggers[i].NativeThread, NIL_RTNATIVETHREAD);
    19101910                ASMAtomicDecS32(&g_cPerThreadLoggers);
  • trunk/src/VBox/Runtime/common/misc/lockvalidator.cpp

    r30111 r30112  
    827827    {
    828828        ASMAtomicUoWriteU32(&pDst->uLine,        0);
    829         ASMAtomicUoWritePtr(&pDst->pszFile,      NULL);
    830         ASMAtomicUoWritePtr(&pDst->pszFunction,  NULL);
     829        ASMAtomicUoWriteNullPtr(&pDst->pszFile);
     830        ASMAtomicUoWriteNullPtr(&pDst->pszFunction);
    831831        ASMAtomicUoWritePtr(&pDst->uId, (RTHCUINTPTR)0);
    832832    }
     
    34723472    {
    34733473        PRTLOCKVALRECSHRDOWN volatile *papOwners = pRec->papOwners;
    3474         ASMAtomicUoWritePtr(&pRec->papOwners, NULL);
     3474        ASMAtomicUoWriteNullPtr(&pRec->papOwners);
    34753475        ASMAtomicUoWriteU32(&pRec->cAllocated, 0);
    34763476
  • trunk/src/VBox/Runtime/common/misc/thread.cpp

    r30111 r30112  
    13491349            if (   pThread->LockValidator.pRec
    13501350                && pThread->LockValidator.enmRecState == enmCurState)
    1351                 ASMAtomicWritePtr(&pThread->LockValidator.pRec, NULL);
     1351                ASMAtomicWriteNullPtr(&pThread->LockValidator.pRec);
    13521352        }
    13531353        /* This is a bit ugly... :-/ */
     
    13551355                     || enmActualState == RTTHREADSTATE_INITIALIZING)
    13561356                 && pThread->LockValidator.pRec)
    1357             ASMAtomicWritePtr(&pThread->LockValidator.pRec, NULL);
     1357            ASMAtomicWriteNullPtr(&pThread->LockValidator.pRec);
    13581358        Assert(   pThread->LockValidator.pRec == NULL
    13591359               || RTTHREAD_IS_SLEEPING(enmActualState));
     
    14411441    PRTTHREADINT pThread = (PRTTHREADINT)pNode;
    14421442    RTTLS iTls = (RTTLS)(uintptr_t)pvUser;
    1443     ASMAtomicWritePtr(&pThread->apvTlsEntries[iTls], NULL);
     1443    ASMAtomicWriteNullPtr(&pThread->apvTlsEntries[iTls]);
    14441444    return 0;
    14451445}
  • trunk/src/VBox/Runtime/generic/tls-generic.cpp

    r30111 r30112  
    8989        return VERR_INVALID_PARAMETER;
    9090
    91     ASMAtomicWritePtr(&g_apfnDestructors[iTls], NULL);
     91    ASMAtomicWriteNullPtr(&g_apfnDestructors[iTls]);
    9292    rtThreadClearTlsEntry(iTls);
    9393    ASMAtomicBitClear(&g_au32AllocatedBitmap[0], iTls);
  • trunk/src/VBox/Runtime/r3/posix/fileaio-posix.cpp

    r30111 r30112  
    493493        AssertRC(rc);
    494494
    495         ASMAtomicWritePtr(&pCtxInt->pReqToCancel, NULL);
     495        ASMAtomicWriteNullPtr(&pCtxInt->pReqToCancel);
    496496        pReqInt->Rc = VERR_FILE_AIO_CANCELED;
    497497        RTFILEAIOREQ_SET_STATE(pReqInt, COMPLETED);
  • trunk/src/VBox/VMM/VMMR0/GVMMR0.cpp

    r30111 r30112  
    10671067    pHandle->iNext = pGVMM->iFreeHead;
    10681068    pGVMM->iFreeHead = iHandle;
    1069     ASMAtomicWritePtr(&pHandle->pGVM,               (PGVM)NULL);
    1070     ASMAtomicWritePtr(&pHandle->pVM,                 (PVM)NULL);
    1071     ASMAtomicWritePtr(&pHandle->pvObj,            (void *)NULL);
    1072     ASMAtomicWritePtr(&pHandle->pSession, (PSUPDRVSESSION)NULL);
     1069    ASMAtomicWriteNullPtr(&pHandle->pGVM);
     1070    ASMAtomicWriteNullPtr(&pHandle->pVM);
     1071    ASMAtomicWriteNullPtr(&pHandle->pvObj);
     1072    ASMAtomicWriteNullPtr(&pHandle->pSession);
    10731073    ASMAtomicWriteSize(&pHandle->hEMT0,     NIL_RTNATIVETHREAD);
    10741074    ASMAtomicWriteSize(&pHandle->ProcId,         NIL_RTPROCESS);
  • trunk/src/VBox/VMM/VMReq.cpp

    r30111 r30112  
    490490        if (ASMAtomicCmpXchgPtr(ppHead, pHead, pList))
    491491            return;
    492         ASMAtomicWritePtr(&pTail->pNext, NULL);
     492        ASMAtomicWriteNullPtr(&pTail->pNext);
    493493        ASMCompilerBarrier();
    494494        if (ASMAtomicCmpXchgPtr(ppHead, pHead, NULL))
     
    10091009        pReqRet = pReqRet->pNext;
    10101010    } while (pReqRet->pNext);
    1011     ASMAtomicWritePtr(&pPrev->pNext, NULL);
     1011    ASMAtomicWriteNullPtr(&pPrev->pNext);
    10121012
    10131013    /* Push the others back onto the list (end of it). */
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