Changeset 8119 in vbox for trunk/src/VBox/Main
- Timestamp:
- Apr 17, 2008 6:26:08 PM (17 years ago)
- svn:sync-xref-src-repo-rev:
- 29822
- Location:
- trunk/src/VBox/Main
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/AutoLock.cpp
r8083 r8119 25 25 RWLockHandle::RWLockHandle() 26 26 { 27 RTCritSectInit (&mCritSect); 28 RTSemEventCreate (&mGoWriteSem); 29 RTSemEventMultiCreate (&mGoReadSem); 27 #ifdef VBOX_MAIN_USE_SEMRW 28 29 int vrc = RTSemRWCreate (&mSemRW); 30 AssertRC (vrc); 31 32 #else /* VBOX_MAIN_USE_SEMRW */ 33 34 int vrc = RTCritSectInit (&mCritSect); 35 AssertRC (vrc); 36 vrc = RTSemEventCreate (&mGoWriteSem); 37 AssertRC (vrc); 38 vrc = RTSemEventMultiCreate (&mGoReadSem); 39 AssertRC (vrc); 30 40 31 41 mWriteLockThread = NIL_RTTHREAD; … … 34 44 mWriteLockLevel = 0; 35 45 mWriteLockPending = 0; 46 47 #endif /* VBOX_MAIN_USE_SEMRW */ 36 48 } 37 49 38 50 RWLockHandle::~RWLockHandle() 39 51 { 52 #ifdef VBOX_MAIN_USE_SEMRW 53 54 RTSemRWDestroy (mSemRW); 55 56 #else /* VBOX_MAIN_USE_SEMRW */ 57 40 58 RTSemEventMultiDestroy (mGoReadSem); 41 59 RTSemEventDestroy (mGoWriteSem); 42 60 RTCritSectDelete (&mCritSect); 61 62 #endif /* VBOX_MAIN_USE_SEMRW */ 43 63 } 44 64 45 65 bool RWLockHandle::isWriteLockOnCurrentThread() const 46 66 { 67 #ifdef VBOX_MAIN_USE_SEMRW 68 69 return RTSemRWIsWriteOwner (mSemRW); 70 71 #else /* VBOX_MAIN_USE_SEMRW */ 72 47 73 RTCritSectEnter (&mCritSect); 48 74 bool locked = mWriteLockThread == RTThreadSelf(); 49 75 RTCritSectLeave (&mCritSect); 50 76 return locked; 77 78 #endif /* VBOX_MAIN_USE_SEMRW */ 51 79 } 52 80 53 81 void RWLockHandle::lockWrite() 54 82 { 83 #ifdef VBOX_MAIN_USE_SEMRW 84 85 int vrc = RTSemRWRequestWrite (mSemRW, RT_INDEFINITE_WAIT); 86 AssertRC (vrc); 87 88 #else /* VBOX_MAIN_USE_SEMRW */ 89 55 90 RTCritSectEnter (&mCritSect); 56 91 … … 79 114 80 115 RTCritSectLeave (&mCritSect); 116 117 #endif /* VBOX_MAIN_USE_SEMRW */ 81 118 } 82 119 83 120 void RWLockHandle::unlockWrite() 84 121 { 122 #ifdef VBOX_MAIN_USE_SEMRW 123 124 int vrc = RTSemRWReleaseWrite (mSemRW); 125 AssertRC (vrc); 126 127 #else /* VBOX_MAIN_USE_SEMRW */ 128 85 129 RTCritSectEnter (&mCritSect); 86 130 … … 103 147 104 148 RTCritSectLeave (&mCritSect); 149 150 #endif /* VBOX_MAIN_USE_SEMRW */ 105 151 } 106 152 107 153 void RWLockHandle::lockRead() 108 154 { 155 #ifdef VBOX_MAIN_USE_SEMRW 156 157 int vrc = RTSemRWRequestRead (mSemRW, RT_INDEFINITE_WAIT); 158 AssertRC (vrc); 159 160 #else /* VBOX_MAIN_USE_SEMRW */ 161 109 162 RTCritSectEnter (&mCritSect); 110 163 … … 146 199 if (isWriteLock) 147 200 RTSemEventMultiWait (mGoReadSem, RT_INDEFINITE_WAIT); 201 202 #endif /* VBOX_MAIN_USE_SEMRW */ 148 203 } 149 204 150 205 void RWLockHandle::unlockRead() 151 206 { 207 #ifdef VBOX_MAIN_USE_SEMRW 208 209 int vrc = RTSemRWReleaseRead (mSemRW); 210 AssertRC (vrc); 211 212 #else /* VBOX_MAIN_USE_SEMRW */ 213 152 214 RTCritSectEnter (&mCritSect); 153 215 … … 177 239 178 240 RTCritSectLeave (&mCritSect); 241 242 #endif /* VBOX_MAIN_USE_SEMRW */ 179 243 } 180 244 181 245 uint32_t RWLockHandle::writeLockLevel() const 182 246 { 247 #ifdef VBOX_MAIN_USE_SEMRW 248 249 return RTSemRWGetWriteRecursion (mSemRW); 250 251 #else /* VBOX_MAIN_USE_SEMRW */ 252 183 253 Assert (mWriteLockLevel != 0); 184 254 185 255 return mWriteLockLevel; 256 257 #endif /* VBOX_MAIN_USE_SEMRW */ 186 258 } 187 259 -
trunk/src/VBox/Main/Makefile.kmk
r8059 r8119 49 49 VBOX_MAIN_DEFS += VBOX_WITH_UNIXY_TAP_NETWORKING 50 50 endif 51 ## @todo later when RTSemRWIsWriteOwner and RTSemRWGetWriteRecursion are done 52 #ifeq ($(filter-out linux darwin freebsd solaris,$(BUILD_TARGET)),) 53 # VBOX_MAIN_DEFS += VBOX_MAIN_USE_SEMRW 54 #endif 55 51 56 ## @todo eliminate or expand VBOX_MAIN_DEFS. 52 57 -
trunk/src/VBox/Main/include/AutoLock.h
r8083 r8119 25 25 #include <iprt/semaphore.h> 26 26 27 #include <iprt/err.h> 27 28 #include <iprt/assert.h> 28 29 29 30 #if defined(DEBUG) 30 31 # include <iprt/asm.h> // for ASMReturnAddress 32 #endif 33 34 #ifdef VBOX_MAIN_USE_SEMRW 35 # include <iprt/semaphore.h> 31 36 #endif 32 37 … … 172 177 uint32_t writeLockLevel() const; 173 178 179 #ifdef VBOX_MAIN_USE_SEMRW 180 181 RTSEMRW mSemRW; 182 183 #else /* VBOX_MAIN_USE_SEMRW */ 184 174 185 mutable RTCRITSECT mCritSect; 175 186 RTSEMEVENT mGoWriteSem; … … 181 192 uint32_t mWriteLockLevel; 182 193 uint32_t mWriteLockPending; 194 195 #endif /* VBOX_MAIN_USE_SEMRW */ 183 196 }; 184 197
Note:
See TracChangeset
for help on using the changeset viewer.