VirtualBox

Changeset 25707 in vbox for trunk/src/VBox/Runtime/generic


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.

Location:
trunk/src/VBox/Runtime/generic
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • 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
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