VirtualBox

Changeset 67721 in vbox


Ignore:
Timestamp:
Jun 30, 2017 10:17:01 AM (8 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
116569
Message:

glue/AutoLock: Adding isReadLockedOnCurrentThread method for debug assertions.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/VBox/com/AutoLock.h

    r63147 r67721  
    125125
    126126    /**
     127     * Returns @c true if the current thread holds a read lock on this
     128     * read/write semaphore. Intended for debugging only as it isn't always
     129     * accurate given @a fWannaHear.
     130     */
     131    virtual bool isReadLockedOnCurrentThread(bool fWannaHear = true) const = 0;
     132
     133    /**
    127134     * Returns the current write lock level of this semaphore. The lock level
    128135     * determines the number of nested #lockWrite() calls on the given
     
    164171
    165172    virtual bool isWriteLockOnCurrentThread() const;
     173    virtual bool isReadLockedOnCurrentThread(bool fWannaHear = true) const;
    166174
    167175    virtual void lockWrite(LOCKVAL_SRC_POS_DECL);
     
    202210    virtual ~WriteLockHandle();
    203211    virtual bool isWriteLockOnCurrentThread() const;
     212    virtual bool isReadLockedOnCurrentThread(bool fWannaHear = true) const;
    204213
    205214    virtual void lockWrite(LOCKVAL_SRC_POS_DECL);
     
    254263        LockHandle *h = lockHandle();
    255264        return h ? h->isWriteLockOnCurrentThread() : false;
     265    }
     266
     267    /**
     268     * Equivalent to <tt>#lockHandle()->isReadLockedOnCurrentThread()</tt>.
     269     * Returns @c false if lockHandle() returns @c NULL.
     270     * @note Use with care, simple debug assertions and similar only.
     271     */
     272    bool isReadLockedOnCurrentThread(bool fWannaHear = true)
     273    {
     274        LockHandle *h = lockHandle();
     275        return h ? h->isReadLockedOnCurrentThread(fWannaHear) : false;
    256276    }
    257277};
     
    573593    bool isWriteLockOnCurrentThread() const;
    574594    uint32_t writeLockLevel() const;
     595
     596    bool isReadLockedOnCurrentThread(bool fWannaHear = true) const;
    575597
    576598private:
  • trunk/src/VBox/Main/glue/AutoLock.cpp

    r63147 r67721  
    230230}
    231231
     232/*virtual*/ bool RWLockHandle::isReadLockedOnCurrentThread(bool fWannaHear) const
     233{
     234#ifdef GLUE_USE_CRITSECTRW
     235    return RTCritSectRwIsReadOwner(&m->CritSect, fWannaHear);
     236#else
     237    return RTSemRWIsReadOwner(m->sem, fWannaHear);
     238#endif
     239}
     240
    232241/*virtual*/ void RWLockHandle::lockRead(LOCKVAL_SRC_POS_DECL)
    233242{
     
    327336    RTCritSectEnter(&m->sem);
    328337#endif
     338}
     339
     340/*virtual*/ bool WriteLockHandle::isReadLockedOnCurrentThread(bool fWannaHear) const
     341{
     342    RT_NOREF(fWannaHear);
     343    return RTCritSectIsOwner(&m->sem);
    329344}
    330345
     
    661676}
    662677
     678/**
     679 * Returns @c true if the current thread holds a write lock on the managed
     680 * read/write semaphore. Returns @c false if the managed semaphore is @c
     681 * NULL.
     682 *
     683 * @note Intended for debugging only (esp. considering fWannaHear).
     684 */
     685bool AutoWriteLock::isReadLockedOnCurrentThread(bool fWannaHear) const
     686{
     687    return m->aHandles[0] ? m->aHandles[0]->isReadLockedOnCurrentThread(fWannaHear) : false;
     688}
     689
    663690////////////////////////////////////////////////////////////////////////////////
    664691//
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