Changeset 25704 in vbox
- Timestamp:
- Jan 10, 2010 8:12:30 PM (15 years ago)
- svn:sync-xref-src-repo-rev:
- 56439
- Location:
- trunk
- Files:
-
- 19 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/iprt/critsect.h
r25685 r25704 125 125 * order inside the same class. If you don't know, 126 126 * then pass RTLOCKVAL_SUB_CLASS_NONE. 127 * @param pszName The lock name (optional). 127 * @param pszNameFmt Name format string for the lock validator, 128 * optional (NULL). Max length is 32 bytes. 129 * @param ... Format string arguments. 128 130 */ 129 131 RTDECL(int) RTCritSectInitEx(PRTCRITSECT pCritSect, uint32_t fFlags, 130 RTLOCKVALCLASS hClass, uint32_t uSubClass, const char *pszName); 132 RTLOCKVALCLASS hClass, uint32_t uSubClass, const char *pszName, ...); 133 134 /** 135 * Changes the lock validator sub-class of the critical section. 136 * 137 * It is recommended to try make sure that nobody is using this critical section 138 * while changing the value. 139 * 140 * @returns The old sub-class. RTLOCKVAL_SUB_CLASS_INVALID is returns if the 141 * lock validator isn't compiled in or either of the parameters are 142 * invalid. 143 * @param pCritSect The critical section. 144 * @param uSubClass The new sub-class value. 145 */ 146 RTDECL(uint32_t) RTCritSectSetSubClass(PRTCRITSECT pCritSect, uint32_t uSubClass); 131 147 132 148 /** -
trunk/include/iprt/lockvalidator.h
r25703 r25704 153 153 /** Pointer to the lock. */ 154 154 RTHCPTR hLock; 155 /** The lock name. */156 R3R0PTRTYPE(const char *) pszName;157 155 /** Pointer to the next sibling record. 158 156 * This is used to find the read side of a read-write lock. */ 159 157 R3R0PTRTYPE(PRTLOCKVALRECUNION) pSibling; 158 /** The lock name. 159 * @remarks The bytes beyond 32 are for better size alignment and can be 160 * taken and used for other purposes if it becomes necessary. */ 161 char szName[32 + (HC_ARCH_BITS == 32 ? 12 : 8)]; 160 162 } RTLOCKVALRECEXCL; 161 AssertCompileSize(RTLOCKVALRECEXCL, HC_ARCH_BITS == 32 ? 8 + 16 + 32 : 8 + 32 + 56);163 AssertCompileSize(RTLOCKVALRECEXCL, HC_ARCH_BITS == 32 ? 0x60 : 0x80); 162 164 /* The pointer type is defined in iprt/types.h. */ 163 165 … … 208 210 /** Pointer to the lock. */ 209 211 RTHCPTR hLock; 210 /** The lock name. */211 R3R0PTRTYPE(const char *) pszName;212 212 /** Pointer to the next sibling record. 213 213 * This is used to find the write side of a read-write lock. */ … … 234 234 /** Pointer to a table containing pointers to records of all the owners. */ 235 235 R3R0PTRTYPE(PRTLOCKVALRECSHRDOWN volatile *) papOwners; 236 #if HC_ARCH_BITS == 32 237 /** Alignment padding. */ 238 uint32_t u32Alignment; 239 #endif 236 237 /** The lock name. 238 * @remarks The bytes beyond 32 are for better size alignment and can be 239 * taken and used for other purposes if it becomes necessary. */ 240 char szName[32 + (HC_ARCH_BITS == 32 ? 8 : 8)]; 240 241 } RTLOCKVALRECSHRD; 241 AssertCompileSize(RTLOCKVALRECSHRD, HC_ARCH_BITS == 32 ? 24 + 20 + 4 : 40 + 24);242 AssertCompileSize(RTLOCKVALRECSHRD, HC_ARCH_BITS == 32 ? 0x50 : 0x60); 242 243 243 244 … … 264 265 * order inside the same class. If you don't know, 265 266 * then pass RTLOCKVAL_SUB_CLASS_NONE. 266 * @param pszName The lock name (optional).267 267 * @param hLock The lock handle. 268 268 * @param fEnabled Pass @c false to explicitly disable lock 269 269 * validation, otherwise @c true. 270 * @param pszNameFmt Name format string for the lock validator, 271 * optional (NULL). Max length is 32 bytes. 272 * @param ... Format string arguments. 270 273 */ 271 274 RTDECL(void) RTLockValidatorRecExclInit(PRTLOCKVALRECEXCL pRec, RTLOCKVALCLASS hClass, uint32_t uSubClass, 272 const char *pszName, void *hLock, bool fEnabled); 275 void *hLock, bool fEnabled, const char *pszNameFmt, ...); 276 /** 277 * Initialize a lock validator record. 278 * 279 * Use RTLockValidatorRecExclDelete to deinitialize it. 280 * 281 * @param pRec The record. 282 * @param hClass The class (no reference consumed). If NIL, the 283 * no lock order validation will be performed on 284 * this lock. 285 * @param uSubClass The sub-class. This is used to define lock 286 * order inside the same class. If you don't know, 287 * then pass RTLOCKVAL_SUB_CLASS_NONE. 288 * @param hLock The lock handle. 289 * @param fEnabled Pass @c false to explicitly disable lock 290 * validation, otherwise @c true. 291 * @param pszNameFmt Name format string for the lock validator, 292 * optional (NULL). Max length is 32 bytes. 293 * @param va Format string arguments. 294 */ 295 RTDECL(void) RTLockValidatorRecExclInitV(PRTLOCKVALRECEXCL pRec, RTLOCKVALCLASS hClass, uint32_t uSubClass, 296 void *hLock, bool fEnabled, const char *pszNameFmt, va_list va); 273 297 /** 274 298 * Uninitialize a lock validator record previously initialized by … … 293 317 * order inside the same class. If you don't know, 294 318 * then pass RTLOCKVAL_SUB_CLASS_NONE. 295 * @param pszName The lock name (optional).296 319 * @param hLock The lock handle. 297 320 * @param fEnabled Pass @c false to explicitly disable lock 298 321 * validation, otherwise @c true. 322 * @param pszNameFmt Name format string for the lock validator, 323 * optional (NULL). Max length is 32 bytes. 324 * @param ... Format string arguments. 299 325 */ 300 326 RTDECL(int) RTLockValidatorRecExclCreate(PRTLOCKVALRECEXCL *ppRec, RTLOCKVALCLASS hClass, uint32_t uSubClass, 301 const char *pszName, void *hLock, bool fEnabled); 327 void *hLock, bool fEnabled, const char *pszNameFmt, ...); 328 329 /** 330 * Create and initialize a lock validator record. 331 * 332 * Use RTLockValidatorRecExclDestroy to deinitialize and destroy the returned 333 * record. 334 * 335 * @return VINF_SUCCESS or VERR_NO_MEMORY. 336 * @param ppRec Where to return the record pointer. 337 * @param hClass The class (no reference consumed). If NIL, the 338 * no lock order validation will be performed on 339 * this lock. 340 * @param uSubClass The sub-class. This is used to define lock 341 * order inside the same class. If you don't know, 342 * then pass RTLOCKVAL_SUB_CLASS_NONE. 343 * @param hLock The lock handle. 344 * @param fEnabled Pass @c false to explicitly disable lock 345 * validation, otherwise @c true. 346 * @param pszNameFmt Name format string for the lock validator, 347 * optional (NULL). Max length is 32 bytes. 348 * @param va Format string arguments. 349 */ 350 RTDECL(int) RTLockValidatorRecExclCreateV(PRTLOCKVALRECEXCL *ppRec, RTLOCKVALCLASS hClass, uint32_t uSubClass, 351 void *hLock, bool fEnabled, const char *pszNameFmt, va_list va); 302 352 303 353 /** … … 308 358 */ 309 359 RTDECL(void) RTLockValidatorRecExclDestroy(PRTLOCKVALRECEXCL *ppRec); 360 361 /** 362 * Sets the sub-class of the record. 363 * 364 * It is recommended to try make sure that nobody is using this class while 365 * changing the value. 366 * 367 * @returns The old sub-class. RTLOCKVAL_SUB_CLASS_INVALID is returns if the 368 * lock validator isn't compiled in or either of the parameters are 369 * invalid. 370 * @param pRec The validator record. 371 * @param uSubClass The new sub-class value. 372 */ 373 RTDECL(uint32_t) RTLockValidatorRecExclSetSubClass(PRTLOCKVALRECEXCL pRec, uint32_t uSubClass); 310 374 311 375 /** … … 497 561 * order inside the same class. If you don't know, 498 562 * then pass RTLOCKVAL_SUB_CLASS_NONE. 499 * @param pszName The lock name (optional).500 563 * @param hLock The lock handle. 501 564 * @param fSignaller Set if event semaphore signaller logic should be … … 504 567 * @param fEnabled Pass @c false to explicitly disable lock 505 568 * validation, otherwise @c true. 569 * @param pszNameFmt Name format string for the lock validator, 570 * optional (NULL). Max length is 32 bytes. 571 * @param ... Format string arguments. 506 572 */ 507 573 RTDECL(void) RTLockValidatorRecSharedInit(PRTLOCKVALRECSHRD pRec, RTLOCKVALCLASS hClass, uint32_t uSubClass, 508 const char *pszName, void *hLock, bool fSignaller, bool fEnabled); 574 void *hLock, bool fSignaller, bool fEnabled, const char *pszNameFmt, ...); 575 /** 576 * Initialize a lock validator record for a shared lock. 577 * 578 * Use RTLockValidatorRecSharedDelete to deinitialize it. 579 * 580 * @param pRec The shared lock record. 581 * @param hClass The class (no reference consumed). If NIL, the 582 * no lock order validation will be performed on 583 * this lock. 584 * @param uSubClass The sub-class. This is used to define lock 585 * order inside the same class. If you don't know, 586 * then pass RTLOCKVAL_SUB_CLASS_NONE. 587 * @param hLock The lock handle. 588 * @param fSignaller Set if event semaphore signaller logic should be 589 * applied to this record, clear if read-write 590 * semaphore logic should be used. 591 * @param fEnabled Pass @c false to explicitly disable lock 592 * validation, otherwise @c true. 593 * @param pszNameFmt Name format string for the lock validator, 594 * optional (NULL). Max length is 32 bytes. 595 * @param va Format string arguments. 596 */ 597 RTDECL(void) RTLockValidatorRecSharedInitV(PRTLOCKVALRECSHRD pRec, RTLOCKVALCLASS hClass, uint32_t uSubClass, 598 void *hLock, bool fSignaller, bool fEnabled, const char *pszNameFmt, va_list va); 509 599 /** 510 600 * Uninitialize a lock validator record previously initialized by … … 790 880 * @param iLine The source position of the call, line. 791 881 * @param pszFunction The source position of the call, function. 792 */ 793 RTDECL(int) RTLockValidatorClassCreate(PRTLOCKVALCLASS phClass, bool fAutodidact, RT_SRC_POS_DECL); 882 * @param pszNameFmt Class name format string, optional (NULL). Max 883 * length is 32 bytes. 884 * @param ... Format string arguments. 885 */ 886 RTDECL(int) RTLockValidatorClassCreate(PRTLOCKVALCLASS phClass, bool fAutodidact, RT_SRC_POS_DECL, const char *pszNameFmt, ...); 794 887 795 888 /** -
trunk/include/iprt/types.h
r25692 r25704 1500 1500 * taking in ascending order. 1501 1501 * @{ */ 1502 /** Invalid value. */ 1503 #define RTLOCKVAL_SUB_CLASS_INVALID UINT32_C(0) 1502 1504 /** Not allowed to be taken with any other locks in the same class. 1503 1505 * This is the recommended value. */ 1504 #define RTLOCKVAL_SUB_CLASS_NONE UINT32_C( 0)1506 #define RTLOCKVAL_SUB_CLASS_NONE UINT32_C(1) 1505 1507 /** Any order is allowed within the class. */ 1506 #define RTLOCKVAL_SUB_CLASS_ANY UINT32_C( 1)1508 #define RTLOCKVAL_SUB_CLASS_ANY UINT32_C(2) 1507 1509 /** The first user value. */ 1508 1510 #define RTLOCKVAL_SUB_CLASS_USER UINT32_C(16) -
trunk/src/VBox/Runtime/common/misc/lockvalidator.cpp
r25703 r25704 509 509 #else 510 510 RTAssertMsg2AddWeak("%s%p %s own=%s nest=%u pos={%Rbn(%u) %Rfn %p}%s%s", pszPrefix, 511 pRec->Excl.hLock, pRec->Excl. pszName,511 pRec->Excl.hLock, pRec->Excl.szName, 512 512 rtLockValidatorNameThreadHandle(&pRec->Excl.hThread), cRecursion, 513 513 pSrcPos->pszFile, pSrcPos->uLine, pSrcPos->pszFunction, pSrcPos->uId, … … 518 518 case RTLOCKVALRECSHRD_MAGIC: 519 519 RTAssertMsg2AddWeak("%s%p %s srec=%p%s", pszPrefix, 520 pRec->Shared.hLock, pRec->Shared. pszName, pRec,520 pRec->Shared.hLock, pRec->Shared.szName, pRec, 521 521 pszSuffix); 522 522 break; … … 535 535 #else 536 536 RTAssertMsg2AddWeak("%s%p %s thr=%s nest=%u pos={%Rbn(%u) %Rfn %p}%s%s", pszPrefix, 537 pShared->hLock, pShared-> pszName,537 pShared->hLock, pShared->szName, 538 538 rtLockValidatorNameThreadHandle(&pRec->ShrdOwner.hThread), cRecursion, 539 539 pSrcPos->pszFile, pSrcPos->uLine, pSrcPos->pszFunction, pSrcPos->uId, … … 1024 1024 1025 1025 1026 RTDECL(int) RTLockValidatorClassCreate(PRTLOCKVALCLASS phClass, bool fAutodidact, RT_SRC_POS_DECL )1026 RTDECL(int) RTLockValidatorClassCreate(PRTLOCKVALCLASS phClass, bool fAutodidact, RT_SRC_POS_DECL, const char *pszNameFmt, ...) 1027 1027 { 1028 1028 RTLOCKVALSRCPOS SrcPos = RTLOCKVALSRCPOS_INIT_POS_NO_ID(); 1029 return RTLockValidatorClassCreateEx(phClass, &SrcPos, 1030 fAutodidact, true /*fRecursionOk*/, false /*fStrictReleaseOrder*/, 1031 1 /*cMsMinDeadlock*/, 1 /*cMsMinOrder*/, 1032 NULL /*pszName*/); 1029 va_list va; 1030 va_start(va, pszNameFmt); 1031 int rc = RTLockValidatorClassCreateExV(phClass, &SrcPos, 1032 fAutodidact, true /*fRecursionOk*/, false /*fStrictReleaseOrder*/, 1033 1 /*cMsMinDeadlock*/, 1 /*cMsMinOrder*/, 1034 pszNameFmt, va); 1035 va_end(va); 1036 return rc; 1033 1037 } 1034 1038 … … 1456 1460 { 1457 1461 case RTLOCKVALRECEXCL_MAGIC: 1458 return pRec->Excl. pszName;1462 return pRec->Excl.szName; 1459 1463 case RTLOCKVALRECSHRD_MAGIC: 1460 return pRec->Shared. pszName;1464 return pRec->Shared.szName; 1461 1465 case RTLOCKVALRECSHRDOWN_MAGIC: 1462 return pRec->ShrdOwner.pSharedRec ? pRec->ShrdOwner.pSharedRec-> pszName : "orphaned";1466 return pRec->ShrdOwner.pSharedRec ? pRec->ShrdOwner.pSharedRec->szName : "orphaned"; 1463 1467 case RTLOCKVALRECNEST_MAGIC: 1464 1468 pRec = rtLockValidatorReadRecUnionPtr(&pRec->Nest.pRec); … … 1468 1472 { 1469 1473 case RTLOCKVALRECEXCL_MAGIC: 1470 return pRec->Excl. pszName;1474 return pRec->Excl.szName; 1471 1475 case RTLOCKVALRECSHRD_MAGIC: 1472 return pRec->Shared. pszName;1476 return pRec->Shared.szName; 1473 1477 case RTLOCKVALRECSHRDOWN_MAGIC: 1474 return pRec->ShrdOwner.pSharedRec ? pRec->ShrdOwner.pSharedRec-> pszName : "orphaned";1478 return pRec->ShrdOwner.pSharedRec ? pRec->ShrdOwner.pSharedRec->szName : "orphaned"; 1475 1479 default: 1476 1480 return "unknown-nested"; … … 2798 2802 2799 2803 2800 RTDECL(void) RTLockValidatorRecExclInit (PRTLOCKVALRECEXCL pRec, RTLOCKVALCLASS hClass, uint32_t uSubClass,2801 const char *pszName, void *hLock, bool fEnabled)2804 RTDECL(void) RTLockValidatorRecExclInitV(PRTLOCKVALRECEXCL pRec, RTLOCKVALCLASS hClass, uint32_t uSubClass, 2805 void *hLock, bool fEnabled, const char *pszNameFmt, va_list va) 2802 2806 { 2803 2807 RTLOCKVAL_ASSERT_PTR_ALIGN(pRec); … … 2816 2820 pRec->cRecursion = 0; 2817 2821 pRec->hLock = hLock; 2818 pRec->pszName = pszName;2819 2822 pRec->pSibling = NULL; 2823 if (pszNameFmt) 2824 RTStrPrintfV(pRec->szName, sizeof(pRec->szName), pszNameFmt, va); 2825 else 2826 { 2827 static uint32_t volatile s_cAnonymous = 0; 2828 uint32_t i = ASMAtomicIncU32(&s_cAnonymous) - 1; 2829 RTStrPrintf(pRec->szName, sizeof(pRec->szName), "anon-excl-%u", i); 2830 } 2820 2831 2821 2832 /* Lazy initialization. */ … … 2825 2836 2826 2837 2827 RTDECL(int) RTLockValidatorRecExclCreate(PRTLOCKVALRECEXCL *ppRec, RTLOCKVALCLASS hClass, 2828 uint32_t uSubClass, const char *pszName, void *pvLock, bool fEnabled) 2838 RTDECL(void) RTLockValidatorRecExclInit(PRTLOCKVALRECEXCL pRec, RTLOCKVALCLASS hClass, uint32_t uSubClass, 2839 void *hLock, bool fEnabled, const char *pszNameFmt, ...) 2840 { 2841 va_list va; 2842 va_start(va, pszNameFmt); 2843 RTLockValidatorRecExclInitV(pRec, hClass, uSubClass, hLock, fEnabled, pszNameFmt, va); 2844 va_end(va); 2845 } 2846 2847 2848 RTDECL(int) RTLockValidatorRecExclCreateV(PRTLOCKVALRECEXCL *ppRec, RTLOCKVALCLASS hClass, 2849 uint32_t uSubClass, void *pvLock, bool fEnabled, 2850 const char *pszNameFmt, va_list va) 2829 2851 { 2830 2852 PRTLOCKVALRECEXCL pRec; … … 2832 2854 if (!pRec) 2833 2855 return VERR_NO_MEMORY; 2834 2835 RTLockValidatorRecExclInit(pRec, hClass, uSubClass, pszName, pvLock, fEnabled); 2836 2856 RTLockValidatorRecExclInitV(pRec, hClass, uSubClass, pvLock, fEnabled, pszNameFmt, va); 2837 2857 return VINF_SUCCESS; 2858 } 2859 2860 2861 RTDECL(int) RTLockValidatorRecExclCreate(PRTLOCKVALRECEXCL *ppRec, RTLOCKVALCLASS hClass, 2862 uint32_t uSubClass, void *pvLock, bool fEnabled, 2863 const char *pszNameFmt, ...) 2864 { 2865 va_list va; 2866 va_start(va, pszNameFmt); 2867 int rc = RTLockValidatorRecExclCreateV(ppRec, hClass, uSubClass, pvLock, fEnabled, pszNameFmt, va); 2868 va_end(va); 2869 return rc; 2838 2870 } 2839 2871 … … 2866 2898 RTMemFree(pRec); 2867 2899 } 2900 } 2901 2902 2903 RTDECL(uint32_t) RTLockValidatorRecExclSetSubClass(PRTLOCKVALRECEXCL pRec, uint32_t uSubClass) 2904 { 2905 AssertPtrReturn(pRec, RTLOCKVAL_SUB_CLASS_INVALID); 2906 AssertReturn(pRec->Core.u32Magic == RTLOCKVALRECEXCL_MAGIC, RTLOCKVAL_SUB_CLASS_INVALID); 2907 AssertReturn( uSubClass >= RTLOCKVAL_SUB_CLASS_USER 2908 || uSubClass == RTLOCKVAL_SUB_CLASS_NONE 2909 || uSubClass == RTLOCKVAL_SUB_CLASS_ANY, 2910 RTLOCKVAL_SUB_CLASS_INVALID); 2911 return ASMAtomicXchgU32(&pRec->uSubClass, uSubClass); 2868 2912 } 2869 2913 … … 3180 3224 3181 3225 3182 RTDECL(void) RTLockValidatorRecSharedInit (PRTLOCKVALRECSHRD pRec, RTLOCKVALCLASS hClass, uint32_t uSubClass,3183 const char *pszName, void *hLock, bool fSignaller, bool fEnabled)3226 RTDECL(void) RTLockValidatorRecSharedInitV(PRTLOCKVALRECSHRD pRec, RTLOCKVALCLASS hClass, uint32_t uSubClass, 3227 void *hLock, bool fSignaller, bool fEnabled, const char *pszNameFmt, va_list va) 3184 3228 { 3185 3229 RTLOCKVAL_ASSERT_PTR_ALIGN(pRec); … … 3190 3234 pRec->hClass = rtLockValidatorClassValidateAndRetain(hClass); 3191 3235 pRec->hLock = hLock; 3192 pRec->pszName = pszName;3193 3236 pRec->fEnabled = fEnabled && RTLockValidatorIsEnabled(); 3194 3237 pRec->fSignaller = fSignaller; … … 3202 3245 pRec->fPadding = false; 3203 3246 pRec->papOwners = NULL; 3204 #if HC_ARCH_BITS == 32 3205 pRec->u32Alignment = UINT32_MAX; 3206 #endif 3247 3248 /* the name */ 3249 if (pszNameFmt) 3250 RTStrPrintfV(pRec->szName, sizeof(pRec->szName), pszNameFmt, va); 3251 else 3252 { 3253 static uint32_t volatile s_cAnonymous = 0; 3254 uint32_t i = ASMAtomicIncU32(&s_cAnonymous) - 1; 3255 RTStrPrintf(pRec->szName, sizeof(pRec->szName), "anon-shrd-%u", i); 3256 } 3257 } 3258 3259 3260 RTDECL(void) RTLockValidatorRecSharedInit(PRTLOCKVALRECSHRD pRec, RTLOCKVALCLASS hClass, uint32_t uSubClass, 3261 void *hLock, bool fSignaller, bool fEnabled, const char *pszNameFmt, ...) 3262 { 3263 va_list va; 3264 va_start(va, pszNameFmt); 3265 RTLockValidatorRecSharedInitV(pRec, hClass, uSubClass, hLock, fSignaller, fEnabled, pszNameFmt, va); 3266 va_end(va); 3207 3267 } 3208 3268 -
trunk/src/VBox/Runtime/generic/critsect-generic.cpp
r25685 r25704 53 53 54 54 55 RTDECL(int) RTCritSectInitEx(PRTCRITSECT pCritSect, uint32_t fFlags, RTLOCKVALCLASS hClass, uint32_t uSubClass, const char *pszName) 55 RTDECL(int) RTCritSectInitEx(PRTCRITSECT pCritSect, uint32_t fFlags, RTLOCKVALCLASS hClass, uint32_t uSubClass, 56 const char *pszNameFmt, ...) 56 57 { 57 58 AssertReturn(fFlags <= (RTCRITSECT_FLAGS_NO_NESTING | RTCRITSECT_FLAGS_NO_LOCK_VAL), VERR_INVALID_PARAMETER); … … 65 66 pCritSect->cLockers = -1; 66 67 pCritSect->NativeThreadOwner = NIL_RTNATIVETHREAD; 67 int rc = RTLockValidatorRecExclCreate(&pCritSect->pValidatorRec, hClass, uSubClass, pszName, 68 pCritSect, !(fFlags & RTCRITSECT_FLAGS_NO_LOCK_VAL)); 68 #ifndef RTCRITSECT_STRICT 69 pCritSect->pValidatorRec = NULL; 70 int rc = VINF_SUCCESS; 71 #else 72 va_list va; 73 va_start(va, pszNameFmt); 74 int rc = RTLockValidatorRecExclCreateV(&pCritSect->pValidatorRec, hClass, uSubClass, pCritSect, 75 !(fFlags & RTCRITSECT_FLAGS_NO_LOCK_VAL), pszNameFmt, va); 76 va_end(va); 77 #endif 69 78 if (RT_SUCCESS(rc)) 70 79 { … … 81 90 } 82 91 RT_EXPORT_SYMBOL(RTCritSectInitEx); 92 93 94 RTDECL(uint32_t) RTCritSectSetSubClass(PRTCRITSECT pCritSect, uint32_t uSubClass) 95 { 96 #ifdef RTCRITSECT_STRICT 97 AssertPtrReturn(pCritSect, RTLOCKVAL_SUB_CLASS_INVALID); 98 AssertReturn(pCritSect->u32Magic == RTCRITSECT_MAGIC, RTLOCKVAL_SUB_CLASS_INVALID); 99 return RTLockValidatorRecExclSetSubClass(pCritSect->pValidatorRec, uSubClass); 100 #else 101 return RTLOCKVAL_SUB_CLASS_INVALID; 102 #endif 103 } 83 104 84 105 -
trunk/src/VBox/Runtime/generic/semrw-generic.cpp
r25685 r25704 135 135 pThis->u32Magic = RTSEMRW_MAGIC; 136 136 #ifdef RTSEMRW_STRICT 137 RTLockValidatorRecExclInit(&pThis->ValidatorWrite, NIL_RTLOCKVALCLASS, RTLOCKVAL_SUB_CLASS_NONE, "RTSemRW", pThis, true); 138 RTLockValidatorRecSharedInit(&pThis->ValidatorRead, NIL_RTLOCKVALCLASS, RTLOCKVAL_SUB_CLASS_NONE, "RTSemRW", pThis, false /*fSignaller*/, true); 137 RTLockValidatorRecExclInit(&pThis->ValidatorWrite, NIL_RTLOCKVALCLASS, RTLOCKVAL_SUB_CLASS_NONE, pThis, 138 true /*fEnabled*/, "RTSemRW"); 139 RTLockValidatorRecSharedInit(&pThis->ValidatorRead, NIL_RTLOCKVALCLASS, RTLOCKVAL_SUB_CLASS_NONE, pThis, 140 false /*fSignaller*/, true /*fEnabled*/, "RTSemEvent"); 139 141 RTLockValidatorRecMakeSiblings(&pThis->ValidatorWrite.Core, &pThis->ValidatorRead.Core); 140 142 #endif -
trunk/src/VBox/Runtime/generic/semrw-lockless-generic.cpp
r25685 r25704 134 134 pThis->fNeedReset = false; 135 135 #ifdef RTSEMRW_STRICT 136 RTLockValidatorRecExclInit(&pThis->ValidatorWrite, NIL_RTLOCKVALCLASS, RTLOCKVAL_SUB_CLASS_NONE, "RTSemRW", pThis, true); 137 RTLockValidatorRecSharedInit(&pThis->ValidatorRead, NIL_RTLOCKVALCLASS, RTLOCKVAL_SUB_CLASS_NONE, "RTSemRW", pThis, false /*fSignaller*/, true); 136 RTLockValidatorRecExclInit(&pThis->ValidatorWrite, NIL_RTLOCKVALCLASS, RTLOCKVAL_SUB_CLASS_NONE, pThis, 137 true /*fEnabled*/, "RTSemRW"); 138 RTLockValidatorRecSharedInit(&pThis->ValidatorRead, NIL_RTLOCKVALCLASS, RTLOCKVAL_SUB_CLASS_NONE, pThis, 139 false /*fSignaller*/, true /*fEnabled*/, "RTSemEvent"); 138 140 RTLockValidatorRecMakeSiblings(&pThis->ValidatorWrite.Core, &pThis->ValidatorRead.Core); 139 141 #endif -
trunk/src/VBox/Runtime/r3/linux/semevent-linux.cpp
r25685 r25704 131 131 RTLockValidatorRecSharedInit(&pThis->Signallers, 132 132 NIL_RTLOCKVALCLASS, RTLOCKVAL_SUB_CLASS_ANY, 133 "RTSemEvent", pThis, true /*fSignaller*/, true);133 pThis, true /*fSignaller*/, true /*fEnabled*/, "RTSemEvent"); 134 134 pThis->fEverHadSignallers = false; 135 135 #endif -
trunk/src/VBox/Runtime/r3/linux/semeventmulti-linux.cpp
r25688 r25704 132 132 RTLockValidatorRecSharedInit(&pThis->Signallers, 133 133 NIL_RTLOCKVALCLASS, RTLOCKVAL_SUB_CLASS_ANY, 134 "RTSemEventMulti", pThis, true /*fSignaller*/, true);134 pThis, true /*fSignaller*/, true /*fEnabled*/, "RTSemEvent"); 135 135 pThis->fEverHadSignallers = false; 136 136 #endif -
trunk/src/VBox/Runtime/r3/linux/semmutex-linux.cpp
r25685 r25704 120 120 pThis->cNesting = 0; 121 121 #ifdef RTSEMMUTEX_STRICT 122 RTLockValidatorRecExclInit(&pThis->ValidatorRec, NIL_RTLOCKVALCLASS, RTLOCKVAL_SUB_CLASS_NONE, "RTSemMutex", pThis, true); 122 RTLockValidatorRecExclInit(&pThis->ValidatorRec, NIL_RTLOCKVALCLASS, RTLOCKVAL_SUB_CLASS_NONE, pThis, 123 true /*fEnabled*/, "RTSemMutex"); 123 124 #endif 124 125 -
trunk/src/VBox/Runtime/r3/posix/semevent-posix.cpp
r25685 r25704 134 134 RTLockValidatorRecSharedInit(&pThis->Signallers, 135 135 NIL_RTLOCKVALCLASS, RTLOCKVAL_SUB_CLASS_ANY, 136 "RTSemEvent", pThis, true /*fSignaller*/, true);136 pThis, true /*fSignaller*/, true /*fEnabled*/, "RTSemEvent"); 137 137 pThis->fEverHadSignallers = false; 138 138 #endif -
trunk/src/VBox/Runtime/r3/posix/semeventmulti-posix.cpp
r25685 r25704 124 124 RTLockValidatorRecSharedInit(&pThis->Signallers, 125 125 NIL_RTLOCKVALCLASS, RTLOCKVAL_SUB_CLASS_ANY, 126 "RTSemEventMulti", pThis, true /*fSignaller*/, true);126 pThis, true /*fSignaller*/, true /*fEnabled*/, "RTSemEvent"); 127 127 pThis->fEverHadSignallers = false; 128 128 #endif -
trunk/src/VBox/Runtime/r3/posix/semmutex-posix.cpp
r25685 r25704 102 102 pThis->u32Magic = RTSEMMUTEX_MAGIC; 103 103 #ifdef RTSEMMUTEX_STRICT 104 RTLockValidatorRecExclInit(&pThis->ValidatorRec, NIL_RTLOCKVALCLASS, RTLOCKVAL_SUB_CLASS_NONE, "RTSemMutex", pThis, true); 104 RTLockValidatorRecExclInit(&pThis->ValidatorRec, NIL_RTLOCKVALCLASS, RTLOCKVAL_SUB_CLASS_NONE, pThis, 105 true /*fEnabled*/, "RTSemMutex"); 105 106 #endif 106 107 -
trunk/src/VBox/Runtime/r3/posix/semrw-posix.cpp
r25685 r25704 126 126 pThis->Writer = (pthread_t)-1; 127 127 #ifdef RTSEMRW_STRICT 128 RTLockValidatorRecExclInit(&pThis->ValidatorWrite, NIL_RTLOCKVALCLASS, RTLOCKVAL_SUB_CLASS_NONE, "RTSemRW", pThis, true); 129 RTLockValidatorRecSharedInit(&pThis->ValidatorRead, NIL_RTLOCKVALCLASS, RTLOCKVAL_SUB_CLASS_NONE, "RTSemRW", pThis, false /*fSignaller*/, true); 128 RTLockValidatorRecExclInit(&pThis->ValidatorWrite, NIL_RTLOCKVALCLASS, RTLOCKVAL_SUB_CLASS_NONE, pThis, 129 true /*fEnabled*/, "RTSemRW"); 130 RTLockValidatorRecSharedInit(&pThis->ValidatorRead, NIL_RTLOCKVALCLASS, RTLOCKVAL_SUB_CLASS_NONE, pThis, 131 false /*fSignaller*/, true /*fEnabled*/, "RTSemEvent"); 130 132 RTLockValidatorRecMakeSiblings(&pThis->ValidatorWrite.Core, &pThis->ValidatorRead.Core); 131 133 #endif -
trunk/src/VBox/Runtime/r3/win/semevent-win.cpp
r25685 r25704 89 89 RTLockValidatorRecSharedInit(&pThis->Signallers, 90 90 NIL_RTLOCKVALCLASS, RTLOCKVAL_SUB_CLASS_ANY, 91 "RTSemEvent", pThis, true /*fSignaller*/, true);91 pThis, true /*fSignaller*/, true /*fEnabled*/, "RTSemEvent"); 92 92 pThis->fEverHadSignallers = false; 93 93 #endif -
trunk/src/VBox/Runtime/r3/win/semeventmulti-win.cpp
r25685 r25704 92 92 RTLockValidatorRecSharedInit(&pThis->Signallers, 93 93 NIL_RTLOCKVALCLASS, RTLOCKVAL_SUB_CLASS_ANY, 94 "RTSemEvent", pThis, true /*fSignaller*/, true);94 pThis, true /*fSignaller*/, true /*fEnabled*/, "RTSemEvent"); 95 95 pThis->fEverHadSignallers = false; 96 96 #endif -
trunk/src/VBox/Runtime/r3/win/semmutex-win.cpp
r25685 r25704 93 93 pThis->cRecursions = 0; 94 94 #ifdef RTSEMMUTEX_STRICT 95 RTLockValidatorRecExclInit(&pThis->ValidatorRec, NIL_RTLOCKVALCLASS, RTLOCKVAL_SUB_CLASS_NONE, "RTSemMutex", pThis, true); 95 RTLockValidatorRecExclInit(&pThis->ValidatorRec, NIL_RTLOCKVALCLASS, RTLOCKVAL_SUB_CLASS_NONE, pThis, 96 true /*fEnabled*/, "RTSemMutex"); 96 97 #endif 97 98 *pMutexSem = pThis; -
trunk/src/VBox/Runtime/testcase/tstRTLockValidator.cpp
r25703 r25704 456 456 static void testDd1(uint32_t cThreads, uint32_t cSecs) 457 457 { 458 testIt(cThreads, cSecs, false, testDd1Thread, " critsect");458 testIt(cThreads, cSecs, false, testDd1Thread, "deadlock, critsect"); 459 459 } 460 460 … … 512 512 static void testDd2(uint32_t cThreads, uint32_t cSecs) 513 513 { 514 testIt(cThreads, cSecs, false, testDd2Thread, " read-write");514 testIt(cThreads, cSecs, false, testDd2Thread, "deadlock, read-write"); 515 515 } 516 516 … … 559 559 static void testDd3(uint32_t cThreads, uint32_t cSecs) 560 560 { 561 testIt(cThreads, cSecs, true, testDd3Thread, " read-write race");561 testIt(cThreads, cSecs, true, testDd3Thread, "deadlock, read-write race"); 562 562 } 563 563 … … 615 615 static void testDd4(uint32_t cThreads, uint32_t cSecs) 616 616 { 617 testIt(cThreads, cSecs, true, testDd4Thread, " read-write race v2");617 testIt(cThreads, cSecs, true, testDd4Thread, "deadlock, read-write race v2"); 618 618 } 619 619 … … 655 655 static void testDd5(uint32_t cThreads, uint32_t cSecs) 656 656 { 657 testIt(cThreads, cSecs, false, testDd5Thread, " mutex");657 testIt(cThreads, cSecs, false, testDd5Thread, "deadlock, mutex"); 658 658 } 659 659 … … 708 708 static void testDd6(uint32_t cThreads, uint32_t cSecs) 709 709 { 710 testIt(cThreads, cSecs, false, testDd6Thread, " event");710 testIt(cThreads, cSecs, false, testDd6Thread, "deadlock, event"); 711 711 } 712 712 … … 762 762 static void testDd7(uint32_t cThreads, uint32_t cSecs) 763 763 { 764 testIt(cThreads, cSecs, false, testDd7Thread, " event multi");764 testIt(cThreads, cSecs, false, testDd7Thread, "deadlock, event multi"); 765 765 } 766 766 … … 776 776 if (i <= 3) 777 777 { 778 RTTEST_CHECK_RC_RETV(g_hTest, RTLockValidatorClassCreate(&g_ahClasses[i], true /*fAutodidact*/, RT_SRC_POS ), VINF_SUCCESS);778 RTTEST_CHECK_RC_RETV(g_hTest, RTLockValidatorClassCreate(&g_ahClasses[i], true /*fAutodidact*/, RT_SRC_POS, "testLo1-%u", i), VINF_SUCCESS); 779 779 RTTEST_CHECK_RC_RETV(g_hTest, RTCritSectInitEx(&g_aCritSects[i], 0, g_ahClasses[i], RTLOCKVAL_SUB_CLASS_NONE, "RTCritSectLO-Auto"), VINF_SUCCESS); 780 780 RTTEST_CHECK_RETV(g_hTest, RTLockValidatorClassRetain(g_ahClasses[i]) == 3); … … 964 964 } 965 965 966 967 static void testLo2(void) 968 { 969 RTTestSub(g_hTest, "locking order, critsect"); 970 971 /* Initialize the critsection with all different classes */ 972 for (unsigned i = 0; i < 4; i++) 973 { 974 RTTEST_CHECK_RC_RETV(g_hTest, RTLockValidatorClassCreate(&g_ahClasses[i], true /*fAutodidact*/, RT_SRC_POS, "testLo2-%u", i), VINF_SUCCESS); 975 RTTEST_CHECK_RC_RETV(g_hTest, RTCritSectInitEx(&g_aCritSects[i], 0, g_ahClasses[i], RTLOCKVAL_SUB_CLASS_NONE, "RTCritSectLO"), VINF_SUCCESS); 976 RTTEST_CHECK_RETV(g_hTest, RTLockValidatorClassRetain(g_ahClasses[i]) == 3); 977 RTTEST_CHECK_RETV(g_hTest, RTLockValidatorClassRelease(g_ahClasses[i]) == 2); 978 } 979 980 /* Enter the first 4 critsects in ascending order and thereby definining 981 this as a valid lock order. */ 982 RTTEST_CHECK_RC(g_hTest, RTCritSectEnter(&g_aCritSects[0]), VINF_SUCCESS); 983 RTTEST_CHECK_RC(g_hTest, RTCritSectEnter(&g_aCritSects[1]), VINF_SUCCESS); 984 RTTEST_CHECK_RC(g_hTest, RTCritSectEnter(&g_aCritSects[2]), VINF_SUCCESS); 985 RTTEST_CHECK_RC(g_hTest, RTCritSectEnter(&g_aCritSects[3]), VINF_SUCCESS); 986 987 /* Now, leave and re-enter the critsects in a way that should break the 988 order and check that we get the appropriate response. */ 989 int rc; 990 RTTEST_CHECK_RC(g_hTest, RTCritSectLeave(&g_aCritSects[0]), VINF_SUCCESS); 991 RTTEST_CHECK_RC(g_hTest, rc = RTCritSectEnter(&g_aCritSects[0]), VERR_SEM_LV_WRONG_ORDER); 992 if (RT_SUCCESS(rc)) 993 RTTEST_CHECK_RC(g_hTest, RTCritSectLeave(&g_aCritSects[0]), VINF_SUCCESS); 994 995 /* Check that recursion isn't subject to order checks. */ 996 RTTEST_CHECK_RC(g_hTest, rc = RTCritSectEnter(&g_aCritSects[1]), VINF_SUCCESS); 997 if (RT_SUCCESS(rc)) 998 RTTEST_CHECK_RC(g_hTest, RTCritSectLeave(&g_aCritSects[1]), VINF_SUCCESS); 999 1000 /* Enable strict release order for class 2 and check that violations 1001 are caught - including recursion. */ 1002 RTTEST_CHECK_RC(g_hTest, RTLockValidatorClassEnforceStrictReleaseOrder(g_ahClasses[2], true), VINF_SUCCESS); 1003 RTTEST_CHECK_RC(g_hTest, RTCritSectEnter(&g_aCritSects[2]), VINF_SUCCESS); /* start recursion */ 1004 RTTEST_CHECK_RC(g_hTest, RTCritSectEnter(&g_aCritSects[3]), VINF_SUCCESS); 1005 RTTEST_CHECK_RC(g_hTest, RTCritSectLeave(&g_aCritSects[2]), VERR_SEM_LV_WRONG_RELEASE_ORDER); 1006 RTTEST_CHECK_RC(g_hTest, RTCritSectLeave(&g_aCritSects[3]), VINF_SUCCESS); 1007 RTTEST_CHECK_RC(g_hTest, RTCritSectLeave(&g_aCritSects[2]), VINF_SUCCESS); /* end recursion */ 1008 RTTEST_CHECK_RC(g_hTest, RTCritSectLeave(&g_aCritSects[2]), VERR_SEM_LV_WRONG_RELEASE_ORDER); 1009 RTTEST_CHECK_RC(g_hTest, RTCritSectLeave(&g_aCritSects[1]), VINF_SUCCESS); 1010 RTTEST_CHECK_RC(g_hTest, RTCritSectLeave(&g_aCritSects[3]), VINF_SUCCESS); 1011 RTTEST_CHECK_RC(g_hTest, RTCritSectLeave(&g_aCritSects[2]), VINF_SUCCESS); 1012 1013 /* clean up */ 1014 for (unsigned i = 0; i < 4; i++) 1015 { 1016 RTTEST_CHECK(g_hTest, RTLockValidatorClassRelease(g_ahClasses[i]) == 1); 1017 g_ahClasses[i] = NIL_RTLOCKVALCLASS; 1018 RTTEST_CHECK_RC_RETV(g_hTest, RTCritSectDelete(&g_aCritSects[i]), VINF_SUCCESS); 1019 } 1020 } 1021 1022 1023 static void testLo3(void) 1024 { 1025 RTTestSub(g_hTest, "locking order, read-write"); 1026 1027 /* Initialize the critsection with all different classes */ 1028 for (unsigned i = 0; i < 4; i++) 1029 { 1030 RTTEST_CHECK_RC_RETV(g_hTest, RTLockValidatorClassCreate(&g_ahClasses[i], true /*fAutodidact*/, RT_SRC_POS, "testLo3-%u", i), VINF_SUCCESS); 1031 RTTEST_CHECK_RC_RETV(g_hTest, RTCritSectInitEx(&g_aCritSects[i], 0, g_ahClasses[i], RTLOCKVAL_SUB_CLASS_NONE, "RTCritSectLO"), VINF_SUCCESS); 1032 RTTEST_CHECK_RETV(g_hTest, RTLockValidatorClassRetain(g_ahClasses[i]) == 4); 1033 RTTEST_CHECK_RETV(g_hTest, RTLockValidatorClassRelease(g_ahClasses[i]) == 3); 1034 } 1035 1036 /* Enter the first 4 critsects in ascending order and thereby definining 1037 this as a valid lock order. */ 1038 RTTEST_CHECK_RC(g_hTest, RTCritSectEnter(&g_aCritSects[0]), VINF_SUCCESS); 1039 RTTEST_CHECK_RC(g_hTest, RTCritSectEnter(&g_aCritSects[1]), VINF_SUCCESS); 1040 RTTEST_CHECK_RC(g_hTest, RTCritSectEnter(&g_aCritSects[2]), VINF_SUCCESS); 1041 RTTEST_CHECK_RC(g_hTest, RTCritSectEnter(&g_aCritSects[3]), VINF_SUCCESS); 1042 1043 /* Now, leave and re-enter the critsects in a way that should break the 1044 order and check that we get the appropriate response. */ 1045 int rc; 1046 RTTEST_CHECK_RC(g_hTest, RTCritSectLeave(&g_aCritSects[0]), VINF_SUCCESS); 1047 RTTEST_CHECK_RC(g_hTest, rc = RTCritSectEnter(&g_aCritSects[0]), VERR_SEM_LV_WRONG_ORDER); 1048 if (RT_SUCCESS(rc)) 1049 RTTEST_CHECK_RC(g_hTest, RTCritSectLeave(&g_aCritSects[0]), VINF_SUCCESS); 1050 1051 /* Check that recursion isn't subject to order checks. */ 1052 RTTEST_CHECK_RC(g_hTest, rc = RTCritSectEnter(&g_aCritSects[1]), VINF_SUCCESS); 1053 if (RT_SUCCESS(rc)) 1054 RTTEST_CHECK_RC(g_hTest, RTCritSectLeave(&g_aCritSects[1]), VINF_SUCCESS); 1055 1056 /* Enable strict release order for class 2 and check that violations 1057 are caught - including recursion. */ 1058 RTTEST_CHECK_RC(g_hTest, RTLockValidatorClassEnforceStrictReleaseOrder(g_ahClasses[2], true), VINF_SUCCESS); 1059 RTTEST_CHECK_RC(g_hTest, RTCritSectEnter(&g_aCritSects[2]), VINF_SUCCESS); /* start recursion */ 1060 RTTEST_CHECK_RC(g_hTest, RTCritSectEnter(&g_aCritSects[3]), VINF_SUCCESS); 1061 RTTEST_CHECK_RC(g_hTest, RTCritSectLeave(&g_aCritSects[2]), VERR_SEM_LV_WRONG_RELEASE_ORDER); 1062 RTTEST_CHECK_RC(g_hTest, RTCritSectLeave(&g_aCritSects[3]), VINF_SUCCESS); 1063 RTTEST_CHECK_RC(g_hTest, RTCritSectLeave(&g_aCritSects[2]), VINF_SUCCESS); /* end recursion */ 1064 RTTEST_CHECK_RC(g_hTest, RTCritSectLeave(&g_aCritSects[2]), VERR_SEM_LV_WRONG_RELEASE_ORDER); 1065 RTTEST_CHECK_RC(g_hTest, RTCritSectLeave(&g_aCritSects[1]), VINF_SUCCESS); 1066 RTTEST_CHECK_RC(g_hTest, RTCritSectLeave(&g_aCritSects[3]), VINF_SUCCESS); 1067 RTTEST_CHECK_RC(g_hTest, RTCritSectLeave(&g_aCritSects[2]), VINF_SUCCESS); 1068 1069 /* clean up */ 1070 for (unsigned i = 0; i < 4; i++) 1071 { 1072 RTTEST_CHECK(g_hTest, RTLockValidatorClassRelease(g_ahClasses[i]) == 1); 1073 g_ahClasses[i] = NIL_RTLOCKVALCLASS; 1074 RTTEST_CHECK_RC_RETV(g_hTest, RTCritSectDelete(&g_aCritSects[i]), VINF_SUCCESS); 1075 } 1076 } 1077 1078 966 1079 static bool testIsLockValidationCompiledIn(void) 967 1080 { … … 1055 1168 { 1056 1169 testLo1(); 1170 testLo2(); 1057 1171 } 1058 1172 -
trunk/src/VBox/VMM/PDMCritSect.cpp
r25685 r25704 127 127 if (RT_SUCCESS(rc)) 128 128 { 129 rc = RTLockValidatorRecExclCreate(&pCritSect->Core.pValidatorRec, NIL_RTLOCKVALCLASS, 0, p szName, pCritSect, true);129 rc = RTLockValidatorRecExclCreate(&pCritSect->Core.pValidatorRec, NIL_RTLOCKVALCLASS, 0, pCritSect, true, "%s", pszName); 130 130 if (RT_SUCCESS(rc)) 131 131 {
Note:
See TracChangeset
for help on using the changeset viewer.