VirtualBox

Changeset 36521 in vbox for trunk/include/iprt/cpp


Ignore:
Timestamp:
Apr 4, 2011 12:24:23 PM (14 years ago)
Author:
vboxsync
Message:

iprt/cpp/lock.h: RTLock, RTLockMtx -> RTCLock, RTClockMtx. 'RTC' is now the official C++ class prefix for IPRT.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/iprt/cpp/lock.h

    r36508 r36521  
    11/** @file
    2  * IPRT - RTLock Classes for Scope-based Locking.
     2 * IPRT - Classes for Scope-based Locking.
    33 */
    44
     
    3939 */
    4040
    41 class RTLock;
     41class RTCLock;
    4242
    4343/**
     
    4848 * a global variable, for class wide purposes.
    4949 *
    50  * This is best used together with RTLock.
     50 * This is best used together with RTCLock.
    5151 */
    52 class RTLockMtx
     52class RTCLockMtx
    5353{
    54 friend class RTLock;
     54friend class RTCLock;
    5555
    5656private:
     
    5858
    5959public:
    60     RTLockMtx()
     60    RTCLockMtx()
    6161    {
    6262#ifdef RT_LOCK_STRICT_ORDER
     
    7070
    7171    /** Use to when creating locks that belongs in the same "class".  */
    72     RTLockMtx(RT_SRC_POS_DECL, uint32_t uSubClass = RTLOCKVAL_SUB_CLASS_NONE)
     72    RTCLockMtx(RT_SRC_POS_DECL, uint32_t uSubClass = RTLOCKVAL_SUB_CLASS_NONE)
    7373    {
    7474#ifdef RT_LOCK_STRICT_ORDER
     
    8383    }
    8484
    85     ~RTLockMtx()
     85    ~RTCLockMtx()
    8686    {
    8787        RTCritSectDelete(&mMtx);
    8888    }
    8989
    90 // lock() and unlock() are private so that only
    91 // friend RTLock can access them
     90    /* lock() and unlock() are private so that only friend RTCLock can access
     91       them. */
    9292private:
    9393    inline void lock()
     
    106106 * The stack object for automatic locking and unlocking.
    107107 *
    108  * This is a helper class for automatic locks, to simplify
    109  * requesting a RTLockMtx and to not forget releasing it.
    110  * To request a RTLockMtx, simply create an instance of RTLock
    111  * on the stack and pass the mutex to it:
     108 * This is a helper class for automatic locks, to simplify requesting a
     109 * RTCLockMtx and to not forget releasing it.  To request a RTCLockMtx, simply
     110 * create an instance of RTCLock on the stack and pass the mutex to it:
    112111 *
    113112 * @code
    114     extern RTLockMtx gMtx;     // wherever this is
     113    extern RTCLockMtx gMtx;     // wherever this is
    115114    ...
    116115    if (...)
    117116    {
    118         RTLock lock(gMtx);
     117        RTCLock lock(gMtx);
    119118        ... // do stuff
    120119        // when lock goes out of scope, destructor releases the mutex
     
    122121   @endcode
    123122 *
    124  * You can also explicitly release the mutex by calling RTLock::release().
     123 * You can also explicitly release the mutex by calling RTCLock::release().
    125124 * This might be helpful if the lock doesn't go out of scope early enough
    126125 * for your mutex to be released.
    127126 */
    128 class RTLock
     127class RTCLock
    129128{
    130129private:
    131     RTLockMtx  &mMtx;
     130    RTCLockMtx &m_rMtx;
    132131    bool        mfLocked;
    133132
    134133public:
    135     RTLock(RTLockMtx &aMtx)
    136         : mMtx(aMtx)
     134    RTCLock(RTCLockMtx &a_rMtx)
     135        : m_rMtx(a_rMtx)
    137136    {
    138         mMtx.lock();
     137        m_rMtx.lock();
    139138        mfLocked = true;
    140139    }
    141140
    142     ~RTLock()
     141    ~RTCLock()
    143142    {
    144143        if (mfLocked)
    145             mMtx.unlock();
     144            m_rMtx.unlock();
    146145    }
    147146
     
    150149        if (mfLocked)
    151150        {
    152             mMtx.unlock();
     151            m_rMtx.unlock();
    153152            mfLocked = false;
    154153        }
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