VirtualBox

Changeset 25524 in vbox for trunk/src/VBox/Runtime/r3


Ignore:
Timestamp:
Dec 20, 2009 4:56:30 PM (15 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
56197
Message:

semrw-posix.cpp,tstRTSemRW: added an insufficient workaround for the glibc pthread_rwlock_unlock issue.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/r3/posix/semrw-posix.cpp

    r25498 r25524  
    7373    /** The usual magic. (RTSEMRW_MAGIC) */
    7474    uint32_t            u32Magic;
    75     /* Alignment padding. */
    76     uint32_t            u32Padding;
     75    /** The number of readers.
     76     * (For preventing screwing up the lock on linux). */
     77    uint32_t volatile   cReaders;
    7778    /** Number of write recursions. */
    7879    uint32_t            cWrites;
     
    112113            if (!rc)
    113114            {
    114                 pThis->u32Magic = RTSEMRW_MAGIC;
    115                 pThis->u32Padding = 0;
    116                 pThis->cWrites = 0;
     115                pThis->u32Magic     = RTSEMRW_MAGIC;
     116                pThis->cReaders    = 0;
     117                pThis->cWrites      = 0;
    117118                pThis->cWriterReads = 0;
    118                 pThis->Writer = (pthread_t)-1;
     119                pThis->Writer       = (pthread_t)-1;
    119120#ifdef RTSEMRW_STRICT
    120121                RTLockValidatorRecInit(&pThis->ValidatorWrite, NIL_RTLOCKVALIDATORCLASS, RTLOCKVALIDATOR_SUB_CLASS_NONE, NULL, pThis);
     
    149150                    VERR_INVALID_HANDLE);
    150151    Assert(pThis->Writer == (pthread_t)-1);
     152    Assert(!pThis->cReaders);
    151153    Assert(!pThis->cWrites);
    152154    Assert(!pThis->cWriterReads);
     
    272274    }
    273275
     276    ASMAtomicIncU32(&pThis->cReaders);
    274277#ifdef RTSEMRW_STRICT
    275278    RTLockValidatorAddReadOwner(&pThis->ValidatorRead, hThreadSelf, pSrcPos);
     
    323326        return rc9;
    324327#endif
     328#ifdef RT_OS_LINUX /* glibc (at least 2.8) may screw up when unlocking a lock we don't own. */
     329    if (ASMAtomicReadU32(&pThis->cReaders) == 0)
     330    {
     331        AssertMsgFailed(("Not owner of %p\n", pThis));
     332        return VERR_NOT_OWNER;
     333    }
     334#endif
     335    ASMAtomicDecU32(&pThis->cReaders);
    325336    int rc = pthread_rwlock_unlock(&pThis->RWLock);
    326337    if (rc)
    327338    {
     339        ASMAtomicIncU32(&pThis->cReaders);
    328340        AssertMsgFailed(("Failed read unlock read-write sem %p, rc=%d.\n", RWSem, rc));
    329341        return RTErrConvertFromErrno(rc);
     
    426438    ATOMIC_SET_PTHREAD_T(&pThis->Writer, Self);
    427439    pThis->cWrites = 1;
     440    Assert(!pThis->cReaders);
    428441#ifdef RTSEMRW_STRICT
    429442    RTLockValidatorSetOwner(&pThis->ValidatorWrite, hThreadSelf, pSrcPos);
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