Changeset 25622 in vbox
- Timestamp:
- Jan 3, 2010 1:56:34 PM (15 years ago)
- svn:sync-xref-src-repo-rev:
- 56313
- Location:
- trunk
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/iprt/lockvalidator.h
r25618 r25622 654 654 RTDECL(void *) RTLockValidatorQueryBlocking(RTTHREAD hThread); 655 655 656 /** 657 * Checks if the thread is running in the lock validator after it has entered a 658 * block state. 659 * 660 * @returns true if it is, false if it isn't. 661 * @param hThread The thread in question. 662 */ 663 RTDECL(bool) RTLockValidatorIsBlockedThreadInValidator(RTTHREAD hThread); 656 664 657 665 -
trunk/src/VBox/Runtime/common/misc/lockvalidator.cpp
r25618 r25622 412 412 Assert(pPerThread->cWriteLocks == 0); 413 413 Assert(pPerThread->cReadLocks == 0); 414 Assert(pPerThread->fInValidator == false); 414 415 } 415 416 … … 1166 1167 rtLockValidatorWriteRecUnionPtr(&pThreadSelf->LockValidator.pRec, pRecU); 1167 1168 rtLockValidatorCopySrcPos(&pThreadSelf->LockValidator.SrcPos, pSrcPos); 1169 ASMAtomicWriteBool(&pThreadSelf->LockValidator.fInValidator, true); 1168 1170 rtThreadSetState(pThreadSelf, enmSleepState); 1169 1171 … … 1174 1176 * isn't any other place to check for this. semmutex-win.cpp for instance. 1175 1177 */ 1178 int rc = VINF_SUCCESS; 1176 1179 if (rtLockValidatorReadThreadHandle(&pRecU->Excl.hThread) == pThreadSelf) 1177 1180 { 1178 if (fRecursiveOk) 1179 return VINF_SUCCESS; 1180 rtLockValidatorComplainFirst("Recursion not allowed", pSrcPos, pThreadSelf, pRecU); 1181 rtLockValidatorComplainPanic(); 1181 if (!fRecursiveOk) 1182 { 1183 rtLockValidatorComplainFirst("Recursion not allowed", pSrcPos, pThreadSelf, pRecU); 1184 rtLockValidatorComplainPanic(); 1185 rc = VERR_SEM_LV_NESTED; 1186 } 1187 } 1188 /* 1189 * Perform deadlock detection. 1190 */ 1191 else if (!rtLockValidatorIsSimpleNoDeadlockCase(pRecU)) 1192 rc = rtLockValidatorDeadlockDetection(pRecU, pThreadSelf, pSrcPos); 1193 1194 if (RT_FAILURE(rc)) 1182 1195 rtThreadSetState(pThreadSelf, enmThreadState); 1183 return VERR_SEM_LV_NESTED; 1184 } 1185 1186 /* 1187 * Perform deadlock detection. 1188 */ 1189 int rc = VINF_SUCCESS; 1190 if (!rtLockValidatorIsSimpleNoDeadlockCase(pRecU)) 1191 { 1192 rc = rtLockValidatorDeadlockDetection(pRecU, pThreadSelf, pSrcPos); 1193 if (RT_FAILURE(rc)) 1194 rtThreadSetState(pThreadSelf, enmThreadState); 1195 } 1196 ASMAtomicWriteBool(&pThreadSelf->LockValidator.fInValidator, false); 1196 1197 return rc; 1197 1198 } … … 1365 1366 rtLockValidatorWriteRecUnionPtr(&pThreadSelf->LockValidator.pRec, pRecU); 1366 1367 rtLockValidatorCopySrcPos(&pThreadSelf->LockValidator.SrcPos, pSrcPos); 1368 ASMAtomicWriteBool(&pThreadSelf->LockValidator.fInValidator, true); 1367 1369 rtThreadSetState(pThreadSelf, enmSleepState); 1368 1370 … … 1370 1372 * Don't do deadlock detection if we're recursing. 1371 1373 */ 1374 int rc = VINF_SUCCESS; 1372 1375 PRTLOCKVALRECSHRDOWN pEntry = rtLockValidatorRecSharedFindOwner(&pRecU->Shared, pThreadSelf, NULL); 1373 1376 if (pEntry) 1374 1377 { 1375 if (fRecursiveOk) 1376 return VINF_SUCCESS; 1377 rtLockValidatorComplainFirst("Recursion not allowed", pSrcPos, pThreadSelf, pRecU); 1378 rtLockValidatorComplainPanic(); 1378 if (!fRecursiveOk) 1379 { 1380 rtLockValidatorComplainFirst("Recursion not allowed", pSrcPos, pThreadSelf, pRecU); 1381 rtLockValidatorComplainPanic(); 1382 rc = VERR_SEM_LV_NESTED; 1383 } 1384 } 1385 /* 1386 * Perform deadlock detection. 1387 */ 1388 else if (!rtLockValidatorIsSimpleNoDeadlockCase(pRecU)) 1389 rc = rtLockValidatorDeadlockDetection(pRecU, pThreadSelf, pSrcPos); 1390 1391 if (RT_FAILURE(rc)) 1379 1392 rtThreadSetState(pThreadSelf, enmThreadState); 1380 return VERR_SEM_LV_NESTED; 1381 } 1382 1383 /* 1384 * Perform deadlock detection. 1385 */ 1386 int rc = VINF_SUCCESS; 1387 if (!rtLockValidatorIsSimpleNoDeadlockCase(pRecU)) 1388 { 1389 rc = rtLockValidatorDeadlockDetection(pRecU, pThreadSelf, pSrcPos); 1390 if (RT_FAILURE(rc)) 1391 rtThreadSetState(pThreadSelf, enmThreadState); 1392 } 1393 ASMAtomicWriteBool(&pThreadSelf->LockValidator.fInValidator, false); 1393 1394 return rc; 1394 1395 } … … 1860 1861 1861 1862 1863 RTDECL(bool) RTLockValidatorIsBlockedThreadInValidator(RTTHREAD hThread) 1864 { 1865 bool fRet = false; 1866 PRTTHREADINT pThread = rtThreadGet(hThread); 1867 if (pThread) 1868 { 1869 fRet = ASMAtomicReadBool(&pThread->LockValidator.fInValidator); 1870 rtThreadRelease(pThread); 1871 } 1872 return fRet; 1873 } 1874 RT_EXPORT_SYMBOL(RTLockValidatorIsBlockedThreadInValidator); 1875 1876 1862 1877 RTDECL(bool) RTLockValidatorSetEnabled(bool fEnabled) 1863 1878 { -
trunk/src/VBox/Runtime/common/misc/thread.cpp
r25618 r25622 1305 1305 Assert(RTTHREAD_IS_SLEEPING(enmState)); 1306 1306 PRTTHREADINT pThread = hThread; 1307 if ( hThread && rtThreadGetState(pThread) == RTTHREADSTATE_RUNNING)1307 if (pThread && rtThreadGetState(pThread) == RTTHREADSTATE_RUNNING) 1308 1308 rtThreadSetState(pThread, enmState); 1309 1309 } -
trunk/src/VBox/Runtime/include/internal/lockvalidator.h
r25611 r25622 65 65 /** Number of registered read locks that this thread owns, nesting included. */ 66 66 int32_t volatile cReadLocks; 67 /** The thread is running inside the lock validator. */ 68 bool volatile fInValidator; 69 /** Reserved for alignment purposes. */ 70 bool afReserved[3]; 67 71 /** Bitmap indicating which entires are free (set) and allocated (clear). */ 68 72 uint32_t bmFreeShrdOwners; 69 /** Reserved for alignment purposes. */70 uint32_t u32Reserved;71 73 /** Statically allocated shared owner records */ 72 74 RTLOCKVALRECSHRDOWN aShrdOwners[32]; -
trunk/src/VBox/Runtime/testcase/tstRTLockValidator.cpp
r25621 r25622 53 53 54 54 static uint32_t g_cThreads; 55 static uint32_t volatileg_iDeadlockThread;55 static uint32_t g_iDeadlockThread; 56 56 static RTTHREAD g_ahThreads[32]; 57 57 static RTCRITSECT g_aCritSects[32]; … … 128 128 if ( enmState == enmDesiredState 129 129 && ( !pvLock 130 || pvLock == RTLockValidatorQueryBlocking(hThread))) 130 || ( pvLock == RTLockValidatorQueryBlocking(hThread) 131 && !RTLockValidatorIsBlockedThreadInValidator(hThread) ) 132 ) 133 ) 131 134 return true; 132 135 } 133 else if (enmState != RTTHREADSTATE_RUNNING) 136 else if ( enmState != RTTHREADSTATE_RUNNING 137 && enmState != RTTHREADSTATE_INITIALIZING) 134 138 return false; 135 139 RTThreadSleep(g_fDoNotSpin ? 3600*1000 : iLoop > 256 ? 1 : 0); … … 173 177 } 174 178 } 179 RTThreadSleep(4); /* fudge factor */ 175 180 return VINF_SUCCESS; 176 181 } … … 416 421 for (uint32_t iPass = 0; iPass < cPasses && RTTestErrorCount(g_hTest) == cErrors; iPass++) 417 422 { 418 #if 0 /** @todo figure why this ain't working for either of the two tests! */419 423 g_iDeadlockThread = (cThreads - 1 + iPass) % cThreads; 420 #endif421 424 g_cLoops = 0; 422 425 g_cDeadlocks = 0; … … 493 496 } 494 497 498 495 499 int main() 496 500 { … … 516 520 */ 517 521 test1(3, 1); 518 519 522 test2(1, 1); 520 523 test2(3, 1); … … 525 528 RTLockValidatorSetQuiet(true); 526 529 527 test1( 2, 1024);528 test1( 3, 1024);529 test1( 7, 896);530 test1(10, 768);531 test1(15, 512);532 test1(30, 384);533 534 test2( 1, 100);535 test2( 2, 1024);536 test2( 3, 1024);537 test2( 7, 896);538 test2(10, 768);539 test2(15, 512);540 test2(30, 384);530 test1( 2, 256); /* 256 * 4ms = 1s (approx); 4ms == fudge factor */ 531 test1( 3, 256); 532 test1( 7, 256); 533 test1(10, 256); 534 test1(15, 256); 535 test1(30, 256); 536 537 test2( 1, 256); 538 test2( 2, 256); 539 test2( 3, 256); 540 test2( 7, 256); 541 test2(10, 256); 542 test2(15, 256); 543 test2(30, 256); 541 544 542 545 test3( 2, 1, 2);
Note:
See TracChangeset
for help on using the changeset viewer.