VirtualBox

Changeset 25707 in vbox


Ignore:
Timestamp:
Jan 11, 2010 10:02:03 AM (15 years ago)
Author:
vboxsync
Message:

iprt: Added RTSemRWCreateEx and RTSemRWSetSubClass. Updated tstRTLockValidator with a test of the SemRW lock order validation.

Location:
trunk
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/iprt/critsect.h

    r25704 r25707  
    100100#define RTCRITSECT_MAGIC                UINT32_C(0x19790326)
    101101
     102/** @name RTCritSectInitEx flags / RTCRITSECT::fFlags
     103 * @{ */
    102104/** If set, nesting(/recursion) is not allowed. */
    103105#define RTCRITSECT_FLAGS_NO_NESTING     UINT32_C(0x00000001)
    104106/** Disables lock validation. */
    105107#define RTCRITSECT_FLAGS_NO_LOCK_VAL    UINT32_C(0x00000002)
     108/** @} */
    106109
    107110#ifdef IN_RING3
     
    119122 * @param   fFlags              Flags, any combination of the RTCRITSECT_FLAGS
    120123 *                              \#defines.
    121  * @param   hClass              The class (no reference consumed). If NIL, the
    122  *                              no lock order validation will be performed on
    123  *                              this lock.
     124 * @param   hClass              The class (no reference consumed).  If NIL, no
     125 *                              lock order validation will be performed on this
     126 *                              lock.
    124127 * @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.
    127130 * @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.
    129132 * @param   ...                 Format string arguments.
    130133 */
    131134RTDECL(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, ...);
    133136
    134137/**
  • trunk/include/iprt/lockvalidator.h

    r25704 r25707  
    606606
    607607/**
     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 */
     619RTDECL(uint32_t) RTLockValidatorRecSharedSetSubClass(PRTLOCKVALRECSHRD pRec, uint32_t uSubClass);
     620
     621/**
    608622 * Check the shared locking order.
    609623 *
  • trunk/include/iprt/semaphore.h

    r25645 r25707  
    532532 *
    533533 * @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 */
     537RTDECL(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 */
     557RTDECL(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/** @} */
    537565
    538566/**
     
    543571 */
    544572RTDECL(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 */
     586RTDECL(uint32_t) RTSemRWSetSubClass(RTSEMRW hRWSem, uint32_t uSubClass);
    545587
    546588/**
  • trunk/src/VBox/Runtime/common/misc/lockvalidator.cpp

    r25704 r25707  
    28072807    RTLOCKVAL_ASSERT_PTR_ALIGN(pRec);
    28082808    RTLOCKVAL_ASSERT_PTR_ALIGN(hLock);
     2809    Assert(   uSubClass >= RTLOCKVAL_SUB_CLASS_USER
     2810           || uSubClass == RTLOCKVAL_SUB_CLASS_NONE
     2811           || uSubClass == RTLOCKVAL_SUB_CLASS_ANY);
    28092812
    28102813    pRec->Core.u32Magic = RTLOCKVALRECEXCL_MAGIC;
     
    32293232    RTLOCKVAL_ASSERT_PTR_ALIGN(pRec);
    32303233    RTLOCKVAL_ASSERT_PTR_ALIGN(hLock);
     3234    Assert(   uSubClass >= RTLOCKVAL_SUB_CLASS_USER
     3235           || uSubClass == RTLOCKVAL_SUB_CLASS_NONE
     3236           || uSubClass == RTLOCKVAL_SUB_CLASS_ANY);
    32313237
    32323238    pRec->Core.u32Magic = RTLOCKVALRECSHRD_MAGIC;
     
    33013307
    33023308    rtLockValidatorSerializeDestructLeave();
     3309}
     3310
     3311
     3312RTDECL(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);
    33033321}
    33043322
  • trunk/src/VBox/Runtime/generic/semrw-generic.cpp

    r25704 r25707  
    9191
    9292
    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
     95RTDECL(int) RTSemRWCreate(PRTSEMRW phRWSem)
     96{
     97    return RTSemRWCreateEx(phRWSem, 0 /*fFlags*/, NIL_RTLOCKVALCLASS, RTLOCKVAL_SUB_CLASS_NONE, "RTSemRW");
     98}
     99RT_EXPORT_SYMBOL(RTSemRWCreate);
     100
     101
     102RTDECL(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     */
    102110    int rc;
    103 
    104     /*
    105      * Allocate memory.
    106      */
    107111    struct RTSEMRWINTERNAL *pThis = (struct RTSEMRWINTERNAL *)RTMemAlloc(sizeof(struct RTSEMRWINTERNAL));
    108112    if (pThis)
     
    135139                        pThis->u32Magic             = RTSEMRW_MAGIC;
    136140#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);
    141150                        RTLockValidatorRecMakeSiblings(&pThis->ValidatorWrite.Core, &pThis->ValidatorRead.Core);
    142151#endif
    143                         *pRWSem = pThis;
     152                        *phRWSem = pThis;
    144153                        return VINF_SUCCESS;
    145154                    }
     
    223232}
    224233RT_EXPORT_SYMBOL(RTSemRWDestroy);
     234
     235
     236RTDECL(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}
     252RT_EXPORT_SYMBOL(RTSemRWSetSubClass);
    225253
    226254
     
    395423
    396424
     425#undef RTSemRWRequestRead
    397426RTDECL(int) RTSemRWRequestRead(RTSEMRW RWSem, unsigned cMillies)
    398427{
     
    415444
    416445
     446#undef RTSemRWRequestReadNoResume
    417447RTDECL(int) RTSemRWRequestReadNoResume(RTSEMRW RWSem, unsigned cMillies)
    418448{
     
    699729
    700730
     731#undef RTSemRWRequestWrite
    701732RTDECL(int) RTSemRWRequestWrite(RTSEMRW RWSem, unsigned cMillies)
    702733{
     
    719750
    720751
     752#undef RTSemRWRequestWriteNoResume
    721753RTDECL(int) RTSemRWRequestWriteNoResume(RTSEMRW RWSem, unsigned cMillies)
    722754{
  • trunk/src/VBox/Runtime/generic/semrw-lockless-generic.cpp

    r25704 r25707  
    113113
    114114
    115 
     115#undef RTSemRWCreate
    116116RTDECL(int) RTSemRWCreate(PRTSEMRW phRWSem)
    117117{
     118    return RTSemRWCreateEx(phRWSem, 0 /*fFlags*/, NIL_RTLOCKVALCLASS, RTLOCKVAL_SUB_CLASS_NONE, "RTSemRW");
     119}
     120RT_EXPORT_SYMBOL(RTSemRWCreate);
     121
     122
     123RTDECL(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
    118128    RTSEMRWINTERNAL *pThis = (RTSEMRWINTERNAL *)RTMemAlloc(sizeof(*pThis));
    119129    if (!pThis)
     
    134144            pThis->fNeedReset           = false;
    135145#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);
    140155            RTLockValidatorRecMakeSiblings(&pThis->ValidatorWrite.Core, &pThis->ValidatorRead.Core);
    141156#endif
     
    148163    return rc;
    149164}
     165RT_EXPORT_SYMBOL(RTSemRWCreateEx);
    150166
    151167
     
    184200    return VINF_SUCCESS;
    185201}
     202RT_EXPORT_SYMBOL(RTSemRWDestroy);
     203
     204
     205RTDECL(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}
     221RT_EXPORT_SYMBOL(RTSemRWSetSubClass);
    186222
    187223
  • trunk/src/VBox/Runtime/r3/posix/semrw-posix.cpp

    r25704 r25707  
    9393
    9494
    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
     97RTDECL(int) RTSemRWCreate(PRTSEMRW phRWSem)
     98{
     99    return RTSemRWCreateEx(phRWSem, 0 /*fFlags*/, NIL_RTLOCKVALCLASS, RTLOCKVAL_SUB_CLASS_NONE, "RTSemRW");
     100}
     101
     102
     103RTDECL(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     */
    104111    int rc;
    105 
    106     /*
    107      * Allocate handle.
    108      */
    109112    struct RTSEMRWINTERNAL *pThis = (struct RTSEMRWINTERNAL *)RTMemAlloc(sizeof(struct RTSEMRWINTERNAL));
    110113    if (pThis)
     
    126129                pThis->Writer       = (pthread_t)-1;
    127130#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);
    132140                RTLockValidatorRecMakeSiblings(&pThis->ValidatorWrite.Core, &pThis->ValidatorRead.Core);
    133141#endif
    134                 *pRWSem = pThis;
     142                *phRWSem = pThis;
    135143                return VINF_SUCCESS;
    136144            }
     
    186194
    187195    return rc;
     196}
     197
     198
     199RTDECL(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
    188214}
    189215
     
    289315
    290316
     317#undef RTSemRWRequestRead
    291318RTDECL(int) RTSemRWRequestRead(RTSEMRW RWSem, unsigned cMillies)
    292319{
     
    307334
    308335
     336#undef RTSemRWRequestReadNoResume
    309337RTDECL(int) RTSemRWRequestReadNoResume(RTSEMRW RWSem, unsigned cMillies)
    310338{
     
    483511
    484512
     513#undef RTSemRWRequestWrite
    485514RTDECL(int) RTSemRWRequestWrite(RTSEMRW RWSem, unsigned cMillies)
    486515{
     
    501530
    502531
     532#undef RTSemRWRequestWriteNoResume
    503533RTDECL(int) RTSemRWRequestWriteNoResume(RTSEMRW RWSem, unsigned cMillies)
    504534{
  • trunk/src/VBox/Runtime/testcase/tstRTLockValidator.cpp

    r25704 r25707  
    978978    }
    979979
     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
    980984    /* Enter the first 4 critsects in ascending order and thereby definining
    981985       this as a valid lock order.  */
     
    10261030
    10271031    /* Initialize the critsection with all different classes */
    1028     for (unsigned i = 0; i < 4; i++)
     1032    for (unsigned i = 0; i < 6; i++)
    10291033    {
    10301034        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);
     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);
    10321036        RTTEST_CHECK_RETV(g_hTest, RTLockValidatorClassRetain(g_ahClasses[i]) == 4);
    10331037        RTTEST_CHECK_RETV(g_hTest, RTLockValidatorClassRelease(g_ahClasses[i]) == 3);
    10341038    }
    10351039
     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
    10361044    /* Enter the first 4 critsects in ascending order and thereby definining
    10371045       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);
    10421052
    10431053    /* Now, leave and re-enter the critsects in a way that should break the
    10441054       order and check that we get the appropriate response. */
    10451055    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);
     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);
    10501060
    10511061    /* 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
     1062    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
    10571067       are caught - including recursion. */
    10581068    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);
    10681085
    10691086    /* 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);
    10731090        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;
    10751093    }
    10761094}
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette