VirtualBox

Changeset 6746 in vbox


Ignore:
Timestamp:
Feb 2, 2008 12:55:04 AM (17 years ago)
Author:
vboxsync
Message:

Replaced rtsemMutexValid by assertions like all the recent implementations does. (no performance gain/loss).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/r3/linux/semmutex-linux.cpp

    r6745 r6746  
    8888
    8989
    90 /**
    91  * Validate a Mutex semaphore handle passed to one of the interface.
    92  *
    93  * @returns true if valid.
    94  * @returns false if invalid.
    95  * @param   pIntMutexSem    Pointer to the mutex semaphore to validate.
    96  */
    97 inline bool rtsemMutexValid(struct RTSEMMUTEXINTERNAL *pIntMutexSem)
    98 {
    99     if ((uintptr_t)pIntMutexSem < 0x10000)
    100         return false;
    101 
    102     if (pIntMutexSem->iMagic != RTSEMMUTEX_MAGIC)
    103         return false;
    104 
    105     if (pIntMutexSem->cNesting == (uint32_t)~0)
    106         return false;
    107 
    108     return true;
    109 }
    110 
    111 
    11290RTDECL(int)  RTSemMutexCreate(PRTSEMMUTEX pMutexSem)
    11391{
     
    133111RTDECL(int)  RTSemMutexDestroy(RTSEMMUTEX MutexSem)
    134112{
     113    /*
     114     * Validate input.
     115     */
     116    if (MutexSem == NIL_RTSEMMUTEX)
     117        return VERR_INVALID_HANDLE;
    135118    struct RTSEMMUTEXINTERNAL *pIntMutexSem = MutexSem;
    136     /*
    137      * Validate input.
    138      */
    139     if (!rtsemMutexValid(pIntMutexSem))
    140     {
    141         AssertMsgFailed(("Invalid handle %p!\n", MutexSem));
    142         return VERR_INVALID_HANDLE;
    143     }
     119    AssertPtrReturn(pIntMutexSem, VERR_INVALID_HANDLE);
     120    AssertMsgReturn(pIntMutexSem->iMagic == RTSEMMUTEX_MAGIC,
     121                    ("MutexSem=%p iMagic=%#x\n", pIntMutexSem, pIntMutexSem->iMagic),
     122                    VERR_INVALID_HANDLE);
    144123
    145124    /*
     
    153132    }
    154133    pIntMutexSem->Owner    = (pthread_t)~0;
    155     pIntMutexSem->cNesting = ~0;
     134    pIntMutexSem->cNesting = 0;
    156135
    157136    /*
     
    169148     */
    170149    struct RTSEMMUTEXINTERNAL *pIntMutexSem = MutexSem;
    171     if (!rtsemMutexValid(pIntMutexSem))
    172     {
    173         AssertMsgFailed(("Invalid handle %p!\n", MutexSem));
    174         return VERR_INVALID_HANDLE;
    175     }
     150    AssertPtrReturn(pIntMutexSem, VERR_INVALID_HANDLE);
     151    AssertMsgReturn(pIntMutexSem->iMagic == RTSEMMUTEX_MAGIC,
     152                    ("MutexSem=%p iMagic=%#x\n", pIntMutexSem, pIntMutexSem->iMagic),
     153                    VERR_INVALID_HANDLE);
    176154
    177155    /*
     
    284262     */
    285263    struct RTSEMMUTEXINTERNAL *pIntMutexSem = MutexSem;
    286     if (!rtsemMutexValid(pIntMutexSem))
    287     {
    288         AssertMsgFailed(("Invalid handle %p!\n", MutexSem));
    289         return VERR_INVALID_HANDLE;
    290     }
     264    AssertPtrReturn(pIntMutexSem, VERR_INVALID_HANDLE);
     265    AssertMsgReturn(pIntMutexSem->iMagic == RTSEMMUTEX_MAGIC,
     266                    ("MutexSem=%p iMagic=%#x\n", pIntMutexSem, pIntMutexSem->iMagic),
     267                    VERR_INVALID_HANDLE);
    291268
    292269    /*
     
    294271     */
    295272    pthread_t Self = pthread_self();
    296     if (    pIntMutexSem->Owner != Self
    297         ||  pIntMutexSem->cNesting == (uint32_t)~0)
     273    if (RT_UNLIKELY(    pIntMutexSem->Owner != Self
     274                    ||  pIntMutexSem->cNesting == 0))
    298275    {
    299276        AssertMsgFailed(("Not owner of mutex %p!! Self=%08x Owner=%08x cNesting=%d\n",
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