VirtualBox

Changeset 25791 in vbox


Ignore:
Timestamp:
Jan 12, 2010 10:57:57 PM (15 years ago)
Author:
vboxsync
Message:

iprt/lockvalidator,tstRTLockValidator: Fixed some class reference counting bugs.

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

Legend:

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

    r25748 r25791  
    13471347                    {
    13481348                        pChunk->aRefs[i].fAutodidacticism = fAutodidacticism;
     1349                        rtLockValidatorClassRetain(pPriorClass);
    13491350                        rc = VINF_SUCCESS;
    13501351                        break;
     
    13781379
    13791380                    ASMAtomicWritePtr((void * volatile *)&pChunk->pNext, pNew);
     1381                    rtLockValidatorClassRetain(pPriorClass);
    13801382                    rc = VINF_SUCCESS;
    13811383                    break;
     
    33743376
    33753377    ASMAtomicWriteU32(&pRec->Core.u32Magic, RTLOCKVALRECSHRD_MAGIC_DEAD);
    3376     ASMAtomicUoWriteHandle(&pRec->hClass, NIL_RTLOCKVALCLASS);
     3378    RTLOCKVALCLASS hClass;
     3379    ASMAtomicXchgHandle(&pRec->hClass, NIL_RTLOCKVALCLASS, &hClass);
    33773380    if (pRec->papOwners)
    33783381    {
     
    33883391
    33893392    rtLockValidatorSerializeDestructLeave();
     3393
     3394    if (hClass != NIL_RTLOCKVALCLASS)
     3395        RTLockValidatorClassRelease(hClass);
    33903396}
    33913397
  • trunk/src/VBox/Runtime/testcase/tstRTLockValidator.cpp

    r25759 r25791  
    952952
    953953    /* clean up */
     954    //for (int i = RT_ELEMENTS(g_ahClasses) - 1; i >= 0; i--)
    954955    for (unsigned i = 0; i < RT_ELEMENTS(g_ahClasses); i++)
    955956    {
     957        uint32_t c;
    956958        if (i <= 3)
    957             RTTEST_CHECK(g_hTest, RTLockValidatorClassRelease(g_ahClasses[i]) == 1);
     959            RTTEST_CHECK_MSG(g_hTest, (c = RTLockValidatorClassRelease(g_ahClasses[i])) == 5 - i,
     960                             (g_hTest, "c=%u i=%u\n", c, i));
    958961        else
    959962        {
    960963            uint32_t cExpect = 1 + (RT_ELEMENTS(g_ahClasses) - i) * 2 - 1;
    961             RTTEST_CHECK(g_hTest, RTLockValidatorClassRelease(g_ahClasses[i]) == cExpect);
     964            RTTEST_CHECK(g_hTest, (c = RTLockValidatorClassRelease(g_ahClasses[i])) == cExpect,
     965                         (g_hTest, "c=%u e=%u i=%u\n", c, cExpect, i));
    962966        }
    963967        g_ahClasses[i] = NIL_RTLOCKVALCLASS;
     
    10181022
    10191023    /* clean up */
    1020     for (unsigned i = 0; i < 4; i++)
     1024    for (int i = 4 - 1; i >= 0; i--)
    10211025    {
    10221026        RTTEST_CHECK(g_hTest, RTLockValidatorClassRelease(g_ahClasses[i]) == 1);
     
    11081112
    11091113    /* clean up */
    1110     for (unsigned i = 0; i < 6; i++)
    1111     {
    1112         RTTEST_CHECK(g_hTest, RTLockValidatorClassRelease(g_ahClasses[i]) == 2);
     1114    for (int i = 6 - 1; i >= 0; i--)
     1115    {
     1116        uint32_t c;
     1117        RTTEST_CHECK_MSG(g_hTest, (c = RTLockValidatorClassRelease(g_ahClasses[i])) == 2, (g_hTest, "c=%u i=%u\n", c, i));
    11131118        g_ahClasses[i] = NIL_RTLOCKVALCLASS;
    11141119        RTTEST_CHECK_RC_RETV(g_hTest, RTSemRWDestroy(g_ahSemRWs[i]), VINF_SUCCESS);
     
    11711176
    11721177    /* clean up */
    1173     for (unsigned i = 0; i < 4; i++)
     1178    for (int i = 4 - 1; i >= 0; i--)
    11741179    {
    11751180        RTTEST_CHECK(g_hTest, RTLockValidatorClassRelease(g_ahClasses[i]) == 1);
     
    11821187
    11831188
    1184 static bool testIsLockValidationCompiledIn(void)
     1189static const char *testCheckIfLockValidationIsCompiledIn(void)
    11851190{
    11861191    RTCRITSECT CritSect;
    1187     RTTEST_CHECK_RC_OK_RET(g_hTest, RTCritSectInit(&CritSect), false);
    1188     RTTEST_CHECK_RC_OK_RET(g_hTest, RTCritSectEnter(&CritSect), false);
     1192    RTTEST_CHECK_RC_OK_RET(g_hTest, RTCritSectInit(&CritSect), "");
     1193    RTTEST_CHECK_RC_OK_RET(g_hTest, RTCritSectEnter(&CritSect), "");
    11891194    bool fRet = CritSect.pValidatorRec
    11901195             && CritSect.pValidatorRec->hThread == RTThreadSelf();
    1191     RTTEST_CHECK_RC_OK_RET(g_hTest, RTCritSectLeave(&CritSect), false);
    1192     RTTEST_CHECK_RC_OK_RET(g_hTest, RTCritSectDelete(&CritSect), false);
    1193 
     1196    RTTEST_CHECK_RC_OK_RET(g_hTest, RTCritSectLeave(&CritSect), "");
     1197    RTTEST_CHECK_RC_OK_RET(g_hTest, RTCritSectDelete(&CritSect), "");
     1198    if (!fRet)
     1199        return "Lock validation is not enabled for critical sections";
     1200
     1201    /* deadlock detection for RTSemRW */
    11941202    RTSEMRW hSemRW;
    1195     RTTEST_CHECK_RC_OK_RET(g_hTest, RTSemRWCreate(&hSemRW), false);
    1196     RTTEST_CHECK_RC_OK_RET(g_hTest, RTSemRWRequestRead(hSemRW, 50), false);
     1203    RTTEST_CHECK_RC_OK_RET(g_hTest, RTSemRWCreateEx(&hSemRW, 0 /*fFlags*/, NIL_RTLOCKVALCLASS,
     1204                                                    RTLOCKVAL_SUB_CLASS_NONE, "RTSemRW-1"), false);
     1205    RTTEST_CHECK_RC_OK_RET(g_hTest, RTSemRWRequestRead(hSemRW, 50), "");
    11971206    int rc = RTSemRWRequestWrite(hSemRW, 1);
     1207    RTTEST_CHECK_RET(g_hTest, RT_FAILURE_NP(rc), "");
     1208    RTTEST_CHECK_RC_OK_RET(g_hTest, RTSemRWReleaseRead(hSemRW), "");
     1209    RTTEST_CHECK_RC_OK_RET(g_hTest, RTSemRWDestroy(hSemRW), "");
    11981210    if (rc != VERR_SEM_LV_ILLEGAL_UPGRADE)
    1199         fRet = false;
    1200     RTTEST_CHECK_RET(g_hTest, RT_FAILURE_NP(rc), false);
    1201     RTTEST_CHECK_RC_OK_RET(g_hTest, RTSemRWReleaseRead(hSemRW), false);
    1202     RTTEST_CHECK_RC_OK_RET(g_hTest, RTSemRWDestroy(hSemRW), false);
    1203 
    1204 #if 0 /** @todo detect it on RTSemMutex... wrong locking order? */
    1205     RTSEMMUTEX hSemMtx;
    1206     RTTEST_CHECK_RC_OK_RET(g_hTest, RTSemMutexCreate(&hSemRW), false);
    1207     RTTEST_CHECK_RC_OK_RET(g_hTest, RTSemMutexRequest(hSemRW, 50), false);
    1208     /*??*/
    1209     RTTEST_CHECK_RET(g_hTest, RT_FAILURE_NP(rc), false);
    1210     RTTEST_CHECK_RC_OK_RET(g_hTest, RTSemRWRelease(hSemRW), false);
    1211     RTTEST_CHECK_RC_OK_RET(g_hTest, RTSemRWDestroy(hSemRW), false);
    1212 #endif
    1213 
     1211        return "Deadlock detection is not enabled for the read/write semaphores";
     1212
     1213    /* lock order for RTSemRW */
     1214    RTTEST_CHECK_RC_OK_RET(g_hTest, RTSemRWCreateEx(&hSemRW, 0 /*fFlags*/,
     1215                                                    RTLockValidatorClassCreateUnique(RT_SRC_POS, NULL),
     1216                                                    RTLOCKVAL_SUB_CLASS_NONE, "RTSemRW-2"), "");
     1217    RTTEST_CHECK_RC_OK_RET(g_hTest, RTSemRWRequestRead(hSemRW, 50), "");
     1218    rc = RTSemRWRequestWrite(hSemRW, 1);
     1219    RTTEST_CHECK_RET(g_hTest, RT_FAILURE_NP(rc), "");
     1220    RTTEST_CHECK_RC_OK_RET(g_hTest, RTSemRWReleaseRead(hSemRW), "");
     1221    RTTEST_CHECK_RC_OK_RET(g_hTest, RTSemRWDestroy(hSemRW), "");
     1222    if (rc != VERR_SEM_LV_WRONG_ORDER)
     1223    {
     1224        RTTestPrintf(g_hTest,  RTTESTLVL_ALWAYS,  "%Rrc\n", rc);
     1225        return "Lock order validation is not enabled for the read/write semaphores";
     1226    }
     1227
     1228    /* lock order for RTSemMutex */
     1229    RTSEMMUTEX hSemMtx1;
     1230    RTTEST_CHECK_RC_OK_RET(g_hTest, RTSemMutexCreateEx(&hSemMtx1, 0 /*fFlags*/,
     1231                                                       RTLockValidatorClassCreateUnique(RT_SRC_POS, NULL),
     1232                                                       RTLOCKVAL_SUB_CLASS_NONE, "RTSemMtx-1"), "");
     1233    RTSEMMUTEX hSemMtx2;
     1234    RTTEST_CHECK_RC_OK_RET(g_hTest, RTSemMutexCreateEx(&hSemMtx2, 0 /*fFlags*/,
     1235                                                       RTLockValidatorClassCreateUnique(RT_SRC_POS, NULL),
     1236                                                       RTLOCKVAL_SUB_CLASS_NONE, "RTSemMtx-2"), "");
     1237    RTTEST_CHECK_RC_OK_RET(g_hTest, RTSemMutexRequest(hSemMtx1, 50), "");
     1238    RTTEST_CHECK_RC_OK_RET(g_hTest, RTSemMutexRequest(hSemMtx2, 50), "");
     1239    RTTEST_CHECK_RC_OK_RET(g_hTest, RTSemMutexRelease(hSemMtx2), "");
     1240    RTTEST_CHECK_RC_OK_RET(g_hTest, RTSemMutexRelease(hSemMtx1), "");
     1241
     1242    RTTEST_CHECK_RC_OK_RET(g_hTest, RTSemMutexRequest(hSemMtx2, 50), "");
     1243    rc = RTSemMutexRequest(hSemMtx1, 50);
     1244    RTTEST_CHECK_RET(g_hTest, RT_FAILURE_NP(rc), "");
     1245    RTTEST_CHECK_RC_OK_RET(g_hTest, RTSemMutexRelease(hSemMtx2), "");
     1246    RTTEST_CHECK_RC_OK_RET(g_hTest, RTSemMutexDestroy(hSemMtx2), "");   hSemMtx2 = NIL_RTSEMMUTEX;
     1247    RTTEST_CHECK_RC_OK_RET(g_hTest, RTSemMutexDestroy(hSemMtx1), "");   hSemMtx1 = NIL_RTSEMMUTEX;
     1248    if (rc != VERR_SEM_LV_WRONG_ORDER)
     1249        return "Lock order validation is not enabled for the mutex semaphores";
     1250
     1251    /* signaller checks on event sems. */
    12141252    RTSEMEVENT hSemEvt;
    1215     RTTEST_CHECK_RC_OK_RET(g_hTest, RTSemEventCreate(&hSemEvt), false);
     1253    RTTEST_CHECK_RC_OK_RET(g_hTest, RTSemEventCreate(&hSemEvt), "");
    12161254    RTSemEventSetSignaller(hSemEvt, RTThreadSelf());
    12171255    RTSemEventSetSignaller(hSemEvt, NIL_RTTHREAD);
    12181256    rc = RTSemEventSignal(hSemEvt);
     1257    RTTEST_CHECK_RET(g_hTest, RT_FAILURE_NP(rc), "");
     1258    RTTEST_CHECK_RC_OK_RET(g_hTest, RTSemEventDestroy(hSemEvt), "");
    12191259    if (rc != VERR_SEM_LV_NOT_SIGNALLER)
    1220         fRet = false;
    1221     RTTEST_CHECK_RET(g_hTest, RT_FAILURE_NP(rc), false);
    1222     RTTEST_CHECK_RC_OK_RET(g_hTest, RTSemEventDestroy(hSemEvt), false);
    1223 
     1260        return "Signalling checks are not enabled for the event semaphores";
     1261
     1262    /* signaller checks on multiple release event sems. */
    12241263    RTSEMEVENTMULTI hSemEvtMulti;
    1225     RTTEST_CHECK_RC_OK_RET(g_hTest, RTSemEventMultiCreate(&hSemEvtMulti), false);
     1264    RTTEST_CHECK_RC_OK_RET(g_hTest, RTSemEventMultiCreate(&hSemEvtMulti), "");
    12261265    RTSemEventMultiSetSignaller(hSemEvtMulti, RTThreadSelf());
    12271266    RTSemEventMultiSetSignaller(hSemEvtMulti, NIL_RTTHREAD);
    12281267    rc = RTSemEventMultiSignal(hSemEvtMulti);
     1268    RTTEST_CHECK_RET(g_hTest, RT_FAILURE_NP(rc), "");
     1269    RTTEST_CHECK_RC_OK_RET(g_hTest, RTSemEventMultiDestroy(hSemEvtMulti), "");
    12291270    if (rc != VERR_SEM_LV_NOT_SIGNALLER)
    1230         fRet = false;
    1231     RTTEST_CHECK_RET(g_hTest, RT_FAILURE_NP(rc), false);
    1232     RTTEST_CHECK_RC_OK_RET(g_hTest, RTSemEventMultiDestroy(hSemEvtMulti), false);
    1233 
    1234     return fRet;
     1271        return "Signalling checks are not enabled for the multiple release event semaphores";
     1272
     1273    /* we're good */
     1274    return NULL;
    12351275}
    12361276
     
    12491289    RTLockValidatorSetMayPanic(false);
    12501290    RTLockValidatorSetQuiet(true);
    1251     if (!testIsLockValidationCompiledIn())
     1291    const char *pszWhyDisabled = testCheckIfLockValidationIsCompiledIn();
     1292    if (pszWhyDisabled)
    12521293        return RTTestErrorCount(g_hTest) > 0
    12531294            ? RTTestSummaryAndDestroy(g_hTest)
    1254             : RTTestSkipAndDestroy(g_hTest, "deadlock detection is not compiled in");
     1295            : RTTestSkipAndDestroy(g_hTest, pszWhyDisabled);
    12551296    RTLockValidatorSetQuiet(false);
    12561297
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