VirtualBox

Changeset 25288 in vbox


Ignore:
Timestamp:
Dec 10, 2009 12:30:09 AM (15 years ago)
Author:
vboxsync
Message:

Main: preparation for deadlock detection: make lock instance data private, no more global semaphore IPRT includes

Location:
trunk/src/VBox/Main
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/AutoLock.cpp

    r25287 r25288  
    2424#include "Logging.h"
    2525
     26#include <iprt/cdefs.h>
     27#include <iprt/critsect.h>
     28#include <iprt/thread.h>
     29#include <iprt/semaphore.h>
     30
     31#include <iprt/err.h>
     32#include <iprt/assert.h>
     33
     34#if defined(DEBUG)
     35# include <iprt/asm.h> // for ASMReturnAddress
     36#endif
     37
    2638#include <iprt/string.h>
    2739
     
    3749////////////////////////////////////////////////////////////////////////////////
    3850
     51struct RWLockHandle::Data
     52{
     53    Data()
     54    { }
     55
     56    RTSEMRW sem;
     57};
     58
    3959RWLockHandle::RWLockHandle()
    4060{
    41     int vrc = RTSemRWCreate (&mSemRW);
    42     AssertRC (vrc);
    43 }
    44 
    45 
    46 RWLockHandle::~RWLockHandle()
    47 {
    48     RTSemRWDestroy (mSemRW);
    49 }
    50 
    51 
    52 bool RWLockHandle::isWriteLockOnCurrentThread() const
    53 {
    54     return RTSemRWIsWriteOwner (mSemRW);
    55 }
    56 
    57 
    58 void RWLockHandle::lockWrite()
    59 {
    60     int vrc = RTSemRWRequestWrite (mSemRW, RT_INDEFINITE_WAIT);
    61     AssertRC (vrc);
    62 }
    63 
    64 
    65 void RWLockHandle::unlockWrite()
    66 {
    67     int vrc = RTSemRWReleaseWrite (mSemRW);
    68     AssertRC (vrc);
    69 }
    70 
    71 
    72 void RWLockHandle::lockRead()
    73 {
    74     int vrc = RTSemRWRequestRead (mSemRW, RT_INDEFINITE_WAIT);
    75     AssertRC (vrc);
    76 }
    77 
    78 
    79 void RWLockHandle::unlockRead()
    80 {
    81     int vrc = RTSemRWReleaseRead (mSemRW);
    82     AssertRC (vrc);
    83 }
    84 
    85 
    86 uint32_t RWLockHandle::writeLockLevel() const
    87 {
    88     return RTSemRWGetWriteRecursion (mSemRW);
     61    m = new Data();
     62    int vrc = RTSemRWCreate(&m->sem);
     63    AssertRC(vrc);
     64}
     65
     66/*virtual*/ RWLockHandle::~RWLockHandle()
     67{
     68    RTSemRWDestroy(m->sem);
     69    delete m;
     70}
     71
     72/*virtual*/ bool RWLockHandle::isWriteLockOnCurrentThread() const
     73{
     74    return RTSemRWIsWriteOwner(m->sem);
     75}
     76
     77/*virtual*/ void RWLockHandle::lockWrite()
     78{
     79    int vrc = RTSemRWRequestWrite(m->sem, RT_INDEFINITE_WAIT);
     80    AssertRC(vrc);
     81}
     82
     83/*virtual*/ void RWLockHandle::unlockWrite()
     84{
     85    int vrc = RTSemRWReleaseWrite(m->sem);
     86    AssertRC(vrc);
     87}
     88
     89/*virtual*/ void RWLockHandle::lockRead()
     90{
     91    int vrc = RTSemRWRequestRead(m->sem, RT_INDEFINITE_WAIT);
     92    AssertRC(vrc);
     93}
     94
     95/*virtual*/ void RWLockHandle::unlockRead()
     96{
     97    int vrc = RTSemRWReleaseRead(m->sem);
     98    AssertRC(vrc);
     99}
     100
     101/*virtual*/ uint32_t RWLockHandle::writeLockLevel() const
     102{
     103    return RTSemRWGetWriteRecursion(m->sem);
    89104}
    90105
     
    95110////////////////////////////////////////////////////////////////////////////////
    96111
     112struct WriteLockHandle::Data
     113{
     114    Data()
     115    { }
     116
     117    mutable RTCRITSECT sem;
     118};
     119
    97120WriteLockHandle::WriteLockHandle()
    98121{
    99     RTCritSectInit(&mCritSect);
    100 }
    101 
    102 /*virtual*/ WriteLockHandle::~WriteLockHandle()
    103 {
    104     RTCritSectDelete(&mCritSect);
     122    m = new Data;
     123    RTCritSectInit(&m->sem);
     124}
     125
     126WriteLockHandle::~WriteLockHandle()
     127{
     128    RTCritSectDelete(&m->sem);
     129    delete m;
    105130}
    106131
    107132/*virtual*/ bool WriteLockHandle::isWriteLockOnCurrentThread() const
    108133{
    109     return RTCritSectIsOwner(&mCritSect);
     134    return RTCritSectIsOwner(&m->sem);
    110135}
    111136
     
    113138{
    114139#if defined(DEBUG)
    115     RTCritSectEnterDebug(&mCritSect,
     140    RTCritSectEnterDebug(&m->sem,
    116141                         "WriteLockHandle::lockWrite() return address >>>",
    117                          0, (RTUINTPTR) ASMReturnAddress());
     142                         0, (RTUINTPTR)ASMReturnAddress());
    118143#else
    119     RTCritSectEnter(&mCritSect);
     144    RTCritSectEnter(&m->sem);
    120145#endif
    121146}
     
    123148/*virtual*/ void WriteLockHandle::unlockWrite()
    124149{
    125     RTCritSectLeave(&mCritSect);
     150    RTCritSectLeave(&m->sem);
    126151}
    127152
     
    138163/*virtual*/ uint32_t WriteLockHandle::writeLockLevel() const
    139164{
    140     return RTCritSectGetRecursion(&mCritSect);
     165    return RTCritSectGetRecursion(&m->sem);
    141166}
    142167
  • trunk/src/VBox/Main/include/AutoLock.h

    r25287 r25288  
    2323#define ____H_AUTOLOCK
    2424
    25 #include <iprt/cdefs.h>
    2625#include <iprt/types.h>
    27 #include <iprt/critsect.h>
    28 #include <iprt/thread.h>
    29 #include <iprt/semaphore.h>
    30 
    31 #include <iprt/err.h>
    32 #include <iprt/assert.h>
    33 
    34 #if defined(DEBUG)
    35 # include <iprt/asm.h> // for ASMReturnAddress
    36 #endif
    37 
    38 #include <iprt/semaphore.h>
    3926
    4027namespace util
     
    114101
    115102private:
    116     RTSEMRW mSemRW;
     103    struct Data;
     104    Data *m;
    117105};
    118106
     
    144132
    145133private:
    146     mutable RTCRITSECT mCritSect;
     134    struct Data;
     135    Data *m;
    147136};
    148137
  • trunk/src/VBox/Main/include/RemoteUSBBackend.h

    r14949 r25288  
    2727#include <VBox/vrdpapi.h>
    2828#include <VBox/vrdpusb.h>
     29
     30#include <iprt/critsect.h>
    2931
    3032//typedef enum
  • trunk/src/VBox/Main/include/VirtualBoxBase.h

    r25200 r25288  
    2424
    2525#include <iprt/cdefs.h>
     26#include <iprt/thread.h>
    2627
    2728#include <list>
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