Changeset 25707 in vbox
- Timestamp:
- Jan 11, 2010 10:02:03 AM (15 years ago)
- Location:
- trunk
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/iprt/critsect.h
r25704 r25707 100 100 #define RTCRITSECT_MAGIC UINT32_C(0x19790326) 101 101 102 /** @name RTCritSectInitEx flags / RTCRITSECT::fFlags 103 * @{ */ 102 104 /** If set, nesting(/recursion) is not allowed. */ 103 105 #define RTCRITSECT_FLAGS_NO_NESTING UINT32_C(0x00000001) 104 106 /** Disables lock validation. */ 105 107 #define RTCRITSECT_FLAGS_NO_LOCK_VAL UINT32_C(0x00000002) 108 /** @} */ 106 109 107 110 #ifdef IN_RING3 … … 119 122 * @param fFlags Flags, any combination of the RTCRITSECT_FLAGS 120 123 * \#defines. 121 * @param hClass The class (no reference consumed). If NIL, the122 * no lock order validation will be performed on123 * thislock.124 * @param hClass The class (no reference consumed). If NIL, no 125 * lock order validation will be performed on this 126 * lock. 124 127 * @param uSubClass The sub-class. This is used to define lock 125 * order inside the same class. If you don't know,126 * then pass RTLOCKVAL_SUB_CLASS_NONE.128 * order within a class. RTLOCKVAL_SUB_CLASS_NONE 129 * is the recommended value here. 127 130 * @param pszNameFmt Name format string for the lock validator, 128 * optional (NULL). Max length is 32 bytes.131 * optional (NULL). Max length is 32 bytes. 129 132 * @param ... Format string arguments. 130 133 */ 131 134 RTDECL(int) RTCritSectInitEx(PRTCRITSECT pCritSect, uint32_t fFlags, 132 RTLOCKVALCLASS hClass, uint32_t uSubClass, const char *pszName , ...);135 RTLOCKVALCLASS hClass, uint32_t uSubClass, const char *pszNameFmt, ...); 133 136 134 137 /** -
trunk/include/iprt/lockvalidator.h
r25704 r25707 606 606 607 607 /** 608 * Sets the sub-class of the record. 609 * 610 * It is recommended to try make sure that nobody is using this class while 611 * changing the value. 612 * 613 * @returns The old sub-class. RTLOCKVAL_SUB_CLASS_INVALID is returns if the 614 * lock validator isn't compiled in or either of the parameters are 615 * invalid. 616 * @param pRec The validator record. 617 * @param uSubClass The new sub-class value. 618 */ 619 RTDECL(uint32_t) RTLockValidatorRecSharedSetSubClass(PRTLOCKVALRECSHRD pRec, uint32_t uSubClass); 620 621 /** 608 622 * Check the shared locking order. 609 623 * -
trunk/include/iprt/semaphore.h
r25645 r25707 532 532 * 533 533 * @returns iprt status code. 534 * @param pRWSem Where to store the handle to the created RW semaphore. 535 */ 536 RTDECL(int) RTSemRWCreate(PRTSEMRW pRWSem); 534 * @param phRWSem Where to store the handle to the newly created 535 * RW semaphore. 536 */ 537 RTDECL(int) RTSemRWCreate(PRTSEMRW phRWSem); 538 539 /** 540 * Creates a read/write semaphore. 541 * 542 * @returns iprt status code. 543 * @param phRWSem Where to store the handle to the newly created 544 * RW semaphore. 545 * @param fFlags Flags, any combination of the RTSEMRW_FLAGS_XXX 546 * \#defines. 547 * @param hClass The class (no reference consumed). If NIL, no 548 * lock order validation will be performed on this 549 * lock. 550 * @param uSubClass The sub-class. This is used to define lock 551 * order within a class. RTLOCKVAL_SUB_CLASS_NONE 552 * is the recommended value here. 553 * @param pszNameFmt Name format string for the lock validator, 554 * optional (NULL). Max length is 32 bytes. 555 * @param ... Format string arguments. 556 */ 557 RTDECL(int) RTSemRWCreateEx(PRTSEMRW phRWSem, uint32_t fFlags, 558 RTLOCKVALCLASS hClass, uint32_t uSubClass, const char *pszNameFmt, ...); 559 560 /** @name RTSemRWCreateEx flags 561 * @{ */ 562 /** Disables lock validation. */ 563 #define RTSEMRW_FLAGS_NO_LOCK_VAL UINT32_C(0x00000001) 564 /** @} */ 537 565 538 566 /** … … 543 571 */ 544 572 RTDECL(int) RTSemRWDestroy(RTSEMRW RWSem); 573 574 /** 575 * Changes the lock validator sub-class of the read/write semaphore. 576 * 577 * It is recommended to try make sure that nobody is using this sempahore while 578 * changing the value. 579 * 580 * @returns The old sub-class. RTLOCKVAL_SUB_CLASS_INVALID is returns if the 581 * lock validator isn't compiled in or either of the parameters are 582 * invalid. 583 * @param hSemRW The handle to the read/write semaphore. 584 * @param uSubClass The new sub-class value. 585 */ 586 RTDECL(uint32_t) RTSemRWSetSubClass(RTSEMRW hRWSem, uint32_t uSubClass); 545 587 546 588 /** -
trunk/src/VBox/Runtime/common/misc/lockvalidator.cpp
r25704 r25707 2807 2807 RTLOCKVAL_ASSERT_PTR_ALIGN(pRec); 2808 2808 RTLOCKVAL_ASSERT_PTR_ALIGN(hLock); 2809 Assert( uSubClass >= RTLOCKVAL_SUB_CLASS_USER 2810 || uSubClass == RTLOCKVAL_SUB_CLASS_NONE 2811 || uSubClass == RTLOCKVAL_SUB_CLASS_ANY); 2809 2812 2810 2813 pRec->Core.u32Magic = RTLOCKVALRECEXCL_MAGIC; … … 3229 3232 RTLOCKVAL_ASSERT_PTR_ALIGN(pRec); 3230 3233 RTLOCKVAL_ASSERT_PTR_ALIGN(hLock); 3234 Assert( uSubClass >= RTLOCKVAL_SUB_CLASS_USER 3235 || uSubClass == RTLOCKVAL_SUB_CLASS_NONE 3236 || uSubClass == RTLOCKVAL_SUB_CLASS_ANY); 3231 3237 3232 3238 pRec->Core.u32Magic = RTLOCKVALRECSHRD_MAGIC; … … 3301 3307 3302 3308 rtLockValidatorSerializeDestructLeave(); 3309 } 3310 3311 3312 RTDECL(uint32_t) RTLockValidatorRecSharedSetSubClass(PRTLOCKVALRECSHRD pRec, uint32_t uSubClass) 3313 { 3314 AssertPtrReturn(pRec, RTLOCKVAL_SUB_CLASS_INVALID); 3315 AssertReturn(pRec->Core.u32Magic == RTLOCKVALRECSHRD_MAGIC, RTLOCKVAL_SUB_CLASS_INVALID); 3316 AssertReturn( uSubClass >= RTLOCKVAL_SUB_CLASS_USER 3317 || uSubClass == RTLOCKVAL_SUB_CLASS_NONE 3318 || uSubClass == RTLOCKVAL_SUB_CLASS_ANY, 3319 RTLOCKVAL_SUB_CLASS_INVALID); 3320 return ASMAtomicXchgU32(&pRec->uSubClass, uSubClass); 3303 3321 } 3304 3322 -
trunk/src/VBox/Runtime/generic/semrw-generic.cpp
r25704 r25707 91 91 92 92 93 /* No debug wrapping here. */ 94 #undef RTSemRWRequestRead 95 #undef RTSemRWRequestReadNoResume 96 #undef RTSemRWRequestWrite 97 #undef RTSemRWRequestWriteNoResume 98 99 100 RTDECL(int) RTSemRWCreate(PRTSEMRW pRWSem) 101 { 93 94 #undef RTSemRWCreate 95 RTDECL(int) RTSemRWCreate(PRTSEMRW phRWSem) 96 { 97 return RTSemRWCreateEx(phRWSem, 0 /*fFlags*/, NIL_RTLOCKVALCLASS, RTLOCKVAL_SUB_CLASS_NONE, "RTSemRW"); 98 } 99 RT_EXPORT_SYMBOL(RTSemRWCreate); 100 101 102 RTDECL(int) RTSemRWCreateEx(PRTSEMRW phRWSem, uint32_t fFlags, 103 RTLOCKVALCLASS hClass, uint32_t uSubClass, const char *pszNameFmt, ...) 104 { 105 AssertReturn(!(fFlags & ~RTSEMRW_FLAGS_NO_LOCK_VAL), VERR_INVALID_PARAMETER); 106 107 /* 108 * Allocate memory. 109 */ 102 110 int rc; 103 104 /*105 * Allocate memory.106 */107 111 struct RTSEMRWINTERNAL *pThis = (struct RTSEMRWINTERNAL *)RTMemAlloc(sizeof(struct RTSEMRWINTERNAL)); 108 112 if (pThis) … … 135 139 pThis->u32Magic = RTSEMRW_MAGIC; 136 140 #ifdef RTSEMRW_STRICT 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"); 141 bool const fLVEnabled = !(fFlags & RTSEMRW_FLAGS_NO_LOCK_VAL); 142 va_list va; 143 va_start(va, pszNameFmt); 144 RTLockValidatorRecExclInit(&pThis->ValidatorWrite, hClass, uSubClass, pThis, fLVEnabled, pszNameFmt); 145 va_end(va); 146 va_start(va, pszNameFmt); 147 RTLockValidatorRecSharedInit(&pThis->ValidatorRead, hClass, uSubClass, pThis, false /*fSignaller*/, 148 fLVEnabled, pszNameFmt); 149 va_end(va); 141 150 RTLockValidatorRecMakeSiblings(&pThis->ValidatorWrite.Core, &pThis->ValidatorRead.Core); 142 151 #endif 143 *p RWSem = pThis;152 *phRWSem = pThis; 144 153 return VINF_SUCCESS; 145 154 } … … 223 232 } 224 233 RT_EXPORT_SYMBOL(RTSemRWDestroy); 234 235 236 RTDECL(uint32_t) RTSemRWSetSubClass(RTSEMRW hRWSem, uint32_t uSubClass) 237 { 238 #ifdef RTSEMRW_STRICT 239 /* 240 * Validate handle. 241 */ 242 struct RTSEMRWINTERNAL *pThis = hRWSem; 243 AssertPtrReturn(pThis, RTLOCKVAL_SUB_CLASS_INVALID); 244 AssertReturn(pThis->u32Magic == RTSEMRW_MAGIC, RTLOCKVAL_SUB_CLASS_INVALID); 245 246 RTLockValidatorRecSharedSetSubClass(&pThis->ValidatorRead, uSubClass); 247 return RTLockValidatorRecExclSetSubClass(&pThis->ValidatorWrite, uSubClass); 248 #else 249 return RTLOCKVAL_SUB_CLASS_INVALID; 250 #endif 251 } 252 RT_EXPORT_SYMBOL(RTSemRWSetSubClass); 225 253 226 254 … … 395 423 396 424 425 #undef RTSemRWRequestRead 397 426 RTDECL(int) RTSemRWRequestRead(RTSEMRW RWSem, unsigned cMillies) 398 427 { … … 415 444 416 445 446 #undef RTSemRWRequestReadNoResume 417 447 RTDECL(int) RTSemRWRequestReadNoResume(RTSEMRW RWSem, unsigned cMillies) 418 448 { … … 699 729 700 730 731 #undef RTSemRWRequestWrite 701 732 RTDECL(int) RTSemRWRequestWrite(RTSEMRW RWSem, unsigned cMillies) 702 733 { … … 719 750 720 751 752 #undef RTSemRWRequestWriteNoResume 721 753 RTDECL(int) RTSemRWRequestWriteNoResume(RTSEMRW RWSem, unsigned cMillies) 722 754 { -
trunk/src/VBox/Runtime/generic/semrw-lockless-generic.cpp
r25704 r25707 113 113 114 114 115 115 #undef RTSemRWCreate 116 116 RTDECL(int) RTSemRWCreate(PRTSEMRW phRWSem) 117 117 { 118 return RTSemRWCreateEx(phRWSem, 0 /*fFlags*/, NIL_RTLOCKVALCLASS, RTLOCKVAL_SUB_CLASS_NONE, "RTSemRW"); 119 } 120 RT_EXPORT_SYMBOL(RTSemRWCreate); 121 122 123 RTDECL(int) RTSemRWCreateEx(PRTSEMRW phRWSem, uint32_t fFlags, 124 RTLOCKVALCLASS hClass, uint32_t uSubClass, const char *pszNameFmt, ...) 125 { 126 AssertReturn(!(fFlags & ~RTSEMRW_FLAGS_NO_LOCK_VAL), VERR_INVALID_PARAMETER); 127 118 128 RTSEMRWINTERNAL *pThis = (RTSEMRWINTERNAL *)RTMemAlloc(sizeof(*pThis)); 119 129 if (!pThis) … … 134 144 pThis->fNeedReset = false; 135 145 #ifdef RTSEMRW_STRICT 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"); 146 bool const fLVEnabled = !(fFlags & RTSEMRW_FLAGS_NO_LOCK_VAL); 147 va_list va; 148 va_start(va, pszNameFmt); 149 RTLockValidatorRecExclInit(&pThis->ValidatorWrite, hClass, uSubClass, pThis, fLVEnabled, pszNameFmt); 150 va_end(va); 151 va_start(va, pszNameFmt); 152 RTLockValidatorRecSharedInit(&pThis->ValidatorRead, hClass, uSubClass, pThis, false /*fSignaller*/, 153 fLVEnabled, pszNameFmt); 154 va_end(va); 140 155 RTLockValidatorRecMakeSiblings(&pThis->ValidatorWrite.Core, &pThis->ValidatorRead.Core); 141 156 #endif … … 148 163 return rc; 149 164 } 165 RT_EXPORT_SYMBOL(RTSemRWCreateEx); 150 166 151 167 … … 184 200 return VINF_SUCCESS; 185 201 } 202 RT_EXPORT_SYMBOL(RTSemRWDestroy); 203 204 205 RTDECL(uint32_t) RTSemRWSetSubClass(RTSEMRW hRWSem, uint32_t uSubClass) 206 { 207 #ifdef RTSEMRW_STRICT 208 /* 209 * Validate handle. 210 */ 211 struct RTSEMRWINTERNAL *pThis = hRWSem; 212 AssertPtrReturn(pThis, RTLOCKVAL_SUB_CLASS_INVALID); 213 AssertReturn(pThis->u32Magic == RTSEMRW_MAGIC, RTLOCKVAL_SUB_CLASS_INVALID); 214 215 RTLockValidatorRecSharedSetSubClass(&pThis->ValidatorRead, uSubClass); 216 return RTLockValidatorRecExclSetSubClass(&pThis->ValidatorWrite, uSubClass); 217 #else 218 return RTLOCKVAL_SUB_CLASS_INVALID; 219 #endif 220 } 221 RT_EXPORT_SYMBOL(RTSemRWSetSubClass); 186 222 187 223 -
trunk/src/VBox/Runtime/r3/posix/semrw-posix.cpp
r25704 r25707 93 93 94 94 95 /* No debug wrapping here. */ 96 #undef RTSemRWRequestRead 97 #undef RTSemRWRequestReadNoResume 98 #undef RTSemRWRequestWrite 99 #undef RTSemRWRequestWriteNoResume 100 101 102 RTDECL(int) RTSemRWCreate(PRTSEMRW pRWSem) 103 { 95 96 #undef RTSemRWCreate 97 RTDECL(int) RTSemRWCreate(PRTSEMRW phRWSem) 98 { 99 return RTSemRWCreateEx(phRWSem, 0 /*fFlags*/, NIL_RTLOCKVALCLASS, RTLOCKVAL_SUB_CLASS_NONE, "RTSemRW"); 100 } 101 102 103 RTDECL(int) RTSemRWCreateEx(PRTSEMRW phRWSem, uint32_t fFlags, 104 RTLOCKVALCLASS hClass, uint32_t uSubClass, const char *pszNameFmt, ...) 105 { 106 AssertReturn(!(fFlags & ~RTSEMRW_FLAGS_NO_LOCK_VAL), VERR_INVALID_PARAMETER); 107 108 /* 109 * Allocate handle. 110 */ 104 111 int rc; 105 106 /*107 * Allocate handle.108 */109 112 struct RTSEMRWINTERNAL *pThis = (struct RTSEMRWINTERNAL *)RTMemAlloc(sizeof(struct RTSEMRWINTERNAL)); 110 113 if (pThis) … … 126 129 pThis->Writer = (pthread_t)-1; 127 130 #ifdef RTSEMRW_STRICT 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"); 131 bool const fLVEnabled = !(fFlags & RTSEMRW_FLAGS_NO_LOCK_VAL); 132 va_list va; 133 va_start(va, pszNameFmt); 134 RTLockValidatorRecExclInit(&pThis->ValidatorWrite, hClass, uSubClass, pThis, fLVEnabled, pszNameFmt); 135 va_end(va); 136 va_start(va, pszNameFmt); 137 RTLockValidatorRecSharedInit(&pThis->ValidatorRead, hClass, uSubClass, pThis, false /*fSignaller*/, 138 fLVEnabled, pszNameFmt); 139 va_end(va); 132 140 RTLockValidatorRecMakeSiblings(&pThis->ValidatorWrite.Core, &pThis->ValidatorRead.Core); 133 141 #endif 134 *p RWSem = pThis;142 *phRWSem = pThis; 135 143 return VINF_SUCCESS; 136 144 } … … 186 194 187 195 return rc; 196 } 197 198 199 RTDECL(uint32_t) RTSemRWSetSubClass(RTSEMRW hRWSem, uint32_t uSubClass) 200 { 201 #ifdef RTSEMRW_STRICT 202 /* 203 * Validate handle. 204 */ 205 struct RTSEMRWINTERNAL *pThis = hRWSem; 206 AssertPtrReturn(pThis, RTLOCKVAL_SUB_CLASS_INVALID); 207 AssertReturn(pThis->u32Magic == RTSEMRW_MAGIC, RTLOCKVAL_SUB_CLASS_INVALID); 208 209 RTLockValidatorRecSharedSetSubClass(&pThis->ValidatorRead, uSubClass); 210 return RTLockValidatorRecExclSetSubClass(&pThis->ValidatorWrite, uSubClass); 211 #else 212 return RTLOCKVAL_SUB_CLASS_INVALID; 213 #endif 188 214 } 189 215 … … 289 315 290 316 317 #undef RTSemRWRequestRead 291 318 RTDECL(int) RTSemRWRequestRead(RTSEMRW RWSem, unsigned cMillies) 292 319 { … … 307 334 308 335 336 #undef RTSemRWRequestReadNoResume 309 337 RTDECL(int) RTSemRWRequestReadNoResume(RTSEMRW RWSem, unsigned cMillies) 310 338 { … … 483 511 484 512 513 #undef RTSemRWRequestWrite 485 514 RTDECL(int) RTSemRWRequestWrite(RTSEMRW RWSem, unsigned cMillies) 486 515 { … … 501 530 502 531 532 #undef RTSemRWRequestWriteNoResume 503 533 RTDECL(int) RTSemRWRequestWriteNoResume(RTSEMRW RWSem, unsigned cMillies) 504 534 { -
trunk/src/VBox/Runtime/testcase/tstRTLockValidator.cpp
r25704 r25707 978 978 } 979 979 980 /* Check the sub-class API.*/ 981 RTTEST_CHECK(g_hTest, RTCritSectSetSubClass(&g_aCritSects[0], RTLOCKVAL_SUB_CLASS_ANY) == RTLOCKVAL_SUB_CLASS_NONE); 982 RTTEST_CHECK(g_hTest, RTCritSectSetSubClass(&g_aCritSects[0], RTLOCKVAL_SUB_CLASS_NONE) == RTLOCKVAL_SUB_CLASS_ANY); 983 980 984 /* Enter the first 4 critsects in ascending order and thereby definining 981 985 this as a valid lock order. */ … … 1026 1030 1027 1031 /* Initialize the critsection with all different classes */ 1028 for (unsigned i = 0; i < 4; i++)1032 for (unsigned i = 0; i < 6; i++) 1029 1033 { 1030 1034 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, RT CritSectInitEx(&g_aCritSects[i], 0, g_ahClasses[i], RTLOCKVAL_SUB_CLASS_NONE, "RTCritSectLO"), VINF_SUCCESS);1035 RTTEST_CHECK_RC_RETV(g_hTest, RTSemRWCreateEx(&g_ahSemRWs[i], 0, g_ahClasses[i], RTLOCKVAL_SUB_CLASS_NONE, "hSemRW-Lo3-%u", i), VINF_SUCCESS); 1032 1036 RTTEST_CHECK_RETV(g_hTest, RTLockValidatorClassRetain(g_ahClasses[i]) == 4); 1033 1037 RTTEST_CHECK_RETV(g_hTest, RTLockValidatorClassRelease(g_ahClasses[i]) == 3); 1034 1038 } 1035 1039 1040 /* Check the sub-class API.*/ 1041 RTTEST_CHECK(g_hTest, RTSemRWSetSubClass(g_ahSemRWs[0], RTLOCKVAL_SUB_CLASS_ANY) == RTLOCKVAL_SUB_CLASS_NONE); 1042 RTTEST_CHECK(g_hTest, RTSemRWSetSubClass(g_ahSemRWs[0], RTLOCKVAL_SUB_CLASS_NONE) == RTLOCKVAL_SUB_CLASS_ANY); 1043 1036 1044 /* Enter the first 4 critsects in ascending order and thereby definining 1037 1045 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); 1046 RTTEST_CHECK_RC(g_hTest, RTSemRWRequestWrite(g_ahSemRWs[0], RT_INDEFINITE_WAIT), VINF_SUCCESS); 1047 RTTEST_CHECK_RC(g_hTest, RTSemRWRequestWrite(g_ahSemRWs[1], RT_INDEFINITE_WAIT), VINF_SUCCESS); 1048 RTTEST_CHECK_RC(g_hTest, RTSemRWRequestRead( g_ahSemRWs[2], RT_INDEFINITE_WAIT), VINF_SUCCESS); 1049 RTTEST_CHECK_RC(g_hTest, RTSemRWRequestWrite(g_ahSemRWs[3], RT_INDEFINITE_WAIT), VINF_SUCCESS); 1050 RTTEST_CHECK_RC(g_hTest, RTSemRWRequestWrite(g_ahSemRWs[4], RT_INDEFINITE_WAIT), VINF_SUCCESS); 1051 RTTEST_CHECK_RC(g_hTest, RTSemRWRequestWrite(g_ahSemRWs[5], RT_INDEFINITE_WAIT), VINF_SUCCESS); 1042 1052 1043 1053 /* Now, leave and re-enter the critsects in a way that should break the 1044 1054 order and check that we get the appropriate response. */ 1045 1055 int rc; 1046 RTTEST_CHECK_RC(g_hTest, RT CritSectLeave(&g_aCritSects[0]), VINF_SUCCESS);1047 RTTEST_CHECK_RC(g_hTest, rc = RT CritSectEnter(&g_aCritSects[0]), VERR_SEM_LV_WRONG_ORDER);1048 if (RT_SUCCESS(rc)) 1049 RTTEST_CHECK_RC(g_hTest, RT CritSectLeave(&g_aCritSects[0]), VINF_SUCCESS);1056 RTTEST_CHECK_RC(g_hTest, RTSemRWReleaseWrite(g_ahSemRWs[0]), VINF_SUCCESS); 1057 RTTEST_CHECK_RC(g_hTest, rc = RTSemRWReleaseWrite(g_ahSemRWs[0]), VERR_SEM_LV_WRONG_ORDER); 1058 if (RT_SUCCESS(rc)) 1059 RTTEST_CHECK_RC(g_hTest, RTSemRWReleaseWrite(g_ahSemRWs[0]), VINF_SUCCESS); 1050 1060 1051 1061 /* Check that recursion isn't subject to order checks. */ 1052 RTTEST_CHECK_RC(g_hTest, rc = RT CritSectEnter(&g_aCritSects[1]), VINF_SUCCESS);1053 if (RT_SUCCESS(rc)) 1054 RTTEST_CHECK_RC(g_hTest, RT CritSectLeave(&g_aCritSects[1]), VINF_SUCCESS);1055 1056 /* Enable strict release order for class 2 and check that violations1062 RTTEST_CHECK_RC(g_hTest, rc = RTSemRWReleaseWrite(g_ahSemRWs[1]), VINF_SUCCESS); 1063 if (RT_SUCCESS(rc)) 1064 RTTEST_CHECK_RC(g_hTest, RTSemRWReleaseWrite(g_ahSemRWs[1]), VINF_SUCCESS); 1065 1066 /* Enable strict release order for class 2 and 3, then check that violations 1057 1067 are caught - including recursion. */ 1058 1068 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); 1069 RTTEST_CHECK_RC(g_hTest, RTLockValidatorClassEnforceStrictReleaseOrder(g_ahClasses[3], true), VINF_SUCCESS); 1070 RTTEST_CHECK_RC(g_hTest, RTSemRWReleaseRead(g_ahSemRWs[2]), VINF_SUCCESS); /* start recursion */ 1071 RTTEST_CHECK_RC(g_hTest, RTSemRWReleaseWrite(g_ahSemRWs[3]), VINF_SUCCESS); 1072 RTTEST_CHECK_RC(g_hTest, RTSemRWReleaseWrite(g_ahSemRWs[4]), VINF_SUCCESS); 1073 RTTEST_CHECK_RC(g_hTest, RTSemRWReleaseRead( g_ahSemRWs[2]), VERR_SEM_LV_WRONG_RELEASE_ORDER); 1074 RTTEST_CHECK_RC(g_hTest, RTSemRWReleaseWrite(g_ahSemRWs[3]), VERR_SEM_LV_WRONG_RELEASE_ORDER); 1075 RTTEST_CHECK_RC(g_hTest, RTSemRWReleaseWrite(g_ahSemRWs[4]), VINF_SUCCESS); 1076 RTTEST_CHECK_RC(g_hTest, RTSemRWReleaseWrite(g_ahSemRWs[3]), VINF_SUCCESS); 1077 RTTEST_CHECK_RC(g_hTest, RTSemRWReleaseRead( g_ahSemRWs[2]), VINF_SUCCESS); /* end recursion */ 1078 RTTEST_CHECK_RC(g_hTest, RTSemRWReleaseRead( g_ahSemRWs[2]), VERR_SEM_LV_WRONG_RELEASE_ORDER); 1079 RTTEST_CHECK_RC(g_hTest, RTSemRWReleaseRead( g_ahSemRWs[3]), VERR_SEM_LV_WRONG_RELEASE_ORDER); 1080 RTTEST_CHECK_RC(g_hTest, RTSemRWReleaseWrite(g_ahSemRWs[1]), VINF_SUCCESS); 1081 RTTEST_CHECK_RC(g_hTest, RTSemRWReleaseWrite(g_ahSemRWs[4]), VINF_SUCCESS); 1082 RTTEST_CHECK_RC(g_hTest, RTSemRWReleaseWrite(g_ahSemRWs[5]), VINF_SUCCESS); 1083 RTTEST_CHECK_RC(g_hTest, RTSemRWReleaseRead( g_ahSemRWs[3]), VINF_SUCCESS); 1084 RTTEST_CHECK_RC(g_hTest, RTSemRWReleaseRead( g_ahSemRWs[2]), VINF_SUCCESS); 1068 1085 1069 1086 /* clean up */ 1070 for (unsigned i = 0; i < 4; i++)1071 { 1072 RTTEST_CHECK(g_hTest, RTLockValidatorClassRelease(g_ahClasses[i]) == 1);1087 for (unsigned i = 0; i < 6; i++) 1088 { 1089 RTTEST_CHECK(g_hTest, RTLockValidatorClassRelease(g_ahClasses[i]) == 2); 1073 1090 g_ahClasses[i] = NIL_RTLOCKVALCLASS; 1074 RTTEST_CHECK_RC_RETV(g_hTest, RTCritSectDelete(&g_aCritSects[i]), VINF_SUCCESS); 1091 RTTEST_CHECK_RC_RETV(g_hTest, RTSemRWDestroy(g_ahSemRWs[i]), VINF_SUCCESS); 1092 g_ahSemRWs[i] = NIL_RTSEMRW; 1075 1093 } 1076 1094 }
Note:
See TracChangeset
for help on using the changeset viewer.