VirtualBox

Ignore:
Timestamp:
Jun 9, 2010 12:14:59 PM (15 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
62505
Message:

iprt/asm.h,*: Revised the ASMAtomic*Ptr functions and macros. The new saves lots of unsafe (void * volatile *) casts as well as adding some type safety when using GCC (typeof rulez).

File:
1 edited

Legend:

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

    r28800 r30111  
    341341DECL_FORCE_INLINE(PRTLOCKVALRECUNION) rtLockValidatorReadRecUnionPtr(PRTLOCKVALRECUNION volatile *ppRec)
    342342{
    343     PRTLOCKVALRECUNION p = (PRTLOCKVALRECUNION)ASMAtomicReadPtr((void * volatile *)ppRec);
     343    PRTLOCKVALRECUNION p = ASMAtomicReadPtrT(ppRec, PRTLOCKVALRECUNION);
    344344    RTLOCKVAL_ASSERT_PTR_ALIGN(p);
    345345    return p;
     
    351351{
    352352    RTLOCKVAL_ASSERT_PTR_ALIGN(pRecNew);
    353     ASMAtomicWritePtr((void * volatile *)ppRec, pRecNew);
     353    ASMAtomicWritePtr(ppRec, pRecNew);
    354354}
    355355
     
    358358DECL_FORCE_INLINE(PRTTHREADINT) rtLockValidatorReadThreadHandle(RTTHREAD volatile *phThread)
    359359{
    360     PRTTHREADINT p = (PRTTHREADINT)ASMAtomicReadPtr((void * volatile *)phThread);
     360    PRTTHREADINT p = ASMAtomicReadPtrT(phThread, PRTTHREADINT);
    361361    RTLOCKVAL_ASSERT_PTR_ALIGN(p);
    362362    return p;
     
    367367DECL_FORCE_INLINE(PRTLOCKVALRECSHRDOWN) rtLockValidatorUoReadSharedOwner(PRTLOCKVALRECSHRDOWN volatile *ppOwner)
    368368{
    369     PRTLOCKVALRECSHRDOWN p = (PRTLOCKVALRECSHRDOWN)ASMAtomicUoReadPtr((void * volatile *)ppOwner);
     369    PRTLOCKVALRECSHRDOWN p = ASMAtomicUoReadPtrT(ppOwner, PRTLOCKVALRECSHRDOWN);
    370370    RTLOCKVAL_ASSERT_PTR_ALIGN(p);
    371371    return p;
     
    819819    if (pSrc)
    820820    {
    821         ASMAtomicUoWriteU32(&pDst->uLine,                           pSrc->uLine);
    822         ASMAtomicUoWritePtr((void * volatile *)&pDst->pszFile,      pSrc->pszFile);
    823         ASMAtomicUoWritePtr((void * volatile *)&pDst->pszFunction,  pSrc->pszFunction);
    824         ASMAtomicUoWritePtr((void * volatile *)&pDst->uId,          (void *)pSrc->uId);
     821        ASMAtomicUoWriteU32(&pDst->uLine,        pSrc->uLine);
     822        ASMAtomicUoWritePtr(&pDst->pszFile,      pSrc->pszFile);
     823        ASMAtomicUoWritePtr(&pDst->pszFunction,  pSrc->pszFunction);
     824        ASMAtomicUoWritePtr((void * volatile *)&pDst->uId, (void *)pSrc->uId);
    825825    }
    826826    else
    827827    {
    828         ASMAtomicUoWriteU32(&pDst->uLine,                           0);
    829         ASMAtomicUoWritePtr((void * volatile *)&pDst->pszFile,      NULL);
    830         ASMAtomicUoWritePtr((void * volatile *)&pDst->pszFunction,  NULL);
    831         ASMAtomicUoWritePtr((void * volatile *)&pDst->uId,          0);
     828        ASMAtomicUoWriteU32(&pDst->uLine,        0);
     829        ASMAtomicUoWritePtr(&pDst->pszFile,      NULL);
     830        ASMAtomicUoWritePtr(&pDst->pszFunction,  NULL);
     831        ASMAtomicUoWritePtr(&pDst->uId, (RTHCUINTPTR)0);
    832832    }
    833833}
     
    13591359                if (    !(*ppHashEntry)
    13601360                    ||  (*ppHashEntry)->cLookups + 128 < cLookups)
    1361                     ASMAtomicWritePtr((void * volatile *)ppHashEntry, &pChunk->aRefs[i]);
     1361                    ASMAtomicWritePtr(ppHashEntry, &pChunk->aRefs[i]);
    13621362
    13631363#ifdef RTLOCKVAL_WITH_CLASS_HASH_STATS
     
    14691469                    pNew->aRefs[0].fAutodidacticism = fAutodidacticism;
    14701470
    1471                     ASMAtomicWritePtr((void * volatile *)&pChunk->pNext, pNew);
     1471                    ASMAtomicWritePtr(&pChunk->pNext, pNew);
    14721472                    rtLockValidatorClassRetain(pPriorClass);
    14731473                    rc = VINF_SUCCESS;
     
    15471547        if (RT_UNLIKELY(ppCoreNext))
    15481548            break;
    1549         pSibling = (PRTLOCKVALRECUNION)ASMAtomicXchgPtr((void * volatile *)ppCoreNext, NULL);
     1549        pSibling = ASMAtomicXchgPtrT(ppCoreNext, NULL, PRTLOCKVALRECUNION);
    15501550    }
    15511551}
     
    34723472    {
    34733473        PRTLOCKVALRECSHRDOWN volatile *papOwners = pRec->papOwners;
    3474         ASMAtomicUoWritePtr((void * volatile *)&pRec->papOwners, NULL);
     3474        ASMAtomicUoWritePtr(&pRec->papOwners, NULL);
    34753475        ASMAtomicUoWriteU32(&pRec->cAllocated, 0);
    34763476
     
    38153815                }
    38163816
    3817                 ASMAtomicWritePtr((void * volatile *)&pShared->papOwners, papOwners);
     3817                ASMAtomicWritePtr(&pShared->papOwners, papOwners);
    38183818                ASMAtomicWriteU32(&pShared->cAllocated, cAllocated);
    38193819            }
     
    38583858            for (uint32_t iEntry = 0; iEntry < cMax; iEntry++)
    38593859            {
    3860                 if (ASMAtomicCmpXchgPtr((void * volatile *)&papOwners[iEntry], pEntry, NULL))
     3860                if (ASMAtomicCmpXchgPtr(&papOwners[iEntry], pEntry, NULL))
    38613861                {
    38623862                    rtLockValidatorSerializeDetectionLeave();
     
    38893889    AssertReturnVoidStmt(pShared->Core.u32Magic == RTLOCKVALRECSHRD_MAGIC, rtLockValidatorSerializeDetectionLeave());
    38903890    if (RT_UNLIKELY(   iEntry >= pShared->cAllocated
    3891                     || !ASMAtomicCmpXchgPtr((void * volatile *)&pShared->papOwners[iEntry], NULL, pEntry)))
     3891                    || !ASMAtomicCmpXchgPtr(&pShared->papOwners[iEntry], NULL, pEntry)))
    38923892    {
    38933893        /* this shouldn't happen yet... */
     
    38963896        uint32_t const                  cMax      = pShared->cAllocated;
    38973897        for (iEntry = 0; iEntry < cMax; iEntry++)
    3898             if (ASMAtomicCmpXchgPtr((void * volatile *)&papOwners[iEntry], NULL, pEntry))
     3898            if (ASMAtomicCmpXchgPtr(&papOwners[iEntry], NULL, pEntry))
    38993899               break;
    39003900        AssertReturnVoidStmt(iEntry < cMax, rtLockValidatorSerializeDetectionLeave());
     
    39313931        while (iEntry < cEntries)
    39323932        {
    3933             PRTLOCKVALRECSHRDOWN pEntry = (PRTLOCKVALRECSHRDOWN)ASMAtomicXchgPtr((void * volatile *)&papEntries[iEntry], NULL);
     3933            PRTLOCKVALRECSHRDOWN pEntry = ASMAtomicXchgPtrT(&papEntries[iEntry], NULL, PRTLOCKVALRECSHRDOWN);
    39343934            if (pEntry)
    39353935            {
Note: See TracChangeset for help on using the changeset viewer.

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