Changeset 45127 in vbox
- Timestamp:
- Mar 21, 2013 2:42:22 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/glue/AutoLock.cpp
r41528 r45127 1 /* $Id$ */ 1 2 /** @file 2 * 3 * Automatic locks, implementation 3 * Automatic locks, implementation. 4 4 */ 5 5 6 6 /* 7 * Copyright (C) 2006-201 2Oracle Corporation7 * Copyright (C) 2006-2013 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 16 16 */ 17 17 18 19 /******************************************************************************* 20 * Defined Constants And Macros * 21 *******************************************************************************/ 22 #define GLUE_USE_CRITSECTRW 23 24 25 /******************************************************************************* 26 * Header Files * 27 *******************************************************************************/ 18 28 #include <iprt/cdefs.h> 19 29 #include <iprt/critsect.h> … … 38 48 #include <list> 39 49 #include <map> 50 40 51 41 52 namespace util … … 134 145 { } 135 146 136 RTSEMRW sem; 137 VBoxLockingClass lockClass; 138 139 #ifdef VBOX_WITH_MAIN_LOCK_VALIDATION 140 com::Utf8Str strDescription; 147 #ifdef GLUE_USE_CRITSECTRW 148 mutable RTCRITSECTRW CritSect; 149 #else 150 RTSEMRW sem; 151 #endif 152 VBoxLockingClass lockClass; 153 154 #ifdef VBOX_WITH_MAIN_LOCK_VALIDATION 155 com::Utf8Str strDescription; 141 156 #endif 142 157 }; … … 147 162 148 163 m->lockClass = lockClass; 149 150 164 #ifdef VBOX_WITH_MAIN_LOCK_VALIDATION 151 165 m->strDescription = com::Utf8StrFmt("r/w %RCv", this); 166 #endif 167 168 #ifdef GLUE_USE_CRITSECTRW 169 # ifdef VBOX_WITH_MAIN_LOCK_VALIDATION 170 int vrc = RTCritSectRwInitEx(&m->CritSect, 0 /*fFlags*/, g_mapLockValidationClasses[lockClass], RTLOCKVAL_SUB_CLASS_ANY, NULL); 171 # else 172 int vrc = RTCritSectRwInitEx(&m->CritSect, 0 /*fFlags*/, NIL_RTLOCKVALCLASS, RTLOCKVAL_SUB_CLASS_ANY, NULL); 173 # endif 174 #else 175 # ifdef VBOX_WITH_MAIN_LOCK_VALIDATION 152 176 int vrc = RTSemRWCreateEx(&m->sem, 0 /*fFlags*/, g_mapLockValidationClasses[lockClass], RTLOCKVAL_SUB_CLASS_ANY, NULL); 153 # else177 # else 154 178 int vrc = RTSemRWCreateEx(&m->sem, 0 /*fFlags*/, NIL_RTLOCKVALCLASS, RTLOCKVAL_SUB_CLASS_ANY, NULL); 179 # endif 155 180 #endif 156 181 AssertRC(vrc); … … 159 184 /*virtual*/ RWLockHandle::~RWLockHandle() 160 185 { 186 #ifdef GLUE_USE_CRITSECTRW 187 RTCritSectRwDelete(&m->CritSect); 188 #else 161 189 RTSemRWDestroy(m->sem); 190 #endif 162 191 delete m; 163 192 } … … 165 194 /*virtual*/ bool RWLockHandle::isWriteLockOnCurrentThread() const 166 195 { 196 #ifdef GLUE_USE_CRITSECTRW 197 return RTCritSectRwIsWriteOwner(&m->CritSect); 198 #else 167 199 return RTSemRWIsWriteOwner(m->sem); 200 #endif 168 201 } 169 202 170 203 /*virtual*/ void RWLockHandle::lockWrite(LOCKVAL_SRC_POS_DECL) 171 204 { 172 #ifdef VBOX_WITH_MAIN_LOCK_VALIDATION 205 #ifdef GLUE_USE_CRITSECTRW 206 # ifdef VBOX_WITH_MAIN_LOCK_VALIDATION 207 int vrc = RTCritSectRwEnterExclDebug(&m->CritSect, (uintptr_t)ASMReturnAddress(), RT_SRC_POS_ARGS); 208 # else 209 int vrc = RTCritSectRwEnterExcl(&m->CritSect); 210 # endif 211 #else 212 # ifdef VBOX_WITH_MAIN_LOCK_VALIDATION 173 213 int vrc = RTSemRWRequestWriteDebug(m->sem, RT_INDEFINITE_WAIT, (uintptr_t)ASMReturnAddress(), RT_SRC_POS_ARGS); 174 # else214 # else 175 215 int vrc = RTSemRWRequestWrite(m->sem, RT_INDEFINITE_WAIT); 216 # endif 176 217 #endif 177 218 AssertRC(vrc); … … 180 221 /*virtual*/ void RWLockHandle::unlockWrite() 181 222 { 223 #ifdef GLUE_USE_CRITSECTRW 224 int vrc = RTCritSectRwLeaveExcl(&m->CritSect); 225 #else 182 226 int vrc = RTSemRWReleaseWrite(m->sem); 227 #endif 183 228 AssertRC(vrc); 184 229 … … 187 232 /*virtual*/ void RWLockHandle::lockRead(LOCKVAL_SRC_POS_DECL) 188 233 { 189 #ifdef VBOX_WITH_MAIN_LOCK_VALIDATION 234 #ifdef GLUE_USE_CRITSECTRW 235 # ifdef VBOX_WITH_MAIN_LOCK_VALIDATION 236 int vrc = RTCritSectRwEnterSharedDebug(&m->CritSect, (uintptr_t)ASMReturnAddress(), RT_SRC_POS_ARGS); 237 # else 238 int vrc = RTCritSectRwEnterShared(&m->CritSect); 239 # endif 240 #else 241 # ifdef VBOX_WITH_MAIN_LOCK_VALIDATION 190 242 int vrc = RTSemRWRequestReadDebug(m->sem, RT_INDEFINITE_WAIT, (uintptr_t)ASMReturnAddress(), RT_SRC_POS_ARGS); 191 # else243 # else 192 244 int vrc = RTSemRWRequestRead(m->sem, RT_INDEFINITE_WAIT); 245 # endif 193 246 #endif 194 247 AssertRC(vrc); … … 197 250 /*virtual*/ void RWLockHandle::unlockRead() 198 251 { 252 #ifdef GLUE_USE_CRITSECTRW 253 int vrc = RTCritSectRwLeaveShared(&m->CritSect); 254 #else 199 255 int vrc = RTSemRWReleaseRead(m->sem); 256 #endif 200 257 AssertRC(vrc); 201 258 } … … 204 261 { 205 262 /* Note! This does not include read recursions done by the writer! */ 263 #ifdef GLUE_USE_CRITSECTRW 264 return RTCritSectRwGetWriteRecursion(&m->CritSect); 265 #else 206 266 return RTSemRWGetWriteRecursion(m->sem); 267 #endif 207 268 } 208 269
Note:
See TracChangeset
for help on using the changeset viewer.