Changeset 25834 in vbox for trunk/src/VBox/Main/glue
- Timestamp:
- Jan 14, 2010 4:21:05 PM (15 years ago)
- svn:sync-xref-src-repo-rev:
- 56614
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/glue/AutoLock.cpp
r25813 r25834 41 41 #include <vector> 42 42 #include <list> 43 #include <map> 43 44 44 45 namespace util … … 51 52 //////////////////////////////////////////////////////////////////////////////// 52 53 53 class RuntimeLockClass 54 { 55 }; 54 #ifdef VBOX_WITH_MAIN_LOCK_VALIDATION 55 typedef std::map<VBoxLockingClass, RTLOCKVALCLASS> LockValidationClassesMap; 56 LockValidationClassesMap g_mapLockValidationClasses; 57 #endif 56 58 57 59 /** … … 61 63 void InitAutoLockSystem() 62 64 { 63 RTPrintf("InitAutoLockSystem\n"); 65 #ifdef VBOX_WITH_MAIN_LOCK_VALIDATION 66 struct 67 { 68 VBoxLockingClass cls; 69 const char *pcszDescription; 70 } aClasses[] = 71 { 72 { LOCKCLASS_VIRTUALBOXOBJECT, "1-VIRTUALBOXOBJECT" }, 73 { LOCKCLASS_VIRTUALBOXLIST, "2-VIRTUALBOXLIST" }, 74 { LOCKCLASS_USBPROXYSERVICE, "3-USBPROXYSERVICE" }, 75 { LOCKCLASS_HOSTOBJECT, "4-HOSTOBJECT" }, 76 { LOCKCLASS_HOSTLIST, "5-HOSTLIST" }, 77 { LOCKCLASS_OTHEROBJECT, "6-OTHEROBJECT" }, 78 { LOCKCLASS_OTHERLIST, "7-OTHERLIST" }, 79 { LOCKCLASS_OBJECTSTATE, "8-OBJECTSTATE" } 80 }; 81 82 RTLOCKVALCLASS hClass; 83 int vrc; 84 for (unsigned i = 0; i < RT_ELEMENTS(aClasses); ++i) 85 { 86 vrc = RTLockValidatorClassCreate(&hClass, 87 true, /*fAutodidact*/ 88 RT_SRC_POS, 89 aClasses[i].pcszDescription); 90 AssertRC(vrc); 91 92 // teach the new class that the classes created previously can be held 93 // while the new class is being acquired 94 for (LockValidationClassesMap::iterator it = g_mapLockValidationClasses.begin(); 95 it != g_mapLockValidationClasses.end(); 96 ++it) 97 { 98 RTLOCKVALCLASS &canBeHeld = it->second; 99 vrc = RTLockValidatorClassAddPriorClass(hClass, 100 canBeHeld); 101 AssertRC(vrc); 102 } 103 104 // and store the new class 105 g_mapLockValidationClasses[aClasses[i].cls] = hClass; 106 } 107 108 /* WriteLockHandle critsect1(LOCKCLASS_VIRTUALBOXOBJECT); 109 WriteLockHandle critsect2(LOCKCLASS_VIRTUALBOXLIST); 110 111 AutoWriteLock lock1(critsect1 COMMA_LOCKVAL_SRC_POS); 112 AutoWriteLock lock2(critsect2 COMMA_LOCKVAL_SRC_POS);*/ 113 #endif 64 114 } 65 115 … … 76 126 77 127 RTSEMRW sem; 78 MainLockValidationClasses lockClass;79 80 #ifdef RT_LOCK_STRICT128 VBoxLockingClass lockClass; 129 130 #ifdef VBOX_WITH_MAIN_LOCK_VALIDATION 81 131 com::Utf8Str strDescription; 82 132 #endif 83 133 }; 84 134 85 RWLockHandle::RWLockHandle( MainLockValidationClasses lockClass)135 RWLockHandle::RWLockHandle(VBoxLockingClass lockClass) 86 136 { 87 137 m = new Data(); … … 89 139 m->lockClass = lockClass; 90 140 91 int vrc = RTSemRWCreateEx(&m->sem, 0 /*fFlags*/, NIL_RTLOCKVALCLASS, RTLOCKVAL_SUB_CLASS_NONE, NULL); 141 #ifdef VBOX_WITH_MAIN_LOCK_VALIDATION 142 m->strDescription = com::Utf8StrFmt("r/w %RCv", this); 143 int vrc = RTSemRWCreateEx(&m->sem, 0 /*fFlags*/, g_mapLockValidationClasses[lockClass], RTLOCKVAL_SUB_CLASS_ANY, NULL); 144 #else 145 int vrc = RTSemRWCreateEx(&m->sem, 0 /*fFlags*/, NIL_RTLOCKVALCLASS, RTLOCKVAL_SUB_CLASS_ANY, NULL); 146 #endif 92 147 AssertRC(vrc); 93 94 #ifdef RT_LOCK_STRICT95 m->strDescription = com::Utf8StrFmt("r/w %RCv", this);96 #endif97 148 } 98 149 … … 110 161 /*virtual*/ void RWLockHandle::lockWrite(LOCKVAL_SRC_POS_DECL) 111 162 { 112 #if defined(RT_LOCK_STRICT)163 #ifdef VBOX_WITH_MAIN_LOCK_VALIDATION 113 164 int vrc = RTSemRWRequestWriteDebug(m->sem, RT_INDEFINITE_WAIT, (uintptr_t)ASMReturnAddress(), RT_SRC_POS_ARGS); 114 165 #else … … 127 178 /*virtual*/ void RWLockHandle::lockRead(LOCKVAL_SRC_POS_DECL) 128 179 { 129 #if defined(RT_LOCK_STRICT)180 #ifdef VBOX_WITH_MAIN_LOCK_VALIDATION 130 181 int vrc = RTSemRWRequestReadDebug(m->sem, RT_INDEFINITE_WAIT, (uintptr_t)ASMReturnAddress(), RT_SRC_POS_ARGS); 131 182 #else … … 147 198 } 148 199 149 #ifdef RT_LOCK_STRICT200 #ifdef VBOX_WITH_MAIN_LOCK_VALIDATION 150 201 /*virtual*/ const char* RWLockHandle::describe() const 151 202 { … … 166 217 167 218 mutable RTCRITSECT sem; 168 MainLockValidationClasses lockClass;169 170 #ifdef RT_LOCK_STRICT219 VBoxLockingClass lockClass; 220 221 #ifdef VBOX_WITH_MAIN_LOCK_VALIDATION 171 222 com::Utf8Str strDescription; 172 223 #endif 173 224 }; 174 225 175 WriteLockHandle::WriteLockHandle( MainLockValidationClasses lockClass)226 WriteLockHandle::WriteLockHandle(VBoxLockingClass lockClass) 176 227 { 177 228 m = new Data; … … 179 230 m->lockClass = lockClass; 180 231 181 int vrc = RTCritSectInitEx(&m->sem, 0/*fFlags*/, NIL_RTLOCKVALCLASS, RTLOCKVAL_SUB_CLASS_NONE, NULL); 232 #ifdef VBOX_WITH_MAIN_LOCK_VALIDATION 233 m->strDescription = com::Utf8StrFmt("crit %RCv", this); 234 int vrc = RTCritSectInitEx(&m->sem, 0/*fFlags*/, g_mapLockValidationClasses[lockClass], RTLOCKVAL_SUB_CLASS_ANY, NULL); 235 #else 236 int vrc = RTCritSectInitEx(&m->sem, 0/*fFlags*/, NIL_RTLOCKVALCLASS, RTLOCKVAL_SUB_CLASS_ANY, NULL); 237 #endif 182 238 AssertRC(vrc); 183 184 #ifdef RT_LOCK_STRICT185 m->strDescription = com::Utf8StrFmt("crit %RCv", this);186 #endif187 239 } 188 240 … … 200 252 /*virtual*/ void WriteLockHandle::lockWrite(LOCKVAL_SRC_POS_DECL) 201 253 { 202 #if defined(RT_LOCK_STRICT)254 #ifdef VBOX_WITH_MAIN_LOCK_VALIDATION 203 255 RTCritSectEnterDebug(&m->sem, (uintptr_t)ASMReturnAddress(), RT_SRC_POS_ARGS); 204 256 #else … … 227 279 } 228 280 229 #ifdef RT_LOCK_STRICT281 #ifdef VBOX_WITH_MAIN_LOCK_VALIDATION 230 282 /*virtual*/ const char* WriteLockHandle::describe() const 231 283 { … … 246 298 { 247 299 Data(size_t cHandles 248 #ifdef RT_LOCK_STRICT300 #ifdef VBOX_WITH_MAIN_LOCK_VALIDATION 249 301 , const char *pcszFile_, 250 302 unsigned uLine_, … … 255 307 aHandles(cHandles), // size of array 256 308 acUnlockedInLeave(cHandles) 257 #ifdef RT_LOCK_STRICT309 #ifdef VBOX_WITH_MAIN_LOCK_VALIDATION 258 310 , pcszFile(pcszFile_), 259 311 uLine(uLine_), … … 275 327 CountsVector acUnlockedInLeave; // for each lock handle, how many times the handle was unlocked in leave(); otherwise 0 276 328 277 #ifdef RT_LOCK_STRICT329 #ifdef VBOX_WITH_MAIN_LOCK_VALIDATION 278 330 // information about where the lock occured (passed down from the AutoLock classes) 279 331 const char *pcszFile; … … 443 495 /*virtual*/ void AutoReadLock::callLockImpl(LockHandle &l) 444 496 { 445 #ifdef RT_LOCK_STRICT497 #ifdef VBOX_WITH_MAIN_LOCK_VALIDATION 446 498 l.lockRead(m->pcszFile, m->uLine, m->pcszFunction); 447 499 #else … … 475 527 /*virtual*/ void AutoWriteLockBase::callLockImpl(LockHandle &l) 476 528 { 477 #ifdef RT_LOCK_STRICT529 #ifdef VBOX_WITH_MAIN_LOCK_VALIDATION 478 530 l.lockWrite(m->pcszFile, m->uLine, m->pcszFunction); 479 531 #else
Note:
See TracChangeset
for help on using the changeset viewer.