Changeset 37419 in vbox
- Timestamp:
- Jun 11, 2011 8:25:37 PM (14 years ago)
- svn:sync-xref-src-repo-rev:
- 72218
- Location:
- trunk
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/iprt/critsect.h
r36492 r37419 102 102 /** Bootstrap hack for use with certain memory allocator locks only! */ 103 103 #define RTCRITSECT_FLAGS_BOOTSTRAP_HACK UINT32_C(0x00000004) 104 /** If set, the critical section becomes a dummy that doesn't serialize any 105 * threads. This flag can only be set at creation time. 106 * 107 * The intended use is avoiding lots of conditional code where some component 108 * might or might not require entering a critical section before access. */ 109 #define RTCRITSECT_FLAGS_NOP UINT32_C(0x00000008) 104 110 /** @} */ 105 111 -
trunk/src/VBox/Runtime/generic/critsect-generic.cpp
r36492 r37419 52 52 const char *pszNameFmt, ...) 53 53 { 54 AssertReturn(!(fFlags & ~(RTCRITSECT_FLAGS_NO_NESTING | RTCRITSECT_FLAGS_NO_LOCK_VAL | RTCRITSECT_FLAGS_BOOTSTRAP_HACK )),54 AssertReturn(!(fFlags & ~(RTCRITSECT_FLAGS_NO_NESTING | RTCRITSECT_FLAGS_NO_LOCK_VAL | RTCRITSECT_FLAGS_BOOTSTRAP_HACK | RTCRITSECT_FLAGS_NOP)), 55 55 VERR_INVALID_PARAMETER); 56 56 … … 66 66 int rc = VINF_SUCCESS; 67 67 #ifdef RTCRITSECT_STRICT 68 if (!(fFlags & RTCRITSECT_FLAGS_BOOTSTRAP_HACK))68 if (!(fFlags & (RTCRITSECT_FLAGS_BOOTSTRAP_HACK | RTCRITSECT_FLAGS_NOP))) 69 69 { 70 70 if (!pszNameFmt) … … 111 111 AssertPtrReturn(pCritSect, RTLOCKVAL_SUB_CLASS_INVALID); 112 112 AssertReturn(pCritSect->u32Magic == RTCRITSECT_MAGIC, RTLOCKVAL_SUB_CLASS_INVALID); 113 AssertReturn(!(pCritSect->fFlags & RTCRITSECT_FLAGS_NOP), RTLOCKVAL_SUB_CLASS_INVALID); 113 114 return RTLockValidatorRecExclSetSubClass(pCritSect->pValidatorRec, uSubClass); 114 115 #else … … 122 123 Assert(pCritSect); 123 124 Assert(pCritSect->u32Magic == RTCRITSECT_MAGIC); 124 RTNATIVETHREAD NativeThreadSelf = RTThreadNativeSelf(); 125 /*AssertReturn(pCritSect->u32Magic == RTCRITSECT_MAGIC, VERR_SEM_DESTROYED);*/ 126 127 /* 128 * Return straight away if NOP. 129 */ 130 if (pCritSect->fFlags & RTCRITSECT_FLAGS_NOP) 131 return VINF_SUCCESS; 125 132 126 133 /* 127 134 * Try take the lock. (cLockers is -1 if it's free) 128 135 */ 136 RTNATIVETHREAD NativeThreadSelf = RTThreadNativeSelf(); 129 137 if (!ASMAtomicCmpXchgS32(&pCritSect->cLockers, 0, -1)) 130 138 { … … 186 194 DECL_FORCE_INLINE(int) rtCritSectEnter(PRTCRITSECT pCritSect, PCRTLOCKVALSRCPOS pSrcPos) 187 195 { 188 Assert(pCritSect); 189 Assert(pCritSect->u32Magic == RTCRITSECT_MAGIC); 196 AssertPtr(pCritSect); 197 AssertReturn(pCritSect->u32Magic == RTCRITSECT_MAGIC, VERR_SEM_DESTROYED); 198 199 /* 200 * Return straight away if NOP. 201 */ 202 if (pCritSect->fFlags & RTCRITSECT_FLAGS_NOP) 203 return VINF_SUCCESS; 204 205 /* 206 * How is calling and is the order right? 207 */ 190 208 RTNATIVETHREAD NativeThreadSelf = RTThreadNativeSelf(); 191 192 /* If the critical section has already been destroyed, then inform the caller. */ 193 if (pCritSect->u32Magic != RTCRITSECT_MAGIC) 194 return VERR_SEM_DESTROYED; 195 196 #ifdef RTCRITSECT_STRICT 197 RTTHREAD hThreadSelf = pCritSect->pValidatorRec 198 ? RTThreadSelfAutoAdopt() 199 : RTThreadSelf(); 200 int rc9; 209 #ifdef RTCRITSECT_STRICT 210 RTTHREAD hThreadSelf = pCritSect->pValidatorRec 211 ? RTThreadSelfAutoAdopt() 212 : RTThreadSelf(); 213 int rc9; 201 214 if (pCritSect->pValidatorRec) /* (bootstap) */ 202 215 { … … 305 318 { 306 319 /* 307 * Assert ownership and so on.320 * Assert sanity and check for NOP. 308 321 */ 309 322 Assert(pCritSect); 310 323 Assert(pCritSect->u32Magic == RTCRITSECT_MAGIC); 324 if (pCritSect->fFlags & RTCRITSECT_FLAGS_NOP) 325 return VINF_SUCCESS; 326 327 /* 328 * Assert ownership and so on. 329 */ 311 330 Assert(pCritSect->cNestings > 0); 312 331 Assert(pCritSect->cLockers >= 0); -
trunk/src/VBox/VMM/VMMAll/PDMAllCritSect.cpp
r36251 r37419 195 195 * See if we're lucky. 196 196 */ 197 /* NOP ... */ 198 if (pCritSect->s.Core.fFlags & RTCRITSECT_FLAGS_NOP) 199 return VINF_SUCCESS; 200 197 201 RTNATIVETHREAD hNativeSelf = pdmCritSectGetNativeSelf(pCritSect); 198 /* Not owned ... */202 /* ... not owned ... */ 199 203 if (ASMAtomicCmpXchgS32(&pCritSect->s.Core.cLockers, 0, -1)) 200 204 return pdmCritSectEnterFirst(pCritSect, hNativeSelf, pSrcPos); … … 367 371 * See if we're lucky. 368 372 */ 373 /* NOP ... */ 374 if (pCritSect->s.Core.fFlags & RTCRITSECT_FLAGS_NOP) 375 return VINF_SUCCESS; 376 369 377 RTNATIVETHREAD hNativeSelf = pdmCritSectGetNativeSelf(pCritSect); 370 /* Not owned ... */378 /* ... not owned ... */ 371 379 if (ASMAtomicCmpXchgS32(&pCritSect->s.Core.cLockers, 0, -1)) 372 380 return pdmCritSectEnterFirst(pCritSect, hNativeSelf, pSrcPos); … … 481 489 Assert(pCritSect->s.Core.NativeThreadOwner == pdmCritSectGetNativeSelf(pCritSect)); 482 490 Assert(pCritSect->s.Core.cNestings >= 1); 491 492 /* 493 * Check for NOP sections. 494 */ 495 if (pCritSect->s.Core.fFlags & RTCRITSECT_FLAGS_NOP) 496 return; 483 497 484 498 /* -
trunk/src/VBox/VMM/VMMR3/PDMCritSect.cpp
r35346 r37419 123 123 * @param va Arguments for the format string. 124 124 */ 125 static int pdmR3CritSectInitOne(PVM pVM, PPDMCRITSECTINT pCritSect, void *pvKey, RT_SRC_POS_DECL, const char *pszNameFmt, va_list va) 125 static int pdmR3CritSectInitOne(PVM pVM, PPDMCRITSECTINT pCritSect, void *pvKey, RT_SRC_POS_DECL, 126 const char *pszNameFmt, va_list va) 126 127 { 127 128 VM_ASSERT_EMT(pVM); … … 459 460 AssertReturn(pCritSect->s.Core.u32Magic == RTCRITSECT_MAGIC, false); 460 461 Assert(pCritSect->s.Core.NativeThreadOwner == RTThreadNativeSelf()); 462 Assert(!(pCritSect->s.Core.fFlags & RTCRITSECT_FLAGS_NOP)); 461 463 462 464 /* No recursion allowed here. */ … … 516 518 VMMR3DECL(int) PDMR3CritSectScheduleExitEvent(PPDMCRITSECT pCritSect, RTSEMEVENT EventToSignal) 517 519 { 520 AssertPtr(pCritSect); 521 Assert(!(pCritSect->s.Core.fFlags & RTCRITSECT_FLAGS_NOP)); 518 522 Assert(EventToSignal != NIL_RTSEMEVENT); 519 523 if (RT_UNLIKELY(!RTCritSectIsOwner(&pCritSect->s.Core)))
Note:
See TracChangeset
for help on using the changeset viewer.