Changeset 25618 in vbox
- Timestamp:
- Jan 2, 2010 12:00:33 PM (15 years ago)
- Location:
- trunk
- Files:
-
- 12 edited
-
include/iprt/lockvalidator.h (modified) (6 diffs)
-
src/VBox/Runtime/common/misc/lockvalidator.cpp (modified) (11 diffs)
-
src/VBox/Runtime/common/misc/thread.cpp (modified) (1 diff)
-
src/VBox/Runtime/generic/critsect-generic.cpp (modified) (2 diffs)
-
src/VBox/Runtime/generic/semrw-generic.cpp (modified) (2 diffs)
-
src/VBox/Runtime/include/internal/thread.h (modified) (2 diffs)
-
src/VBox/Runtime/r3/linux/semmutex-linux.cpp (modified) (1 diff)
-
src/VBox/Runtime/r3/posix/semmutex-posix.cpp (modified) (1 diff)
-
src/VBox/Runtime/r3/posix/semrw-posix.cpp (modified) (2 diffs)
-
src/VBox/Runtime/r3/win/semmutex-win.cpp (modified) (1 diff)
-
src/VBox/Runtime/testcase/tstRTLockValidator.cpp (modified) (11 diffs)
-
src/VBox/VMM/VMMAll/PDMAllCritSect.cpp (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/iprt/lockvalidator.h
r25617 r25618 434 434 435 435 /** 436 * Do deadlock detection before blocking on exclusive access to a lock. 437 * 438 * @retval VINF_SUCCESS 436 * Do deadlock detection before blocking on exclusive access to a lock and 437 * change the thread state. 438 * 439 * @retval VINF_SUCCESS - thread is in the specified sleep state. 439 440 * @retval VERR_SEM_LV_DEADLOCK if blocking would deadlock. Gone thru the 440 441 * motions. … … 450 451 * @param pSrcPos The source position of the lock operation. 451 452 * @param fRecursiveOk Whether it's ok to recurse. 453 * @param enmSleepState The sleep state to enter on successful return. 452 454 */ 453 455 RTDECL(int) RTLockValidatorRecExclCheckBlocking(PRTLOCKVALRECEXCL pRec, RTTHREAD hThreadSelf, 454 PCRTLOCKVALSRCPOS pSrcPos, bool fRecursiveOk); 456 PCRTLOCKVALSRCPOS pSrcPos, bool fRecursiveOk, 457 RTTHREADSTATE enmSleepState); 455 458 456 459 /** … … 463 466 * @param pSrcPos The source position of the lock operation. 464 467 * @param fRecursiveOk Whether it's ok to recurse. 468 * @param enmSleepState The sleep state to enter on successful return. 465 469 */ 466 470 RTDECL(int) RTLockValidatorRecExclCheckOrderAndBlocking(PRTLOCKVALRECEXCL pRec, RTTHREAD hThreadSelf, 467 PCRTLOCKVALSRCPOS pSrcPos, bool fRecursiveOk); 471 PCRTLOCKVALSRCPOS pSrcPos, bool fRecursiveOk, 472 RTTHREADSTATE enmSleepState); 468 473 469 474 /** … … 509 514 510 515 /** 511 * Do deadlock detection before blocking on shared access to a lock. 512 * 513 * @retval VINF_SUCCESS 516 * Do deadlock detection before blocking on shared access to a lock and change 517 * the thread state. 518 * 519 * @retval VINF_SUCCESS - thread is in the specified sleep state. 514 520 * @retval VERR_SEM_LV_DEADLOCK if blocking would deadlock. Gone thru the 515 521 * motions. … … 525 531 * @param pSrcPos The source position of the lock operation. 526 532 * @param fRecursiveOk Whether it's ok to recurse. 533 * @param enmSleepState The sleep state to enter on successful return. 527 534 */ 528 535 RTDECL(int) RTLockValidatorRecSharedCheckBlocking(PRTLOCKVALRECSHRD pRec, RTTHREAD hThreadSelf, 529 PCRTLOCKVALSRCPOS pSrcPos, bool fRecursiveOk); 536 PCRTLOCKVALSRCPOS pSrcPos, bool fRecursiveOk, 537 RTTHREADSTATE enmSleepState); 530 538 531 539 /** … … 540 548 */ 541 549 RTDECL(int) RTLockValidatorRecSharedCheckOrderAndBlocking(PRTLOCKVALRECSHRD pRec, RTTHREAD hThreadSelf, 542 PCRTLOCKVALSRCPOS pSrcPos, bool fRecursiveOk); 550 PCRTLOCKVALSRCPOS pSrcPos, bool fRecursiveOk, 551 RTTHREADSTATE enmSleepState); 543 552 544 553 /** -
trunk/src/VBox/Runtime/common/misc/lockvalidator.cpp
r25617 r25618 1133 1133 1134 1134 RTDECL(int) RTLockValidatorRecExclCheckBlocking(PRTLOCKVALRECEXCL pRec, RTTHREAD hThreadSelf, 1135 PCRTLOCKVALSRCPOS pSrcPos, bool fRecursiveOk) 1135 PCRTLOCKVALSRCPOS pSrcPos, bool fRecursiveOk, 1136 RTTHREADSTATE enmSleepState) 1136 1137 { 1137 1138 /* … … 1149 1150 Assert(pThreadSelf == RTThreadSelf()); 1150 1151 1152 AssertReturn(RTTHREAD_IS_SLEEPING(enmSleepState), VERR_SEM_LV_INVALID_PARAMETER); 1153 1151 1154 RTTHREADSTATE enmThreadState = rtThreadGetState(pThreadSelf); 1152 AssertReturn( enmThreadState == RTTHREADSTATE_RUNNING 1153 || enmThreadState == RTTHREADSTATE_TERMINATED /* rtThreadRemove uses locks too */ 1154 || enmThreadState == RTTHREADSTATE_INITIALIZING /* rtThreadInsert uses locks too */ 1155 , VERR_SEM_LV_INVALID_PARAMETER); 1155 if (RT_UNLIKELY(enmThreadState != RTTHREADSTATE_RUNNING)) 1156 { 1157 AssertReturn( enmThreadState == RTTHREADSTATE_TERMINATED /* rtThreadRemove uses locks too */ 1158 || enmThreadState == RTTHREADSTATE_INITIALIZING /* rtThreadInsert uses locks too */ 1159 , VERR_SEM_LV_INVALID_PARAMETER); 1160 enmSleepState = enmThreadState; 1161 } 1156 1162 1157 1163 /* … … 1160 1166 rtLockValidatorWriteRecUnionPtr(&pThreadSelf->LockValidator.pRec, pRecU); 1161 1167 rtLockValidatorCopySrcPos(&pThreadSelf->LockValidator.SrcPos, pSrcPos); 1168 rtThreadSetState(pThreadSelf, enmSleepState); 1162 1169 1163 1170 /* … … 1173 1180 rtLockValidatorComplainFirst("Recursion not allowed", pSrcPos, pThreadSelf, pRecU); 1174 1181 rtLockValidatorComplainPanic(); 1182 rtThreadSetState(pThreadSelf, enmThreadState); 1175 1183 return VERR_SEM_LV_NESTED; 1176 1184 } … … 1179 1187 * Perform deadlock detection. 1180 1188 */ 1181 if (rtLockValidatorIsSimpleNoDeadlockCase(pRecU)) 1182 return VINF_SUCCESS; 1183 return rtLockValidatorDeadlockDetection(pRecU, pThreadSelf, pSrcPos); 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 return rc; 1184 1197 } 1185 1198 RT_EXPORT_SYMBOL(RTLockValidatorRecExclCheckBlocking); … … 1187 1200 1188 1201 RTDECL(int) RTLockValidatorRecExclCheckOrderAndBlocking(PRTLOCKVALRECEXCL pRec, RTTHREAD hThreadSelf, 1189 PCRTLOCKVALSRCPOS pSrcPos, bool fRecursiveOk) 1202 PCRTLOCKVALSRCPOS pSrcPos, bool fRecursiveOk, 1203 RTTHREADSTATE enmSleepState) 1190 1204 { 1191 1205 int rc = RTLockValidatorRecExclCheckOrder(pRec, hThreadSelf, pSrcPos); 1192 1206 if (RT_SUCCESS(rc)) 1193 rc = RTLockValidatorRecExclCheckBlocking(pRec, hThreadSelf, pSrcPos, fRecursiveOk );1207 rc = RTLockValidatorRecExclCheckBlocking(pRec, hThreadSelf, pSrcPos, fRecursiveOk, enmSleepState); 1194 1208 return rc; 1195 1209 } … … 1318 1332 1319 1333 RTDECL(int) RTLockValidatorRecSharedCheckBlocking(PRTLOCKVALRECSHRD pRec, RTTHREAD hThreadSelf, 1320 PCRTLOCKVALSRCPOS pSrcPos, bool fRecursiveOk) 1334 PCRTLOCKVALSRCPOS pSrcPos, bool fRecursiveOk, 1335 RTTHREADSTATE enmSleepState) 1321 1336 { 1322 1337 /* … … 1334 1349 Assert(pThreadSelf == RTThreadSelf()); 1335 1350 1351 AssertReturn(RTTHREAD_IS_SLEEPING(enmSleepState), VERR_SEM_LV_INVALID_PARAMETER); 1352 1336 1353 RTTHREADSTATE enmThreadState = rtThreadGetState(pThreadSelf); 1337 AssertReturn( enmThreadState == RTTHREADSTATE_RUNNING 1338 || enmThreadState == RTTHREADSTATE_TERMINATED /* rtThreadRemove uses locks too */ 1339 || enmThreadState == RTTHREADSTATE_INITIALIZING /* rtThreadInsert uses locks too */ 1340 , VERR_SEM_LV_INVALID_PARAMETER); 1354 if (RT_UNLIKELY(enmThreadState != RTTHREADSTATE_RUNNING)) 1355 { 1356 AssertReturn( enmThreadState == RTTHREADSTATE_TERMINATED /* rtThreadRemove uses locks too */ 1357 || enmThreadState == RTTHREADSTATE_INITIALIZING /* rtThreadInsert uses locks too */ 1358 , VERR_SEM_LV_INVALID_PARAMETER); 1359 enmSleepState = enmThreadState; 1360 } 1341 1361 1342 1362 /* … … 1345 1365 rtLockValidatorWriteRecUnionPtr(&pThreadSelf->LockValidator.pRec, pRecU); 1346 1366 rtLockValidatorCopySrcPos(&pThreadSelf->LockValidator.SrcPos, pSrcPos); 1367 rtThreadSetState(pThreadSelf, enmSleepState); 1347 1368 1348 1369 /* … … 1356 1377 rtLockValidatorComplainFirst("Recursion not allowed", pSrcPos, pThreadSelf, pRecU); 1357 1378 rtLockValidatorComplainPanic(); 1379 rtThreadSetState(pThreadSelf, enmThreadState); 1358 1380 return VERR_SEM_LV_NESTED; 1359 1381 } … … 1362 1384 * Perform deadlock detection. 1363 1385 */ 1364 if (rtLockValidatorIsSimpleNoDeadlockCase(pRecU)) 1365 return VINF_SUCCESS; 1366 return rtLockValidatorDeadlockDetection(pRecU, pThreadSelf, pSrcPos); 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 return rc; 1367 1394 } 1368 1395 RT_EXPORT_SYMBOL(RTLockValidatorRecSharedCheckBlocking); 1369 1396 1370 1397 1371 RTDECL(int) RTLockValidatorRecSharedCheckOrderAndBlocking(PRTLOCKVALRECSHRD pRec, RTTHREAD hThreadSelf, PCRTLOCKVALSRCPOS pSrcPos, bool fRecursiveOk) 1398 RTDECL(int) RTLockValidatorRecSharedCheckOrderAndBlocking(PRTLOCKVALRECSHRD pRec, RTTHREAD hThreadSelf, 1399 PCRTLOCKVALSRCPOS pSrcPos, bool fRecursiveOk, 1400 RTTHREADSTATE enmSleepState) 1372 1401 { 1373 1402 int rc = RTLockValidatorRecSharedCheckOrder(pRec, hThreadSelf, pSrcPos); 1374 1403 if (RT_SUCCESS(rc)) 1375 rc = RTLockValidatorRecSharedCheckBlocking(pRec, hThreadSelf, pSrcPos, fRecursiveOk );1404 rc = RTLockValidatorRecSharedCheckBlocking(pRec, hThreadSelf, pSrcPos, fRecursiveOk, enmSleepState); 1376 1405 return rc; 1377 1406 } -
trunk/src/VBox/Runtime/common/misc/thread.cpp
r25611 r25618 196 196 } 197 197 198 199 /**200 * Sets the thread state.201 *202 * @param pThread The thread.203 * @param enmNewState The new thread state.204 */205 DECLINLINE(void) rtThreadSetState(PRTTHREADINT pThread, RTTHREADSTATE enmNewState)206 {207 AssertCompile(sizeof(pThread->enmState) == sizeof(uint32_t));208 ASMAtomicWriteU32((uint32_t volatile *)&pThread->enmState, enmNewState);209 }210 198 211 199 #ifdef IN_RING3 -
trunk/src/VBox/Runtime/generic/critsect-generic.cpp
r25614 r25618 209 209 #ifdef RTCRITSECT_STRICT 210 210 int rc9 = RTLockValidatorRecExclCheckBlocking(pCritSect->pValidatorRec, hThreadSelf, pSrcPos, 211 !(pCritSect->fFlags & RTCRITSECT_FLAGS_NO_NESTING)); 211 !(pCritSect->fFlags & RTCRITSECT_FLAGS_NO_NESTING), 212 RTTHREADSTATE_CRITSECT); 212 213 if (RT_FAILURE(rc9)) 213 214 { … … 215 216 return rc9; 216 217 } 217 #endif 218 218 #else 219 219 RTThreadBlocking(hThreadSelf, RTTHREADSTATE_CRITSECT); 220 #endif 220 221 int rc = RTSemEventWait(pCritSect->EventSem, RT_INDEFINITE_WAIT); 221 222 RTThreadUnblocked(hThreadSelf, RTTHREADSTATE_CRITSECT); -
trunk/src/VBox/Runtime/generic/semrw-generic.cpp
r25616 r25618 320 320 } 321 321 #ifdef RTSEMRW_STRICT 322 rc = RTLockValidatorRecSharedCheckBlocking(&pThis->ValidatorRead, hThreadSelf, pSrcPos, true );322 rc = RTLockValidatorRecSharedCheckBlocking(&pThis->ValidatorRead, hThreadSelf, pSrcPos, true, RTTHREADSTATE_RW_READ); 323 323 if (RT_FAILURE(rc)) 324 324 break; 325 #e ndif325 #else 326 326 RTThreadBlocking(hThreadSelf, RTTHREADSTATE_RW_READ); 327 327 #endif 328 328 int rcWait = rc = RTSemEventMultiWait(pThis->ReadEvent, cMillies); 329 329 RTThreadUnblocked(hThreadSelf, RTTHREADSTATE_RW_READ); … … 572 572 } 573 573 } 574 #ifdef RTSEMRW_STRICT 575 rc = RTLockValidatorRecExclCheckBlocking(&pThis->ValidatorWrite, hThreadSelf, pSrcPos, true); 574 575 #ifdef RTSEMRW_STRICT 576 rc = RTLockValidatorRecExclCheckBlocking(&pThis->ValidatorWrite, hThreadSelf, pSrcPos, true, RTTHREADSTATE_RW_WRITE); 576 577 if (RT_FAILURE(rc)) 577 578 break; 578 #e ndif579 #else 579 580 RTThreadBlocking(hThreadSelf, RTTHREADSTATE_RW_WRITE); 581 #endif 580 582 int rcWait = rc = RTSemEventWait(pThis->WriteEvent, cMillies); 581 583 RTThreadUnblocked(hThreadSelf, RTTHREADSTATE_RW_WRITE); -
trunk/src/VBox/Runtime/include/internal/thread.h
r25611 r25618 196 196 #endif 197 197 198 #ifdef ___iprt_asm_h 199 198 200 /** 199 201 * Gets the thread state. … … 207 209 } 208 210 211 /** 212 * Sets the thread state. 213 * 214 * @param pThread The thread. 215 * @param enmNewState The new thread state. 216 */ 217 DECLINLINE(void) rtThreadSetState(PRTTHREADINT pThread, RTTHREADSTATE enmNewState) 218 { 219 AssertCompile(sizeof(pThread->enmState) == sizeof(uint32_t)); 220 ASMAtomicWriteU32((uint32_t volatile *)&pThread->enmState, enmNewState); 221 } 222 223 #endif 224 209 225 RT_C_DECLS_END 210 226 -
trunk/src/VBox/Runtime/r3/linux/semmutex-linux.cpp
r25614 r25618 240 240 { 241 241 #ifdef RTSEMMUTEX_STRICT 242 int rc9 = RTLockValidatorRecExclCheckBlocking(&pThis->ValidatorRec, hThreadSelf, pSrcPos, true );242 int rc9 = RTLockValidatorRecExclCheckBlocking(&pThis->ValidatorRec, hThreadSelf, pSrcPos, true, RTTHREADSTATE_MUTEX); 243 243 if (RT_FAILURE(rc9)) 244 244 return rc9; 245 #e ndif245 #else 246 246 RTThreadBlocking(hThreadSelf, RTTHREADSTATE_MUTEX); 247 #endif 247 248 } 248 249 -
trunk/src/VBox/Runtime/r3/posix/semmutex-posix.cpp
r25614 r25618 188 188 #ifdef RTSEMMUTEX_STRICT 189 189 hThreadSelf = RTThreadSelfAutoAdopt(); 190 int rc9 = RTLockValidatorRecExclCheckOrderAndBlocking(&pThis->ValidatorRec, hThreadSelf, pSrcPos, true );190 int rc9 = RTLockValidatorRecExclCheckOrderAndBlocking(&pThis->ValidatorRec, hThreadSelf, pSrcPos, true, RTTHREADSTATE_MUTEX); 191 191 if (RT_FAILURE(rc9)) 192 192 return rc9; 193 193 #else 194 194 hThreadSelf = RTThreadSelf(); 195 #endif196 195 RTThreadBlocking(hThreadSelf, RTTHREADSTATE_MUTEX); 196 #endif 197 197 } 198 198 -
trunk/src/VBox/Runtime/r3/posix/semrw-posix.cpp
r25616 r25618 219 219 #ifdef RTSEMRW_STRICT 220 220 hThreadSelf = RTThreadSelfAutoAdopt(); 221 int rc9 = RTLockValidatorRecSharedCheckOrderAndBlocking(&pThis->ValidatorRead, hThreadSelf, pSrcPos, true );221 int rc9 = RTLockValidatorRecSharedCheckOrderAndBlocking(&pThis->ValidatorRead, hThreadSelf, pSrcPos, true, RTTHREADSTATE_RW_READ); 222 222 if (RT_FAILURE(rc9)) 223 223 return rc9; 224 224 #else 225 225 hThreadSelf = RTThreadSelf(); 226 #endif227 226 RTThreadBlocking(hThreadSelf, RTTHREADSTATE_RW_READ); 227 #endif 228 228 } 229 229 … … 381 381 #ifdef RTSEMRW_STRICT 382 382 hThreadSelf = RTThreadSelfAutoAdopt(); 383 int rc9 = RTLockValidatorRecExclCheckOrderAndBlocking(&pThis->ValidatorWrite, hThreadSelf, pSrcPos, true );383 int rc9 = RTLockValidatorRecExclCheckOrderAndBlocking(&pThis->ValidatorWrite, hThreadSelf, pSrcPos, true, RTTHREADSTATE_RW_WRITE); 384 384 if (RT_FAILURE(rc9)) 385 385 return rc9; 386 386 #else 387 387 hThreadSelf = RTThreadSelf(); 388 #endif389 388 RTThreadBlocking(hThreadSelf, RTTHREADSTATE_RW_WRITE); 389 #endif 390 390 } 391 391 -
trunk/src/VBox/Runtime/r3/win/semmutex-win.cpp
r25614 r25618 159 159 #ifdef RTSEMMUTEX_STRICT 160 160 hThreadSelf = RTThreadSelfAutoAdopt(); 161 int rc9 = RTLockValidatorRecExclCheckOrderAndBlocking(&pThis->ValidatorRec, hThreadSelf, pSrcPos, true );161 int rc9 = RTLockValidatorRecExclCheckOrderAndBlocking(&pThis->ValidatorRec, hThreadSelf, pSrcPos, true, RTTHREADSTATE_MUTEX); 162 162 if (RT_FAILURE(rc9)) 163 163 return rc9; 164 164 #else 165 165 hThreadSelf = RTThreadSelf(); 166 #endif167 166 RTThreadBlocking(hThreadSelf, RTTHREADSTATE_MUTEX); 167 #endif 168 168 } 169 169 int rc = WaitForSingleObjectEx(pThis->hMtx, -
trunk/src/VBox/Runtime/testcase/tstRTLockValidator.cpp
r25617 r25618 41 41 #include <iprt/test.h> 42 42 #include <iprt/thread.h> 43 #include <iprt/time.h> 43 44 44 45 … … 47 48 *******************************************************************************/ 48 49 /** The testcase handle. */ 49 static RTTEST g_hTest;50 static RTTEST g_hTest; 50 51 /** Flip this in the debugger to get some peace to single step wild code. */ 51 bool volatile g_fDoNotSpin = false;52 bool volatile g_fDoNotSpin = false; 52 53 53 54 static uint32_t g_cThreads; … … 56 57 static RTCRITSECT g_aCritSects[32]; 57 58 static RTSEMRW g_ahSemRWs[32]; 59 60 /** When to stop testing. */ 61 static uint64_t g_NanoTSStop; 62 /** The number of deadlocks. */ 63 static uint32_t volatile g_cDeadlocks; 64 /** The number of loops. */ 65 static uint32_t volatile g_cLoops; 58 66 59 67 … … 281 289 282 290 283 static void testIt(uint32_t cThreads, uint32_t cPasses, PFNRTTHREAD pfnThread, const char *pszName) 291 static DECLCALLBACK(int) test3Thread(RTTHREAD ThreadSelf, void *pvUser) 292 { 293 uintptr_t i = (uintptr_t)pvUser; 294 RTSEMRW hMine = g_ahSemRWs[i]; 295 RTSEMRW hNext = g_ahSemRWs[(i + 1) % g_cThreads]; 296 int rc; 297 298 if (i & 1) 299 RTTEST_CHECK_RC_RET(g_hTest, RTSemRWRequestWrite(hMine, RT_INDEFINITE_WAIT), VINF_SUCCESS, rcCheck); 300 else 301 RTTEST_CHECK_RC_RET(g_hTest, RTSemRWRequestRead(hMine, RT_INDEFINITE_WAIT), VINF_SUCCESS, rcCheck); 302 if (testWaitForSemRWToBeOwned(hNext)) 303 { 304 do 305 { 306 rc = RTSemRWRequestWrite(hNext, 60*1000); 307 if (rc != VINF_SUCCESS && rc != VERR_SEM_LV_DEADLOCK && rc != VERR_SEM_LV_ILLEGAL_UPGRADE) 308 { 309 RTTestFailed(g_hTest, "#%u: RTSemRWRequestWrite -> %Rrc\n", i, rc); 310 break; 311 } 312 if (RT_SUCCESS(rc)) 313 { 314 RTTEST_CHECK_RC(g_hTest, rc = RTSemRWReleaseWrite(hNext), VINF_SUCCESS); 315 if (RT_FAILURE(rc)) 316 break; 317 } 318 else 319 ASMAtomicIncU32(&g_cDeadlocks); 320 ASMAtomicIncU32(&g_cLoops); 321 } while (RTTimeNanoTS() < g_NanoTSStop); 322 } 323 if (i & 1) 324 RTTEST_CHECK_RC(g_hTest, RTSemRWReleaseWrite(hMine), VINF_SUCCESS); 325 else 326 RTTEST_CHECK_RC(g_hTest, RTSemRWReleaseRead(hMine), VINF_SUCCESS); 327 RTTEST_CHECK(g_hTest, RTThreadGetState(RTThreadSelf()) == RTTHREADSTATE_RUNNING); 328 return VINF_SUCCESS; 329 } 330 331 332 static void testIt(uint32_t cThreads, uint32_t cPasses, uint64_t cNanoSecs, PFNRTTHREAD pfnThread, const char *pszName) 284 333 { 285 334 RTTestSubF(g_hTest, "%s, %u threads, %u passes", pszName, cThreads, cPasses); … … 297 346 } 298 347 299 uint32_t cErrors = RTTestErrorCount(g_hTest); 348 uint32_t cLoops = 0; 349 uint32_t cDeadlocks = 0; 350 uint32_t cErrors = RTTestErrorCount(g_hTest); 300 351 for (uint32_t iPass = 0; iPass < cPasses && RTTestErrorCount(g_hTest) == cErrors; iPass++) 301 352 { … … 303 354 g_iDeadlockThread = (cThreads - 1 + iPass) % cThreads; 304 355 #endif 356 g_cLoops = 0; 357 g_cDeadlocks = 0; 358 g_NanoTSStop = cNanoSecs ? RTTimeNanoTS() + cNanoSecs : 0; 359 305 360 int rc = testStartThreads(cThreads, pfnThread); 306 361 if (RT_SUCCESS(rc)) 307 testWaitForThreads(30*1000, true); 362 testWaitForThreads(30*1000 + cNanoSecs / 1000000, true); 363 364 RTTEST_CHECK(g_hTest, !cNanoSecs || g_cLoops > 0); 365 cLoops += g_cLoops; 366 RTTEST_CHECK(g_hTest, !cNanoSecs || g_cDeadlocks > 0); 367 cDeadlocks += g_cDeadlocks; 308 368 } 309 369 … … 314 374 } 315 375 testWaitForThreads(10*1000, false); 376 377 if (cNanoSecs) 378 RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "cLoops=%u cDeadlocks=%u (%u%%)\n", 379 cLoops, cDeadlocks, cLoops ? cDeadlocks * 100 / cLoops : 0); 316 380 } 317 381 … … 319 383 static void test1(uint32_t cThreads, uint32_t cPasses) 320 384 { 321 testIt(cThreads, cPasses, test1Thread, "critsect");385 testIt(cThreads, cPasses, 0, test1Thread, "critsect"); 322 386 } 323 387 … … 325 389 static void test2(uint32_t cThreads, uint32_t cPasses) 326 390 { 327 testIt(cThreads, cPasses, test2Thread, "read-write"); 391 testIt(cThreads, cPasses, 0, test2Thread, "read-write"); 392 } 393 394 395 static void test3(uint32_t cThreads, uint32_t cPasses, uint64_t cNanoSecs) 396 { 397 testIt(cThreads, cPasses, cNanoSecs, test3Thread, "read-write race"); 328 398 } 329 399 … … 383 453 */ 384 454 RTLockValidatorSetQuiet(true); 385 455 #if 0 386 456 test1( 2, 1024); 387 457 test1( 3, 1024); … … 398 468 test2(15, 512); 399 469 test2(30, 384); 400 470 #endif 471 472 test3( 2, 2, 5*UINT64_C(1000000000)); 473 test3(10, 1, 5*UINT64_C(1000000000)); 401 474 402 475 return RTTestSummaryAndDestroy(g_hTest); -
trunk/src/VBox/VMM/VMMAll/PDMAllCritSect.cpp
r25614 r25618 139 139 # ifdef PDMCRITSECT_STRICT 140 140 int rc9 = RTLockValidatorRecExclCheckBlocking(pCritSect->s.Core.pValidatorRec, hThreadSelf, pSrcPos, 141 !(pCritSect->s.Core.fFlags & RTCRITSECT_FLAGS_NO_NESTING)); 141 !(pCritSect->s.Core.fFlags & RTCRITSECT_FLAGS_NO_NESTING), 142 RTTHREADSTATE_CRITSECT); 142 143 if (RT_FAILURE(rc9)) 143 144 return rc9; 144 # endif 145 145 # else 146 146 RTThreadBlocking(hThreadSelf, RTTHREADSTATE_CRITSECT); 147 # endif 147 148 int rc = SUPSemEventWaitNoResume(pSession, hEvent, RT_INDEFINITE_WAIT); 148 149 RTThreadUnblocked(hThreadSelf, RTTHREADSTATE_CRITSECT);
Note:
See TracChangeset
for help on using the changeset viewer.

