Changeset 25478 in vbox
- Timestamp:
- Dec 18, 2009 12:58:10 PM (15 years ago)
- Location:
- trunk
- Files:
-
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/iprt/lockvalidator.h
r25467 r25478 44 44 RT_C_DECLS_BEGIN 45 45 46 /** 47 * Record recording the ownership of a lock. 48 * 49 * This is typically part of the per-lock data structure when compiling with 50 * the lock validator. 51 */ 52 typedef struct RTLOCKVALIDATORREC 46 typedef struct RTLOCKVALIDATORSRCPOS 53 47 { 54 /** Magic value (RTLOCKVALIDATORREC_MAGIC). */55 uint32_t u32Magic;56 /** The line number in the file. */57 uint32_t volatile uLine;58 48 /** The file where the lock was taken. */ 59 49 R3R0PTRTYPE(const char * volatile) pszFile; … … 62 52 /** Some ID indicating where the lock was taken, typically an address. */ 63 53 RTHCUINTPTR volatile uId; 54 /** The line number in the file. */ 55 uint32_t volatile uLine; 56 #if HC_ARCH_BITS == 64 57 uint32_t u32Padding; /**< Alignment padding. */ 58 #endif 59 } RTLOCKVALIDATORSRCPOS; 60 AssertCompileSize(RTLOCKVALIDATORSRCPOS, HC_ARCH_BITS == 32 ? 16 : 32); 61 /* The pointer types are defined in iprt/types.h. */ 62 63 /** @def RTLOCKVALIDATORSRCPOS_INIT 64 * Initializer for a RTLOCKVALIDATORSRCPOS variable. 65 * 66 * @param pszFile The file name. Optional (NULL). 67 * @param uLine The line number in that file. Optional (0). 68 * @param pszFunction The function. Optional (NULL). 69 * @param uId Some location ID, normally the return address. 70 * Optional (NULL). 71 */ 72 #if HC_ARCH_BITS == 64 73 # define RTLOCKVALIDATORSRCPOS_INIT(pszFile, uLine, pszFunction, uId) \ 74 { (pszFile), (pszFunction), (uId), (uLine), 0 } 75 #else 76 # define RTLOCKVALIDATORSRCPOS_INIT(pszFile, uLine, pszFunction, uId) \ 77 { (pszFile), (pszFunction), (uId), (uLine) } 78 #endif 79 80 /** @def RTLOCKVALIDATORSRCPOS_INIT_DEBUG_API 81 * Initializer for a RTLOCKVALIDATORSRCPOS variable in a typicial debug API 82 * variant. Assumes RT_SRC_POS_DECL and RTHCUINTPTR uId as arguments. 83 */ 84 #define RTLOCKVALIDATORSRCPOS_INIT_DEBUG_API() \ 85 RTLOCKVALIDATORSRCPOS_INIT(pszFile, iLine, pszFunction, uId) 86 87 /** @def RTLOCKVALIDATORSRCPOS_INIT_NORMAL_API 88 * Initializer for a RTLOCKVALIDATORSRCPOS variable in a normal API 89 * variant. Assumes iprt/asm.h is included. 90 */ 91 #define RTLOCKVALIDATORSRCPOS_INIT_NORMAL_API() \ 92 RTLOCKVALIDATORSRCPOS_INIT(__FILE__, __LINE__, __PRETTY_FUNCTION__, (uintptr_t)ASMReturnAddress()) 93 94 95 /** 96 * Record recording the ownership of a lock. 97 * 98 * This is typically part of the per-lock data structure when compiling with 99 * the lock validator. 100 */ 101 typedef struct RTLOCKVALIDATORREC 102 { 103 /** Magic value (RTLOCKVALIDATORREC_MAGIC). */ 104 uint32_t u32Magic; 105 /** Reserved. */ 106 uint32_t u32Reserved; 107 /** Source position where the lock was taken. */ 108 RTLOCKVALIDATORSRCPOS SrcPos; 64 109 /** The current owner thread. */ 65 110 RTTHREAD volatile hThread; … … 76 121 /** The lock name. */ 77 122 R3R0PTRTYPE(const char *) pszName; 123 /** Reserved. */ 124 RTHCPTR pvReserved; 78 125 } RTLOCKVALIDATORREC; 79 AssertCompileSize(RTLOCKVALIDATORREC, HC_ARCH_BITS == 32 ? 48 : 80); 80 /* The pointer is defined in iprt/types.h */ 126 AssertCompileSize(RTLOCKVALIDATORREC, HC_ARCH_BITS == 32 ? 8 + 16 + 32 : 8 + 32 + 56); 127 /* The pointer type is defined in iprt/types.h. */ 128 129 /** Pointer to a record of one ownership share. */ 130 typedef struct RTLOCKVALIDATORSHAREDREC *PRTLOCKVALIDATORSHAREDREC; 131 /** 132 * For recording the one ownership share. 133 */ 134 typedef struct RTLOCKVALIDATORSHAREDONE 135 { 136 /** Magic value (RTLOCKVALIDATORSHAREDONE_MAGIC). */ 137 uint32_t u32Magic; 138 /** Recursion count */ 139 uint32_t cRecursion; 140 /** The current owner thread. */ 141 RTTHREAD volatile hThread; 142 /** Pointer to the lock record below us. Only accessed by the owner. */ 143 R3R0PTRTYPE(PRTLOCKVALIDATORREC) pDown; 144 /** Pointer back to the shared record. */ 145 R3R0PTRTYPE(PRTLOCKVALIDATORSHAREDREC) pSharedRec; 146 #if HC_ARCH_BITS == 32 147 /** Reserved. */ 148 RTHCPTR pvReserved; 149 #endif 150 /** Source position where the lock was taken. */ 151 RTLOCKVALIDATORSRCPOS SrcPos; 152 } RTLOCKVALIDATORSHAREDONE; 153 AssertCompileSize(RTLOCKVALIDATORSHAREDONE, HC_ARCH_BITS == 32 ? 24 + 16 : 32 + 32); 154 /** Pointer to a RTLOCKVALIDATORSHAREDONE. */ 155 typedef RTLOCKVALIDATORSHAREDONE *PRTLOCKVALIDATORSHAREDONE; 156 157 /** 158 * Record recording the shared ownership of a lock. 159 * 160 * This is typically part of the per-lock data structure when compiling with 161 * the lock validator. 162 */ 163 typedef struct RTLOCKVALIDATORSHARED 164 { 165 /** Magic value (RTLOCKVALIDATORSHARED_MAGIC). */ 166 uint32_t u32Magic; 167 /** The lock sub-class. */ 168 uint32_t volatile uSubClass; 169 /** The lock class. */ 170 RTLOCKVALIDATORCLASS hClass; 171 /** Pointer to the lock. */ 172 RTHCPTR hLock; 173 /** The lock name. */ 174 R3R0PTRTYPE(const char *) pszName; 175 176 /** The number of entries in the table. 177 * Updated before inserting and after removal. */ 178 uint32_t volatile cEntries; 179 /** The index of the last entry (approximately). */ 180 uint32_t volatile iLastEntry; 181 /** The max table size. */ 182 uint32_t volatile cAllocated; 183 /** Set if the table is being reallocated, clear if not. 184 * This is used together with rtLockValidatorSerializeDetectionEnter to make 185 * sure there is exactly one thread doing the reallocation and that nobody is 186 * using the table at that point. */ 187 bool volatile fReallocating; 188 /** Alignment padding. */ 189 bool afPadding[3]; 190 /** Pointer to a table containing pointers to records of all the owners. */ 191 R3R0PTRTYPE(PRTLOCKVALIDATORSHAREDONE volatile *) papOwners; 192 /** Alignment padding. */ 193 uint64_t u64Alignment; 194 } RTLOCKVALIDATORSHARED; 195 AssertCompileSize(RTLOCKVALIDATORSHARED, HC_ARCH_BITS == 32 ? 20 + 20 + 8 : 32 + 32); 196 /** Pointer to a RTLOCKVALIDATORSHARED. */ 197 typedef RTLOCKVALIDATORSHARED *PRTLOCKVALIDATORSHARED; 81 198 82 199 … … 158 275 * pass NIL_RTTHREAD and this method will figure it 159 276 * out. 160 * @param uId Some kind of locking location ID. Typically a 161 * return address up the stack. Optional (0). 162 * @param pszFile The file where the lock is being acquired from. 163 * Optional. 164 * @param iLine The line number in that file. Optional (0). 165 * @param pszFunction The functionn where the lock is being acquired 166 * from. Optional. 167 */ 168 RTDECL(int) RTLockValidatorCheckOrder(PRTLOCKVALIDATORREC pRec, RTTHREAD hThread, RTHCUINTPTR uId, RT_SRC_POS_DECL); 169 170 /** 171 * Change the thread state to blocking and do deadlock detection. 277 * @param pSrcPos The source position of the lock operation. 278 */ 279 RTDECL(int) RTLockValidatorCheckOrder(PRTLOCKVALIDATORREC pRec, RTTHREAD hThread, PCRTLOCKVALIDATORSRCPOS pSrcPos); 280 281 /** 282 * Do deadlock detection before blocking on a lock. 172 283 * 173 284 * @retval VINF_SUCCESS … … 183 294 * @param pvBlock Pointer to a RTLOCKVALIDATORREC structure. 184 295 * @param fRecursiveOk Whether it's ok to recurse. 185 * @param uId Where we are blocking. 186 * @param RT_SRC_POS_DECL Where we are blocking. 296 * @param pSrcPos The source position of the lock operation. 187 297 */ 188 298 RTDECL(int) RTLockValidatorCheckBlocking(PRTLOCKVALIDATORREC pRec, RTTHREAD hThread, 189 299 RTTHREADSTATE enmState, bool fRecursiveOk, 190 RTHCUINTPTR uId, RT_SRC_POS_DECL);300 PCRTLOCKVALIDATORSRCPOS pSrcPos); 191 301 192 302 /** … … 213 323 * 214 324 * @param pRec The validator record. 215 * @param uId Some kind of locking location ID. Typically a 216 * return address up the stack. Optional (0). 217 * @param pszFile The file where the lock is being acquired from. 218 * Optional. 219 * @param iLine The line number in that file. Optional (0). 220 * @param pszFunction The functionn where the lock is being acquired 221 * from. Optional. 222 */ 223 RTDECL(int) RTLockValidatorRecordRecursion(PRTLOCKVALIDATORREC pRec, RTHCUINTPTR uId, RT_SRC_POS_DECL); 325 * @param pSrcPos The source position of the lock operation. 326 */ 327 RTDECL(int) RTLockValidatorRecordRecursion(PRTLOCKVALIDATORREC pRec, PCRTLOCKVALIDATORSRCPOS pSrcPos); 224 328 225 329 /** … … 244 348 * pass NIL_RTTHREAD and this method will figure it 245 349 * out. 246 * @param uId Some kind of locking location ID. Typically a 247 * return address up the stack. Optional (0). 248 * @param pszFile The file where the lock is being acquired from. 249 * Optional. 250 * @param iLine The line number in that file. Optional (0). 251 * @param pszFunction The functionn where the lock is being acquired 252 * from. Optional. 253 */ 254 RTDECL(RTTHREAD) RTLockValidatorSetOwner(PRTLOCKVALIDATORREC pRec, RTTHREAD hThread, RTHCUINTPTR uId, RT_SRC_POS_DECL); 350 * @param pSrcPos The source position of the lock operation. 351 */ 352 RTDECL(RTTHREAD) RTLockValidatorSetOwner(PRTLOCKVALIDATORREC pRec, RTTHREAD hThread, PCRTLOCKVALIDATORSRCPOS pSrcPos); 255 353 256 354 -
trunk/include/iprt/thread.h
r25409 r25478 34 34 #include <iprt/types.h> 35 35 #include <iprt/stdarg.h> 36 37 #ifdef IN_RC38 # error "There are no threading APIs available Guest Context!"39 #endif40 41 36 42 37 … … 89 84 90 85 /** 91 * Get the thread handle of the current thread.92 *93 * @returns Thread handle.94 */95 RTDECL(RTTHREAD) RTThreadSelf(void);96 97 /**98 * Get the thread handle of the current thread, automatically adopting alien99 * threads.100 *101 * @returns Thread handle.102 */103 RTDECL(RTTHREAD) RTThreadSelfAutoAdopt(void);104 105 /**106 * Get the native thread handle of the current thread.107 *108 * @returns Native thread handle.109 */110 RTDECL(RTNATIVETHREAD) RTThreadNativeSelf(void);111 112 /**113 * Millisecond granular sleep function.114 *115 * @returns VINF_SUCCESS on success.116 * @returns VERR_INTERRUPTED if a signal or other asynchronous stuff happend117 * which interrupt the peaceful sleep.118 * @param cMillies Number of milliseconds to sleep.119 * 0 milliseconds means yielding the timeslice - deprecated!120 * @remark See RTThreadNanoSleep() for sleeping for smaller periods of time.121 */122 RTDECL(int) RTThreadSleep(unsigned cMillies);123 124 /**125 * Yields the CPU.126 *127 * @returns true if we yielded.128 * @returns false if it's probable that we didn't yield.129 */130 RTDECL(bool) RTThreadYield(void);131 132 133 134 /**135 * Thread function.136 *137 * @returns 0 on success.138 * @param ThreadSelf Thread handle to this thread.139 * @param pvUser User argument.140 */141 typedef DECLCALLBACK(int) FNRTTHREAD(RTTHREAD ThreadSelf, void *pvUser);142 /** Pointer to a FNRTTHREAD(). */143 typedef FNRTTHREAD *PFNRTTHREAD;144 145 /**146 86 * Thread types. 147 87 * Besides identifying the purpose of the thread, the thread type is … … 225 165 } RTTHREADTYPE; 226 166 167 168 #ifndef IN_RC 169 170 /** 171 * Get the thread handle of the current thread. 172 * 173 * @returns Thread handle. 174 */ 175 RTDECL(RTTHREAD) RTThreadSelf(void); 176 177 /** 178 * Get the thread handle of the current thread, automatically adopting alien 179 * threads. 180 * 181 * @returns Thread handle. 182 */ 183 RTDECL(RTTHREAD) RTThreadSelfAutoAdopt(void); 184 185 /** 186 * Get the native thread handle of the current thread. 187 * 188 * @returns Native thread handle. 189 */ 190 RTDECL(RTNATIVETHREAD) RTThreadNativeSelf(void); 191 192 /** 193 * Millisecond granular sleep function. 194 * 195 * @returns VINF_SUCCESS on success. 196 * @returns VERR_INTERRUPTED if a signal or other asynchronous stuff happend 197 * which interrupt the peaceful sleep. 198 * @param cMillies Number of milliseconds to sleep. 199 * 0 milliseconds means yielding the timeslice - deprecated! 200 * @remark See RTThreadNanoSleep() for sleeping for smaller periods of time. 201 */ 202 RTDECL(int) RTThreadSleep(unsigned cMillies); 203 204 /** 205 * Yields the CPU. 206 * 207 * @returns true if we yielded. 208 * @returns false if it's probable that we didn't yield. 209 */ 210 RTDECL(bool) RTThreadYield(void); 211 212 213 214 /** 215 * Thread function. 216 * 217 * @returns 0 on success. 218 * @param ThreadSelf Thread handle to this thread. 219 * @param pvUser User argument. 220 */ 221 typedef DECLCALLBACK(int) FNRTTHREAD(RTTHREAD ThreadSelf, void *pvUser); 222 /** Pointer to a FNRTTHREAD(). */ 223 typedef FNRTTHREAD *PFNRTTHREAD; 227 224 228 225 /** … … 443 440 RTDECL(int) RTThreadPoke(RTTHREAD hThread); 444 441 445 # ifdef IN_RING0442 # ifdef IN_RING0 446 443 447 444 /** … … 490 487 /** In debug builds this will be used to check for cpu migration. */ 491 488 RTCPUID idCpu; 492 # ifdef RT_OS_WINDOWS489 # ifdef RT_OS_WINDOWS 493 490 /** The old IRQL. Don't touch! */ 494 491 unsigned char uchOldIrql; … … 499 496 /** Reserved, MBZ. */ 500 497 uint8_t bReserved3; 501 # define RTTHREADPREEMPTSTATE_INITIALIZER { NIL_RTCPUID, 255, 0, 0, 0 }502 # elif defined(RT_OS_SOLARIS)498 # define RTTHREADPREEMPTSTATE_INITIALIZER { NIL_RTCPUID, 255, 0, 0, 0 } 499 # elif defined(RT_OS_SOLARIS) 503 500 /** The Old PIL. Don't touch! */ 504 501 uint32_t uOldPil; 505 # define RTTHREADPREEMPTSTATE_INITIALIZER { NIL_RTCPUID, UINT32_MAX }506 # else502 # define RTTHREADPREEMPTSTATE_INITIALIZER { NIL_RTCPUID, UINT32_MAX } 503 # else 507 504 /** Reserved, MBZ. */ 508 505 uint32_t u32Reserved; 509 # define RTTHREADPREEMPTSTATE_INITIALIZER { NIL_RTCPUID, 0 }510 # endif506 # define RTTHREADPREEMPTSTATE_INITIALIZER { NIL_RTCPUID, 0 } 507 # endif 511 508 } RTTHREADPREEMPTSTATE; 512 509 /** Pointer to a preemption state. */ … … 542 539 RTDECL(bool) RTThreadIsInInterrupt(RTTHREAD hThread); 543 540 544 # endif /* IN_RING0 */545 546 547 # ifdef IN_RING3541 # endif /* IN_RING0 */ 542 543 544 # ifdef IN_RING3 548 545 549 546 /** … … 702 699 /** @} */ 703 700 704 #endif /* IN_RING3 */ 701 # endif /* IN_RING3 */ 702 # endif /* !IN_RC */ 705 703 706 704 /** @} */ -
trunk/include/iprt/types.h
r25426 r25478 1477 1477 /** Pointer to a lock validator record. 1478 1478 * The structure definition is found in iprt/lockvalidator.h. */ 1479 typedef struct RTLOCKVALIDATORREC *PRTLOCKVALIDATORREC; 1479 typedef struct RTLOCKVALIDATORREC *PRTLOCKVALIDATORREC; 1480 /** Pointer to a lock validator source poisition. 1481 * The structure definition is found in iprt/lockvalidator.h. */ 1482 typedef struct RTLOCKVALIDATORSRCPOS *PRTLOCKVALIDATORSRCPOS; 1483 /** Pointer to a const lock validator source poisition. 1484 * The structure definition is found in iprt/lockvalidator.h. */ 1485 typedef struct RTLOCKVALIDATORSRCPOS const *PCRTLOCKVALIDATORSRCPOS; 1480 1486 1481 1487 -
trunk/src/VBox/Runtime/common/misc/lockvalidator.cpp
r25467 r25478 63 63 64 64 65 /** 66 * Copy a source position record. 67 * 68 * @param pDst The destination. 69 * @param pSrc The source. 70 */ 71 DECL_FORCE_INLINE(void) rtLockValidatorCopySrcPos(PRTLOCKVALIDATORSRCPOS pDst, PCRTLOCKVALIDATORSRCPOS pSrc) 72 { 73 ASMAtomicUoWriteU32(&pDst->uLine, pSrc->uLine); 74 ASMAtomicUoWritePtr((void * volatile *)&pDst->pszFile, pSrc->pszFile); 75 ASMAtomicUoWritePtr((void * volatile *)&pDst->pszFunction, pSrc->pszFunction); 76 ASMAtomicUoWritePtr((void * volatile *)&pDst->uId, (void *)pSrc->uId); 77 } 78 79 80 /** 81 * Init a source position record. 82 * 83 * @param pSrcPos The source position record. 84 */ 85 DECL_FORCE_INLINE(void) rtLockValidatorInitSrcPos(PRTLOCKVALIDATORSRCPOS pSrcPos) 86 { 87 pSrcPos->pszFile = NULL; 88 pSrcPos->pszFunction = NULL; 89 pSrcPos->uId = 0; 90 pSrcPos->uLine = 0; 91 #if HC_ARCH_BITS == 64 92 pSrcPos->u32Padding = 0; 93 #endif 94 } 95 65 96 66 97 /** … … 113 144 { 114 145 pRec->u32Magic = RTLOCKVALIDATORREC_MAGIC; 115 pRec->uLine = 0; 116 pRec->pszFile = NULL; 117 pRec->pszFunction = NULL; 118 pRec->uId = 0; 146 rtLockValidatorInitSrcPos(&pRec->SrcPos); 119 147 pRec->hThread = NIL_RTTHREAD; 120 148 pRec->pDown = NULL; … … 179 207 180 208 181 RTDECL(int) RTLockValidatorCheckOrder(PRTLOCKVALIDATORREC pRec, RTTHREAD hThread, RTHCUINTPTR uId, RT_SRC_POS_DECL)209 RTDECL(int) RTLockValidatorCheckOrder(PRTLOCKVALIDATORREC pRec, RTTHREAD hThread, PCRTLOCKVALIDATORSRCPOS pSrcPos) 182 210 { 183 211 AssertReturn(pRec->u32Magic == RTLOCKVALIDATORREC_MAGIC, VERR_SEM_LV_INVALID_PARAMETER); … … 205 233 206 234 207 RTDECL(int) RTLockValidatorRecordRecursion(PRTLOCKVALIDATORREC pRec, RTHCUINTPTR uId, RT_SRC_POS_DECL)235 RTDECL(int) RTLockValidatorRecordRecursion(PRTLOCKVALIDATORREC pRec, PCRTLOCKVALIDATORSRCPOS pSrcPos) 208 236 { 209 237 AssertReturn(pRec->u32Magic == RTLOCKVALIDATORREC_MAGIC, VERR_SEM_LV_INVALID_PARAMETER); … … 227 255 228 256 229 RTDECL(RTTHREAD) RTLockValidatorSetOwner(PRTLOCKVALIDATORREC pRec, RTTHREAD hThread, RTHCUINTPTR uId, RT_SRC_POS_DECL)257 RTDECL(RTTHREAD) RTLockValidatorSetOwner(PRTLOCKVALIDATORREC pRec, RTTHREAD hThread, PCRTLOCKVALIDATORSRCPOS pSrcPos) 230 258 { 231 259 AssertReturn(pRec->u32Magic == RTLOCKVALIDATORREC_MAGIC, NIL_RTTHREAD); … … 248 276 * Update the record. 249 277 */ 250 ASMAtomicUoWriteU32(&pRec->uLine, iLine); 251 ASMAtomicUoWritePtr((void * volatile *)&pRec->pszFile, pszFile); 252 ASMAtomicUoWritePtr((void * volatile *)&pRec->pszFunction, pszFunction); 253 ASMAtomicUoWritePtr((void * volatile *)&pRec->uId, (void *)uId); 278 rtLockValidatorCopySrcPos(&pRec->SrcPos, pSrcPos); 254 279 ASMAtomicUoWriteU32(&pRec->cRecursion, 1); 255 256 280 ASMAtomicWriteHandle(&pRec->hThread, hThread); 257 281 … … 369 393 * @param pCur The thread we're deadlocking with. 370 394 * @param enmState The sleep state. 371 * @param RT_SRC_POS_DECL Where we are going to deadlock. 372 * @param uId Where we are going to deadlock. 395 * @param pSrcPos Where we are going to deadlock. 373 396 */ 374 397 static void rtLockValidatorComplainAboutDeadlock(PRTLOCKVALIDATORREC pRec, PRTTHREADINT pThread, RTTHREADSTATE enmState, 375 PRTTHREADINT pCur, RTHCUINTPTR uId, RT_SRC_POS_DECL)376 { 377 AssertMsg1(pCur == pThread ? "!!Deadlock detected!!" : "!!Deadlock exists!!", iLine, pszFile,pszFunction);398 PRTTHREADINT pCur, PCRTLOCKVALIDATORSRCPOS pSrcPos) 399 { 400 AssertMsg1(pCur == pThread ? "!!Deadlock detected!!" : "!!Deadlock exists!!", pSrcPos->uLine, pSrcPos->pszFile, pSrcPos->pszFunction); 378 401 379 402 /* … … 390 413 AssertMsg2(" #%u: %RTthrd/%RTnthrd %s: %s(%u) %RTptr\n", 391 414 iEntry, pCur, pCur->Core.Key, pCur->szName, 392 pCur->LockValidator. pszBlockFile, pCur->LockValidator.uBlockLine,393 pCur->LockValidator. pszBlockFunction, pCur->LockValidator.uBlockId);415 pCur->LockValidator.SrcPos.pszFile, pCur->LockValidator.SrcPos.uLine, 416 pCur->LockValidator.SrcPos.pszFunction, pCur->LockValidator.SrcPos.uId); 394 417 PRTTHREADINT pNext = NULL; 395 418 RTTHREADSTATE enmCurState = rtThreadGetState(pCur); … … 418 441 AssertMsg2(" Waiting on %s %p [%s]: Entered %s(%u) %s %p\n", 419 442 RTThreadStateName(enmCurState), pCurRec->hLock, pCurRec->pszName, 420 pCurRec-> pszFile, pCurRec->uLine, pCurRec->pszFunction, pCurRec->uId);443 pCurRec->SrcPos.pszFile, pCurRec->SrcPos.uLine, pCurRec->SrcPos.pszFunction, pCurRec->SrcPos.uId); 421 444 pNext = pCurRec->hThread; 422 445 } … … 461 484 RTDECL(int) RTLockValidatorCheckBlocking(PRTLOCKVALIDATORREC pRec, RTTHREAD hThread, 462 485 RTTHREADSTATE enmState, bool fRecursiveOk, 463 RTHCUINTPTR uId, RT_SRC_POS_DECL)486 PCRTLOCKVALIDATORSRCPOS pSrcPos) 464 487 { 465 488 /* … … 482 505 * performing deadlock detection. 483 506 */ 484 /** @todo This has to be serialized! The deadlock detection isn't 100% safe!!! */ 485 pThread->LockValidator.pRec = pRec; 486 pThread->LockValidator.pszBlockFunction = pszFunction; 487 pThread->LockValidator.pszBlockFile = pszFile; 488 pThread->LockValidator.uBlockLine = iLine; 489 pThread->LockValidator.uBlockId = uId; 490 491 RTThreadBlocking(hThread, enmState); 507 pThread->LockValidator.pRec = pRec; 508 rtLockValidatorCopySrcPos(&pThread->LockValidator.SrcPos, pSrcPos); 492 509 493 510 /* … … 604 621 * Ok, if we ever get here, it's most likely a genuine deadlock. 605 622 */ 606 rtLockValidatorComplainAboutDeadlock(pRec, pThread, enmState, pCur, uId, RT_SRC_POS_ARGS);623 rtLockValidatorComplainAboutDeadlock(pRec, pThread, enmState, pCur, pSrcPos); 607 624 608 625 rtLockValidatorSerializeDetectionLeave(); -
trunk/src/VBox/Runtime/generic/critsect-generic.cpp
r25467 r25478 244 244 ASMAtomicWriteHandle(&pCritSect->NativeThreadOwner, NativeThreadSelf); 245 245 #ifdef RTCRITSECT_STRICT 246 RTLockValidatorSetOwner(pCritSect->pValidatorRec, ThreadSelf, uId, RT_SRC_POS_ARGS); 246 RTLOCKVALIDATORSRCPOS SrcPos = RTLOCKVALIDATORSRCPOS_INIT_DEBUG_API(); 247 RTLockValidatorSetOwner(pCritSect->pValidatorRec, ThreadSelf, &SrcPos); 247 248 #endif 248 249 … … 283 284 RTNATIVETHREAD NativeThreadSelf = RTThreadNativeSelf(); 284 285 #ifdef RTCRITSECT_STRICT 285 RTTHREAD hThreadSelf = RTThreadSelfAutoAdopt(); 286 RTLockValidatorCheckOrder(pCritSect->pValidatorRec, hThreadSelf, uId, RT_SRC_POS_ARGS); 286 RTTHREAD hThreadSelf = RTThreadSelfAutoAdopt(); 287 RTLOCKVALIDATORSRCPOS SrcPos = RTLOCKVALIDATORSRCPOS_INIT_DEBUG_API(); 288 RTLockValidatorCheckOrder(pCritSect->pValidatorRec, hThreadSelf, &SrcPos); 287 289 #endif 288 290 … … 324 326 int rc9 = RTLockValidatorCheckBlocking(pCritSect->pValidatorRec, hThreadSelf, RTTHREADSTATE_CRITSECT, 325 327 !(pCritSect->fFlags & RTCRITSECT_FLAGS_NO_NESTING), 326 uId, RT_SRC_POS_ARGS);328 &SrcPos); 327 329 if (RT_FAILURE(rc9)) 328 330 { … … 330 332 return rc9; 331 333 } 332 #e lse334 #endif 333 335 RTThreadBlocking(hThreadSelf, RTTHREADSTATE_CRITSECT); 334 #endif335 336 336 337 int rc = RTSemEventWait(pCritSect->EventSem, RT_INDEFINITE_WAIT); … … 352 353 ASMAtomicWriteHandle(&pCritSect->NativeThreadOwner, NativeThreadSelf); 353 354 #ifdef RTCRITSECT_STRICT 354 RTLockValidatorSetOwner(pCritSect->pValidatorRec, hThreadSelf, uId, RT_SRC_POS_ARGS);355 RTLockValidatorSetOwner(pCritSect->pValidatorRec, hThreadSelf, &SrcPos); 355 356 #endif 356 357 -
trunk/src/VBox/Runtime/include/internal/lockvalidator.h
r25436 r25478 48 48 /** What we're blocking on. */ 49 49 PRTLOCKVALIDATORREC pRec; 50 /** Where we're blocking. */ 51 const char volatile *pszBlockFunction; 52 /** Where we're blocking. */ 53 const char volatile *pszBlockFile; 54 /** Where we're blocking. */ 55 uint32_t volatile uBlockLine; 56 /** Where we're blocking. */ 57 RTHCUINTPTR volatile uBlockId; 58 50 /** Where we are blocking. */ 51 RTLOCKVALIDATORSRCPOS SrcPos; 59 52 /** Number of registered write locks, mutexes and critsects that this thread owns. */ 60 53 int32_t volatile cWriteLocks; -
trunk/src/VBox/Runtime/include/internal/strict.h
r25467 r25478 58 58 #endif 59 59 60 #ifdef RTSEMMUTEX_STRICT61 # define RTSEMMUTEX_STRICT_POS_DECL RTHCUINTPTR uId, RT_SRC_POS_DECL62 # define RTSEMMUTEX_STRICT_POS_ARGS uId, RT_SRC_POS_ARGS63 #else64 # define RTSEMMUTEX_STRICT_POS_DECL int iDummy65 # define RTSEMMUTEX_STRICT_POS_ARGS 066 #endif67 68 60 69 61 /** @def RTSEMRW_STRICT … … 74 66 #endif 75 67 76 #ifdef RTSEMRW_STRICT77 # define RTSEMRW_STRICT_POS_DECL RTHCUINTPTR uId, RT_SRC_POS_DECL78 # define RTSEMRW_STRICT_POS_ARGS uId, RT_SRC_POS_ARGS79 #else80 # define RTSEMRW_STRICT_POS_DECL int iDummy81 # define RTSEMRW_STRICT_POS_ARGS 082 #endif83 84 68 85 69 -
trunk/src/VBox/Runtime/r3/linux/semmutex-linux.cpp
r25467 r25478 167 167 168 168 169 DECL_FORCE_INLINE(int) rtSemMutexRequest(RTSEMMUTEX MutexSem, unsigned cMillies, bool fAutoResume, RTSEMMUTEX_STRICT_POS_DECL)169 DECL_FORCE_INLINE(int) rtSemMutexRequest(RTSEMMUTEX MutexSem, unsigned cMillies, bool fAutoResume, PCRTLOCKVALIDATORSRCPOS pSrcPos) 170 170 { 171 171 /* … … 178 178 #ifdef RTSEMMUTEX_STRICT 179 179 RTTHREAD hThreadSelf = RTThreadSelfAutoAdopt(); 180 RTLockValidatorCheckOrder(&pThis->ValidatorRec, hThreadSelf, RTSEMMUTEX_STRICT_POS_ARGS);180 RTLockValidatorCheckOrder(&pThis->ValidatorRec, hThreadSelf, pSrcPos); 181 181 #endif 182 182 … … 232 232 #ifdef RTSEMMUTEX_STRICT 233 233 int rc9 = RTLockValidatorCheckBlocking(&pThis->ValidatorRec, hThreadSelf, 234 RTTHREADSTATE_MUTEX, true, uId, RT_SRC_POS_ARGS);234 RTTHREADSTATE_MUTEX, true, pSrcPos); 235 235 if (RT_FAILURE(rc9)) 236 236 return rc9; 237 #e lse237 #endif 238 238 RTThreadBlocking(hThreadSelf, RTTHREADSTATE_MUTEX); 239 #endif240 239 } 241 240 … … 300 299 ASMAtomicWriteU32(&pThis->cNesting, 1); 301 300 #ifdef RTSEMMUTEX_STRICT 302 RTLockValidatorSetOwner(&pThis->ValidatorRec, hThreadSelf, RTSEMMUTEX_STRICT_POS_ARGS);301 RTLockValidatorSetOwner(&pThis->ValidatorRec, hThreadSelf, pSrcPos); 303 302 #endif 304 303 return VINF_SUCCESS; … … 309 308 { 310 309 #ifndef RTSEMMUTEX_STRICT 311 int rc = rtSemMutexRequest(MutexSem, cMillies, true, RTSEMMUTEX_STRICT_POS_ARGS); 310 int rc = rtSemMutexRequest(MutexSem, cMillies, true, NULL); 311 #else 312 RTLOCKVALIDATORSRCPOS SrcPos = RTLOCKVALIDATORSRCPOS_INIT_NORMAL_API(); 313 int rc = rtSemMutexRequest(MutexSem, cMillies, true, &SrcPos); 314 #endif 312 315 Assert(rc != VERR_INTERRUPTED); 313 316 return rc; 314 #else315 return RTSemMutexRequestDebug(MutexSem, cMillies, (uintptr_t)ASMReturnAddress(), RT_SRC_POS);316 #endif317 317 } 318 318 … … 320 320 RTDECL(int) RTSemMutexRequestDebug(RTSEMMUTEX MutexSem, unsigned cMillies, RTHCUINTPTR uId, RT_SRC_POS_DECL) 321 321 { 322 #ifdef RTSEMMUTEX_STRICT 323 int rc = rtSemMutexRequest(MutexSem, cMillies, true, RTSEMMUTEX_STRICT_POS_ARGS);322 RTLOCKVALIDATORSRCPOS SrcPos = RTLOCKVALIDATORSRCPOS_INIT_DEBUG_API(); 323 int rc = rtSemMutexRequest(MutexSem, cMillies, true, &SrcPos); 324 324 Assert(rc != VERR_INTERRUPTED); 325 325 return rc; 326 } 327 328 329 RTDECL(int) RTSemMutexRequestNoResume(RTSEMMUTEX MutexSem, unsigned cMillies) 330 { 331 #ifndef RTSEMMUTEX_STRICT 332 return rtSemMutexRequest(MutexSem, cMillies, false, NULL); 326 333 #else 327 return RTSemMutexRequest(MutexSem, cMillies); 328 #endif 329 } 330 331 332 RTDECL(int) RTSemMutexRequestNoResume(RTSEMMUTEX MutexSem, unsigned cMillies) 333 { 334 #ifndef RTSEMMUTEX_STRICT 335 return rtSemMutexRequest(MutexSem, cMillies, false, RTSEMMUTEX_STRICT_POS_ARGS); 336 #else 337 return RTSemMutexRequestNoResumeDebug(MutexSem, cMillies, (uintptr_t)ASMReturnAddress(), RT_SRC_POS); 334 RTLOCKVALIDATORSRCPOS SrcPos = RTLOCKVALIDATORSRCPOS_INIT_NORMAL_API(); 335 return rtSemMutexRequest(MutexSem, cMillies, false, &SrcPos); 338 336 #endif 339 337 } … … 342 340 RTDECL(int) RTSemMutexRequestNoResumeDebug(RTSEMMUTEX MutexSem, unsigned cMillies, RTHCUINTPTR uId, RT_SRC_POS_DECL) 343 341 { 344 #ifdef RTSEMMUTEX_STRICT 345 return rtSemMutexRequest(MutexSem, cMillies, false, RTSEMMUTEX_STRICT_POS_ARGS); 346 #else 347 return RTSemMutexRequest(MutexSem, cMillies); 348 #endif 342 RTLOCKVALIDATORSRCPOS SrcPos = RTLOCKVALIDATORSRCPOS_INIT_DEBUG_API(); 343 return rtSemMutexRequest(MutexSem, cMillies, false, &SrcPos); 349 344 } 350 345 -
trunk/src/VBox/Runtime/r3/posix/semmutex-posix.cpp
r25467 r25478 155 155 156 156 157 DECL_FORCE_INLINE(int) rtSemMutexRequest(RTSEMMUTEX MutexSem, unsigned cMillies, RTSEMMUTEX_STRICT_POS_DECL)157 DECL_FORCE_INLINE(int) rtSemMutexRequest(RTSEMMUTEX MutexSem, unsigned cMillies, PCRTLOCKVALIDATORSRCPOS pSrcPos) 158 158 { 159 159 /* … … 166 166 #ifdef RTSEMMUTEX_STRICT 167 167 RTTHREAD hThreadSelf = RTThreadSelfAutoAdopt(); 168 RTLockValidatorCheckOrder(&pThis->ValidatorRec, hThreadSelf, RTSEMMUTEX_STRICT_POS_ARGS);168 RTLockValidatorCheckOrder(&pThis->ValidatorRec, hThreadSelf, pSrcPos); 169 169 #endif 170 170 … … 190 190 #ifdef RTSEMMUTEX_STRICT 191 191 int rc9 = RTLockValidatorCheckBlocking(&pThis->ValidatorRec, hThreadSelf, 192 RTTHREADSTATE_MUTEX, true, uId, RT_SRC_POS_ARGS);192 RTTHREADSTATE_MUTEX, true, pSrcPos); 193 193 if (RT_FAILURE(rc9)) 194 194 return rc9; 195 #e lse195 #endif 196 196 RTThreadBlocking(hThreadSelf, RTTHREADSTATE_MUTEX); 197 #endif198 197 } 199 198 … … 248 247 ASMAtomicWriteU32(&pThis->cNesting, 1); 249 248 #ifdef RTSEMMUTEX_STRICT 250 RTLockValidatorSetOwner(&pThis->ValidatorRec, hThreadSelf, RTSEMMUTEX_STRICT_POS_ARGS);249 RTLockValidatorSetOwner(&pThis->ValidatorRec, hThreadSelf, pSrcPos); 251 250 #endif 252 251 … … 258 257 { 259 258 #ifndef RTSEMMUTEX_STRICT 260 return rtSemMutexRequest(MutexSem, cMillies, RTSEMMUTEX_STRICT_POS_ARGS);259 return rtSemMutexRequest(MutexSem, cMillies, NULL); 261 260 #else 262 return RTSemMutexRequestDebug(MutexSem, cMillies, (uintptr_t)ASMReturnAddress(), RT_SRC_POS); 261 RTLOCKVALIDATORSRCPOS SrcPos = RTLOCKVALIDATORSRCPOS_INIT_NORMAL_API(); 262 return rtSemMutexRequest(MutexSem, cMillies, &SrcPos); 263 263 #endif 264 264 } … … 267 267 RTDECL(int) RTSemMutexRequestDebug(RTSEMMUTEX MutexSem, unsigned cMillies, RTHCUINTPTR uId, RT_SRC_POS_DECL) 268 268 { 269 #ifdef RTSEMMUTEX_STRICT 270 return rtSemMutexRequest(MutexSem, cMillies, RTSEMMUTEX_STRICT_POS_ARGS); 269 RTLOCKVALIDATORSRCPOS SrcPos = RTLOCKVALIDATORSRCPOS_INIT_DEBUG_API(); 270 return rtSemMutexRequest(MutexSem, cMillies, &SrcPos); 271 } 272 273 274 RTDECL(int) RTSemMutexRequestNoResume(RTSEMMUTEX MutexSem, unsigned cMillies) 275 { 276 /* (EINTR isn't returned by the wait functions we're using.) */ 277 #ifndef RTSEMMUTEX_STRICT 278 return rtSemMutexRequest(MutexSem, cMillies, NULL); 271 279 #else 272 return RTSemMutexRequest(MutexSem, cMillies); 273 #endif 274 } 275 276 277 RTDECL(int) RTSemMutexRequestNoResume(RTSEMMUTEX MutexSem, unsigned cMillies) 278 { 279 /* EINTR isn't returned by the wait functions we're using. */ 280 #ifndef RTSEMMUTEX_STRICT 281 return RTSemMutexRequest(MutexSem, cMillies); 282 #else 283 return RTSemMutexRequestDebug(MutexSem, cMillies, (uintptr_t)ASMReturnAddress(), RT_SRC_POS); 280 RTLOCKVALIDATORSRCPOS SrcPos = RTLOCKVALIDATORSRCPOS_INIT_NORMAL_API(); 281 return rtSemMutexRequest(MutexSem, cMillies, &SrcPos); 284 282 #endif 285 283 } … … 288 286 RTDECL(int) RTSemMutexRequestNoResumeDebug(RTSEMMUTEX MutexSem, unsigned cMillies, RTHCUINTPTR uId, RT_SRC_POS_DECL) 289 287 { 290 /* EINTR isn't returned by the wait functions we're using. */ 291 #ifdef RTSEMMUTEX_STRICT 292 return RTSemMutexRequestDebug(MutexSem, cMillies, RTSEMMUTEX_STRICT_POS_ARGS); 293 #else 294 return RTSemMutexRequest(MutexSem, cMillies); 295 #endif 288 RTLOCKVALIDATORSRCPOS SrcPos = RTLOCKVALIDATORSRCPOS_INIT_DEBUG_API(); 289 return rtSemMutexRequest(MutexSem, cMillies, &SrcPos); 296 290 } 297 291 -
trunk/src/VBox/Runtime/r3/posix/semrw-posix.cpp
r25467 r25478 315 315 316 316 317 DECL_FORCE_INLINE(int) rtSemRWRequestWrite(RTSEMRW RWSem, unsigned cMillies, RTSEMRW_STRICT_POS_DECL)317 DECL_FORCE_INLINE(int) rtSemRWRequestWrite(RTSEMRW RWSem, unsigned cMillies, PCRTLOCKVALIDATORSRCPOS pSrcPos) 318 318 { 319 319 /* … … 327 327 #ifdef RTSEMRW_STRICT 328 328 RTTHREAD hThreadSelf = RTThreadSelfAutoAdopt(); 329 RTLockValidatorCheckOrder(&pThis->ValidatorRec, hThreadSelf, RTSEMRW_STRICT_POS_ARGS);329 RTLockValidatorCheckOrder(&pThis->ValidatorRec, hThreadSelf, pSrcPos); 330 330 #endif 331 331 … … 339 339 { 340 340 #ifdef RTSEMRW_STRICT 341 int rc9 = RTLockValidatorRecordRecursion(&pThis->ValidatorRec, RTSEMRW_STRICT_POS_ARGS);341 int rc9 = RTLockValidatorRecordRecursion(&pThis->ValidatorRec, pSrcPos); 342 342 if (RT_FAILURE(rc9)) 343 343 return rc9; … … 357 357 { 358 358 #ifdef RTSEMRW_STRICT 359 int rc9 = RTLockValidatorCheckBlocking(&pThis->ValidatorRec, hThreadSelf, RTTHREADSTATE_RW_WRITE, true, uId, RT_SRC_POS_ARGS);359 int rc9 = RTLockValidatorCheckBlocking(&pThis->ValidatorRec, hThreadSelf, RTTHREADSTATE_RW_WRITE, true, pSrcPos); 360 360 if (RT_FAILURE(rc9)) 361 361 return rc9; 362 #e lse362 #endif 363 363 RTThreadBlocking(hThreadSelf, RTTHREADSTATE_RW_WRITE); 364 #endif365 364 } 366 365 … … 412 411 pThis->cWrites = 1; 413 412 #ifdef RTSEMRW_STRICT 414 RTLockValidatorSetOwner(&pThis->ValidatorRec, hThreadSelf, RTSEMRW_STRICT_POS_ARGS);413 RTLockValidatorSetOwner(&pThis->ValidatorRec, hThreadSelf, pSrcPos); 415 414 #endif 416 415 return VINF_SUCCESS; … … 421 420 { 422 421 #ifndef RTSEMRW_STRICT 423 return rtSemRWRequestWrite(RWSem, cMillies, RTSEMRW_STRICT_POS_ARGS);422 return rtSemRWRequestWrite(RWSem, cMillies, NULL); 424 423 #else 425 return RTSemRWRequestWriteDebug(RWSem, cMillies, (uintptr_t)ASMReturnAddress(), RT_SRC_POS); 424 RTLOCKVALIDATORSRCPOS SrcPos = RTLOCKVALIDATORSRCPOS_INIT_NORMAL_API(); 425 return rtSemRWRequestWrite(RWSem, cMillies, &SrcPos); 426 426 #endif 427 427 } … … 430 430 RTDECL(int) RTSemRWRequestWriteDebug(RTSEMRW RWSem, unsigned cMillies, RTHCUINTPTR uId, RT_SRC_POS_DECL) 431 431 { 432 #ifdef RTSEMRW_STRICT 433 return rtSemRWRequestWrite(RWSem, cMillies, RTSEMRW_STRICT_POS_ARGS); 434 #else 435 return RTSemRWRequestWrite(RWSem, cMillies); 436 #endif 432 RTLOCKVALIDATORSRCPOS SrcPos = RTLOCKVALIDATORSRCPOS_INIT_DEBUG_API(); 433 return rtSemRWRequestWrite(RWSem, cMillies, &SrcPos); 437 434 } 438 435 … … 442 439 /* EINTR isn't returned by the wait functions we're using. */ 443 440 #ifndef RTSEMRW_STRICT 444 return RTSemRWRequestWrite(RWSem, cMillies);441 return rtSemRWRequestWrite(RWSem, cMillies, NULL); 445 442 #else 446 return RTSemRWRequestWriteDebug(RWSem, cMillies, (uintptr_t)ASMReturnAddress(), RT_SRC_POS); 443 RTLOCKVALIDATORSRCPOS SrcPos = RTLOCKVALIDATORSRCPOS_INIT_NORMAL_API(); 444 return rtSemRWRequestWrite(RWSem, cMillies, &SrcPos); 447 445 #endif 448 446 } … … 452 450 { 453 451 /* EINTR isn't returned by the wait functions we're using. */ 454 #ifdef RTSEMRW_STRICT 455 return RTSemRWRequestWriteDebug(RWSem, cMillies, RTSEMRW_STRICT_POS_ARGS); 456 #else 457 return RTSemRWRequestWrite(RWSem, cMillies); 458 #endif 452 RTLOCKVALIDATORSRCPOS SrcPos = RTLOCKVALIDATORSRCPOS_INIT_DEBUG_API(); 453 return rtSemRWRequestWrite(RWSem, cMillies, &SrcPos); 459 454 } 460 455 -
trunk/src/VBox/Runtime/r3/win/semmutex-win.cpp
r25467 r25478 138 138 * 139 139 * @returns Same as RTSEmMutexRequestNoResume 140 * @param MutexSem 141 * @param cMillies 142 * @param TSEMMUTEX_STRICT_POS_DECLThe source position of the caller.140 * @param MutexSem The mutex handle. 141 * @param cMillies The number of milliseconds to wait. 142 * @param pSrcPos The source position of the caller. 143 143 */ 144 DECL_FORCE_INLINE(int) rtSemMutexRequestNoResume(RTSEMMUTEX MutexSem, unsigned cMillies, RTSEMMUTEX_STRICT_POS_DECL)144 DECL_FORCE_INLINE(int) rtSemMutexRequestNoResume(RTSEMMUTEX MutexSem, unsigned cMillies, PCRTLOCKVALIDATORSRCPOS pSrcPos) 145 145 { 146 146 /* … … 153 153 #ifdef RTSEMMUTEX_STRICT 154 154 RTTHREAD hThreadSelf = RTThreadSelfAutoAdopt(); 155 RTLockValidatorCheckOrder(&pThis->ValidatorRec, hThreadSelf, RTSEMMUTEX_STRICT_POS_ARGS);155 RTLockValidatorCheckOrder(&pThis->ValidatorRec, hThreadSelf, pSrcPos); 156 156 #else 157 157 RTTHREAD hThreadSelf = RTThreadSelf(); … … 165 165 #ifdef RTSEMMUTEX_STRICT 166 166 int rc9 = RTLockValidatorCheckBlocking(&pThis->ValidatorRec, hThreadSelf, 167 RTTHREADSTATE_MUTEX, true, uId, RT_SRC_POS_ARGS);167 RTTHREADSTATE_MUTEX, true, pSrcPos); 168 168 if (RT_FAILURE(rc9)) 169 169 return rc9; 170 #e lse170 #endif 171 171 RTThreadBlocking(hThreadSelf, RTTHREADSTATE_MUTEX); 172 #endif173 172 } 174 173 int rc = WaitForSingleObjectEx(pThis->hMtx, … … 180 179 case WAIT_OBJECT_0: 181 180 #ifdef RTSEMMUTEX_STRICT 182 RTLockValidatorSetOwner(&pThis->ValidatorRec, hThreadSelf, RTSEMMUTEX_STRICT_POS_ARGS);181 RTLockValidatorSetOwner(&pThis->ValidatorRec, hThreadSelf, pSrcPos); 183 182 #endif 184 183 return VINF_SUCCESS; … … 204 203 { 205 204 #ifndef RTSEMMUTEX_STRICT 206 return rtSemMutexRequestNoResume(MutexSem, cMillies, RTSEMMUTEX_STRICT_POS_ARGS);205 return rtSemMutexRequestNoResume(MutexSem, cMillies, NULL); 207 206 #else 208 return RTSemMutexRequestNoResumeDebug(MutexSem, cMillies, (uintptr_t)ASMReturnAddress(), RT_SRC_POS); 207 RTLOCKVALIDATORSRCPOS SrcPos = RTLOCKVALIDATORSRCPOS_INIT_NORMAL_API(); 208 return rtSemMutexRequestNoResume(MutexSem, cMillies, &SrcPos); 209 209 #endif 210 210 } … … 213 213 RTDECL(int) RTSemMutexRequestNoResumeDebug(RTSEMMUTEX MutexSem, unsigned cMillies, RTHCUINTPTR uId, RT_SRC_POS_DECL) 214 214 { 215 #ifdef RTSEMMUTEX_STRICT 216 return rtSemMutexRequestNoResume(MutexSem, cMillies, RTSEMMUTEX_STRICT_POS_ARGS); 217 #else 218 return RTSemMutexRequestNoResume(MutexSem, cMillies); 219 #endif 215 RTLOCKVALIDATORSRCPOS SrcPos = RTLOCKVALIDATORSRCPOS_INIT_DEBUG_API(); 216 return rtSemMutexRequestNoResume(MutexSem, cMillies, &SrcPos); 220 217 } 221 218 -
trunk/src/VBox/VMM/PDMCritSect.cpp
r25406 r25478 396 396 397 397 #ifdef PDMCRITSECT_STRICT 398 const char * const pszFile = pCritSect->s.Core.pValidatorRec->pszFile; 399 const char * const pszFunction = pCritSect->s.Core.pValidatorRec->pszFunction; 400 uint32_t const iLine = pCritSect->s.Core.pValidatorRec->uLine; 401 RTHCUINTPTR const uId = pCritSect->s.Core.pValidatorRec->uId; 398 RTLOCKVALIDATORSRCPOS const SrcPos = pCritSect->s.Core.pValidatorRec->SrcPos; 402 399 #endif 403 400 PDMCritSectLeave(pCritSect); … … 423 420 424 421 #ifdef PDMCRITSECT_STRICT 425 int rc = PDMCritSectEnterDebug(pCritSect, VERR_INTERNAL_ERROR, uId, pszFile, iLine, pszFunction); 422 int rc = PDMCritSectEnterDebug(pCritSect, VERR_INTERNAL_ERROR, 423 SrcPos.uId, SrcPos.pszFile, SrcPos.uLine, SrcPos.pszFunction); 426 424 #else 427 425 int rc = PDMCritSectEnter(pCritSect, VERR_INTERNAL_ERROR); -
trunk/src/VBox/VMM/VMMAll/PDMAllCritSect.cpp
r25467 r25478 52 52 #define PDMCRITSECT_SPIN_COUNT_RC 256 53 53 54 #ifdef PDMCRITSECT_STRICT55 # define PDMCRITSECT_STRICT_POS_DECL RTHCUINTPTR uId, RT_SRC_POS_DECL56 # define PDMCRITSECT_STRICT_POS_ARGS uId, RT_SRC_POS_ARGS57 # define PDMCRITSECT_STRICT_BLOCK_RET(hThread, pRec, fRecursive) \58 do { \59 int rc9 = RTLockValidatorCheckBlocking(pRec, (hThread), RTTHREADSTATE_CRITSECT, fRecursive, uId, RT_SRC_POS_ARGS); \60 if (RT_FAILURE(rc9)) \61 return rc9; \62 } while (0)63 #else64 # define PDMCRITSECT_STRICT_POS_DECL int iDummy65 # define PDMCRITSECT_STRICT_POS_ARGS 066 # define PDMCRITSECT_STRICT_BLOCK_RET(hThread, pRec, fRecursive) \67 RTThreadBlocking((hThread), RTTHREADSTATE_CRITSECT)68 #endif69 #define PDMCRITSECT_STRICT_UNBLOCK(hThread) RTThreadUnblocked((hThread), RTTHREADSTATE_CRITSECT)70 54 71 55 /* Undefine the automatic VBOX_STRICT API mappings. */ … … 104 88 * @param hNativeSelf The native handle of this thread. 105 89 */ 106 DECL_FORCE_INLINE(int) pdmCritSectEnterFirst(PPDMCRITSECT pCritSect, RTNATIVETHREAD hNativeSelf, P DMCRITSECT_STRICT_POS_DECL)90 DECL_FORCE_INLINE(int) pdmCritSectEnterFirst(PPDMCRITSECT pCritSect, RTNATIVETHREAD hNativeSelf, PCRTLOCKVALIDATORSRCPOS pSrcPos) 107 91 { 108 92 AssertMsg(pCritSect->s.Core.NativeThreadOwner == NIL_RTNATIVETHREAD, ("NativeThreadOwner=%p\n", pCritSect->s.Core.NativeThreadOwner)); … … 113 97 114 98 # ifdef PDMCRITSECT_STRICT 115 RTLockValidatorSetOwner(pCritSect->s.Core.pValidatorRec, NIL_RTTHREAD, PDMCRITSECT_STRICT_POS_ARGS);99 RTLockValidatorSetOwner(pCritSect->s.Core.pValidatorRec, NIL_RTTHREAD, pSrcPos); 116 100 # endif 117 101 … … 129 113 * @param hNativeSelf The native thread handle. 130 114 */ 131 static int pdmR3CritSectEnterContended(PPDMCRITSECT pCritSect, RTNATIVETHREAD hNativeSelf, P DMCRITSECT_STRICT_POS_DECL)115 static int pdmR3CritSectEnterContended(PPDMCRITSECT pCritSect, RTNATIVETHREAD hNativeSelf, PCRTLOCKVALIDATORSRCPOS pSrcPos) 132 116 { 133 117 /* … … 135 119 */ 136 120 if (ASMAtomicIncS32(&pCritSect->s.Core.cLockers) == 0) 137 return pdmCritSectEnterFirst(pCritSect, hNativeSelf, PDMCRITSECT_STRICT_POS_ARGS);121 return pdmCritSectEnterFirst(pCritSect, hNativeSelf, pSrcPos); 138 122 STAM_COUNTER_INC(&pCritSect->s.StatContentionR3); 139 123 … … 141 125 * The wait loop. 142 126 */ 143 PSUPDRVSESSION pSession = pCritSect->s.CTX_SUFF(pVM)->pSession;144 SUPSEMEVENT hEvent = (SUPSEMEVENT)pCritSect->s.Core.EventSem;127 PSUPDRVSESSION pSession = pCritSect->s.CTX_SUFF(pVM)->pSession; 128 SUPSEMEVENT hEvent = (SUPSEMEVENT)pCritSect->s.Core.EventSem; 145 129 # ifdef PDMCRITSECT_STRICT 146 RTTHREAD h Self= RTThreadSelfAutoAdopt();147 int rc2 = RTLockValidatorCheckOrder(pCritSect->s.Core.pValidatorRec, h Self, 0, NULL, 0, NULL);130 RTTHREAD hThreadSelf = RTThreadSelfAutoAdopt(); 131 int rc2 = RTLockValidatorCheckOrder(pCritSect->s.Core.pValidatorRec, hThreadSelf, pSrcPos); 148 132 if (RT_FAILURE(rc2)) 149 133 return rc2; 150 134 # else 151 RTTHREAD h Self= RTThreadSelf();135 RTTHREAD hThreadSelf = RTThreadSelf(); 152 136 # endif 153 137 for (;;) 154 138 { 155 PDMCRITSECT_STRICT_BLOCK_RET(hSelf, pCritSect->s.Core.pValidatorRec, !(pCritSect->s.Core.fFlags & RTCRITSECT_FLAGS_NO_NESTING)); 139 # ifdef PDMCRITSECT_STRICT 140 int rc9 = RTLockValidatorCheckBlocking(pCritSect->s.Core.pValidatorRec, hThreadSelf, RTTHREADSTATE_CRITSECT, 141 !(pCritSect->s.Core.fFlags & RTCRITSECT_FLAGS_NO_NESTING), pSrcPos); 142 if (RT_FAILURE(rc9)) 143 return rc9; 144 # endif 145 146 RTThreadBlocking(hThreadSelf, RTTHREADSTATE_CRITSECT); 156 147 int rc = SUPSemEventWaitNoResume(pSession, hEvent, RT_INDEFINITE_WAIT); 157 PDMCRITSECT_STRICT_UNBLOCK(hSelf); 148 RTThreadUnblocked(hThreadSelf, RTTHREADSTATE_CRITSECT); 149 158 150 if (RT_UNLIKELY(pCritSect->s.Core.u32Magic != RTCRITSECT_MAGIC)) 159 151 return VERR_SEM_DESTROYED; 160 152 if (rc == VINF_SUCCESS) 161 return pdmCritSectEnterFirst(pCritSect, hNativeSelf, PDMCRITSECT_STRICT_POS_ARGS);153 return pdmCritSectEnterFirst(pCritSect, hNativeSelf, pSrcPos); 162 154 AssertMsg(rc == VERR_INTERRUPTED, ("rc=%Rrc\n", rc)); 163 155 } … … 178 170 * and the section is busy. 179 171 */ 180 DECL_FORCE_INLINE(int) pdmCritSectEnter(PPDMCRITSECT pCritSect, int rcBusy, P DMCRITSECT_STRICT_POS_DECL)172 DECL_FORCE_INLINE(int) pdmCritSectEnter(PPDMCRITSECT pCritSect, int rcBusy, PCRTLOCKVALIDATORSRCPOS pSrcPos) 181 173 { 182 174 Assert(pCritSect->s.Core.cNestings < 8); /* useful to catch incorrect locking */ … … 195 187 /* Not owned ... */ 196 188 if (ASMAtomicCmpXchgS32(&pCritSect->s.Core.cLockers, 0, -1)) 197 return pdmCritSectEnterFirst(pCritSect, hNativeSelf, PDMCRITSECT_STRICT_POS_ARGS);189 return pdmCritSectEnterFirst(pCritSect, hNativeSelf, pSrcPos); 198 190 199 191 /* ... or nested. */ … … 215 207 { 216 208 if (ASMAtomicCmpXchgS32(&pCritSect->s.Core.cLockers, 0, -1)) 217 return pdmCritSectEnterFirst(pCritSect, hNativeSelf, PDMCRITSECT_STRICT_POS_ARGS);209 return pdmCritSectEnterFirst(pCritSect, hNativeSelf, pSrcPos); 218 210 ASMNopPause(); 219 211 /** @todo Should use monitor/mwait on e.g. &cLockers here, possibly with a … … 228 220 * Take the slow path. 229 221 */ 230 return pdmR3CritSectEnterContended(pCritSect, hNativeSelf, PDMCRITSECT_STRICT_POS_ARGS);222 return pdmR3CritSectEnterContended(pCritSect, hNativeSelf, pSrcPos); 231 223 #else 232 224 /* … … 254 246 { 255 247 #ifndef PDMCRITSECT_STRICT 256 return pdmCritSectEnter(pCritSect, rcBusy, PDMCRITSECT_STRICT_POS_ARGS);257 #else 258 /* No need for a second code instance. */259 return PDMCritSectEnterDebug(pCritSect, rcBusy, (uintptr_t)ASMReturnAddress(), RT_SRC_POS);248 return pdmCritSectEnter(pCritSect, rcBusy, NULL); 249 #else 250 RTLOCKVALIDATORSRCPOS SrcPos = RTLOCKVALIDATORSRCPOS_INIT_NORMAL_API(); 251 return pdmCritSectEnter(pCritSect, rcBusy, &SrcPos); 260 252 #endif 261 253 } … … 283 275 { 284 276 #ifdef PDMCRITSECT_STRICT 285 return pdmCritSectEnter(pCritSect, rcBusy, PDMCRITSECT_STRICT_POS_ARGS);286 #else 287 /* No need for a second code instance. */ 288 return PDMCritSectEnter(pCritSect, rcBusy);277 RTLOCKVALIDATORSRCPOS SrcPos = RTLOCKVALIDATORSRCPOS_INIT_DEBUG_API(); 278 return pdmCritSectEnter(pCritSect, rcBusy, &SrcPos); 279 #else 280 return pdmCritSectEnter(pCritSect, rcBusy, NULL); 289 281 #endif 290 282 } … … 301 293 * @param pCritSect The critical section. 302 294 */ 303 static int pdmCritSectTryEnter(PPDMCRITSECT pCritSect, P DMCRITSECT_STRICT_POS_DECL)295 static int pdmCritSectTryEnter(PPDMCRITSECT pCritSect, PCRTLOCKVALIDATORSRCPOS pSrcPos) 304 296 { 305 297 /* … … 316 308 /* Not owned ... */ 317 309 if (ASMAtomicCmpXchgS32(&pCritSect->s.Core.cLockers, 0, -1)) 318 return pdmCritSectEnterFirst(pCritSect, hNativeSelf, PDMCRITSECT_STRICT_POS_ARGS);310 return pdmCritSectEnterFirst(pCritSect, hNativeSelf, pSrcPos); 319 311 320 312 /* ... or nested. */ … … 355 347 { 356 348 #ifndef PDMCRITSECT_STRICT 357 return pdmCritSectTryEnter(pCritSect, PDMCRITSECT_STRICT_POS_ARGS);358 #else 359 /* No need for a second code instance. */360 return PDMCritSectTryEnterDebug(pCritSect, (uintptr_t)ASMReturnAddress(), RT_SRC_POS);349 return pdmCritSectTryEnter(pCritSect, NULL); 350 #else 351 RTLOCKVALIDATORSRCPOS SrcPos = RTLOCKVALIDATORSRCPOS_INIT_NORMAL_API(); 352 return pdmCritSectTryEnter(pCritSect, &SrcPos); 361 353 #endif 362 354 } … … 383 375 { 384 376 #ifdef PDMCRITSECT_STRICT 385 return pdmCritSectTryEnter(pCritSect, PDMCRITSECT_STRICT_POS_ARGS);386 #else 387 /* No need for a second code instance. */ 388 return PDMCritSectTryEnter(pCritSect);377 RTLOCKVALIDATORSRCPOS SrcPos = RTLOCKVALIDATORSRCPOS_INIT_DEBUG_API(); 378 return pdmCritSectTryEnter(pCritSect, &SrcPos); 379 #else 380 return pdmCritSectTryEnter(pCritSect, NULL); 389 381 #endif 390 382 }
Note:
See TracChangeset
for help on using the changeset viewer.