VirtualBox

Changeset 25707 in vbox for trunk/src/VBox/Runtime/r3/posix


Ignore:
Timestamp:
Jan 11, 2010 10:02:03 AM (15 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
56444
Message:

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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{
Note: See TracChangeset for help on using the changeset viewer.

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