VirtualBox

Changeset 25373 in vbox for trunk/src/VBox/Runtime/generic


Ignore:
Timestamp:
Dec 14, 2009 7:20:27 PM (15 years ago)
Author:
vboxsync
Message:

IPRT,PDMCritSect: More validation changes. Validate posix and linux mutexes. Always update the thread state with critsects.

Location:
trunk/src/VBox/Runtime/generic
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/generic/critsect-generic.cpp

    r25368 r25373  
    244244    ASMAtomicWriteHandle(&pCritSect->NativeThreadOwner, NativeThreadSelf);
    245245#ifdef RTCRITSECT_STRICT
    246     RTLockValidatorSetOwner(pCritSect->pValidatorRec, ThreadSelf, uId, RT_SRC_POS_ARGS);
     246    RTThreadWriteLockInc(RTLockValidatorSetOwner(pCritSect->pValidatorRec, ThreadSelf, uId, RT_SRC_POS_ARGS));
    247247#endif
    248248
     
    283283    RTNATIVETHREAD  NativeThreadSelf = RTThreadNativeSelf();
    284284#ifdef RTCRITSECT_STRICT
    285     RTTHREAD        ThreadSelf = RTThreadSelf();
    286     if (ThreadSelf == NIL_RTTHREAD)
    287         RTThreadAdopt(RTTHREADTYPE_DEFAULT, 0, NULL, &ThreadSelf);
    288     RTLockValidatorCheckOrder(pCritSect->pValidatorRec, ThreadSelf, uId, RT_SRC_POS_ARGS);
     285    RTTHREAD        hThreadSelf = RTThreadSelfAutoAdopt();
     286    RTLockValidatorCheckOrder(pCritSect->pValidatorRec, hThreadSelf, uId, RT_SRC_POS_ARGS);
    289287#endif
    290288
     
    315313        }
    316314
     315        /*
     316         * Wait for the current owner to release it.
     317         */
     318#ifndef RTCRITSECT_STRICT
     319        RTTHREAD hThreadSelf = RTThreadSelf();
     320#endif
    317321        for (;;)
    318322        {
    319 #ifdef RTCRITSECT_STRICT
    320             RTThreadBlocking(ThreadSelf, RTTHREADSTATE_CRITSECT, pCritSect->pValidatorRec, uId, RT_SRC_POS_ARGS);
    321 #endif
     323            RTThreadBlocking(hThreadSelf, RTTHREADSTATE_CRITSECT, RTCRITSECT_STRICT_BLOCK_ARGS(pCritSect->pValidatorRec));
    322324            int rc = RTSemEventWait(pCritSect->EventSem, RT_INDEFINITE_WAIT);
    323 #ifdef RTCRITSECT_STRICT
    324             RTThreadUnblocked(ThreadSelf, RTTHREADSTATE_CRITSECT);
    325 #endif
     325            RTThreadUnblocked(hThreadSelf, RTTHREADSTATE_CRITSECT);
    326326            if (pCritSect->u32Magic != RTCRITSECT_MAGIC)
    327327                return VERR_SEM_DESTROYED;
     
    339339    ASMAtomicWriteHandle(&pCritSect->NativeThreadOwner, NativeThreadSelf);
    340340#ifdef RTCRITSECT_STRICT
    341     RTLockValidatorSetOwner(pCritSect->pValidatorRec, ThreadSelf, uId, RT_SRC_POS_ARGS);
    342     RTThreadWriteLockInc(ThreadSelf);
     341    RTThreadWriteLockInc(RTLockValidatorSetOwner(pCritSect->pValidatorRec, hThreadSelf, uId, RT_SRC_POS_ARGS));
    343342#endif
    344343
     
    393392         */
    394393#ifdef RTCRITSECT_STRICT
    395         RTLockValidatorUnsetOwner(pCritSect->pValidatorRec);
     394        RTThreadWriteLockInc(RTLockValidatorUnsetOwner(pCritSect->pValidatorRec));
    396395#endif
    397396        ASMAtomicWriteHandle(&pCritSect->NativeThreadOwner, NIL_RTNATIVETHREAD);
  • trunk/src/VBox/Runtime/generic/semnoint-generic.cpp

    r21337 r25373  
    126126RT_EXPORT_SYMBOL(RTSemMutexRequest);
    127127
     128
     129RTDECL(int) RTSemMutexRequestDebug(RTSEMMUTEX Mutex, unsigned cMillies, RTHCUINTPTR uId, RT_SRC_POS_DECL)
     130{
     131    int rc;
     132    if (cMillies == RT_INDEFINITE_WAIT)
     133    {
     134        do rc = RTSemMutexRequestNoResumeDebug(Mutex, cMillies, uId, RT_SRC_POS_ARGS);
     135        while (rc == VERR_INTERRUPTED);
     136    }
     137    else
     138    {
     139        const uint64_t u64Start = RTTimeMilliTS();
     140        rc = RTSemMutexRequestNoResumeDebug(Mutex, cMillies, uId, RT_SRC_POS_ARGS);
     141        if (rc == VERR_INTERRUPTED)
     142        {
     143            do
     144            {
     145                uint64_t u64Elapsed = RTTimeMilliTS() - u64Start;
     146                if (u64Elapsed >= cMillies)
     147                    return VERR_TIMEOUT;
     148                rc = RTSemMutexRequestNoResumeDebug(Mutex, cMillies - (unsigned)u64Elapsed, uId, RT_SRC_POS_ARGS);
     149            } while (rc == VERR_INTERRUPTED);
     150        }
     151    }
     152    return rc;
     153}
     154RT_EXPORT_SYMBOL(RTSemMutexRequestDebug);
     155
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