Changeset 90381 in vbox for trunk/src/VBox/VMM/VMMAll
- Timestamp:
- Jul 28, 2021 9:58:54 PM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/VMM/VMMAll/PDMAllCritSect.cpp
r90379 r90381 129 129 * @param hNativeSelf The native thread handle. 130 130 * @param pSrcPos The source position of the lock operation. 131 */ 132 static int pdmR3R0CritSectEnterContended(PVMCC pVM, PPDMCRITSECT pCritSect, RTNATIVETHREAD hNativeSelf, PCRTLOCKVALSRCPOS pSrcPos) 131 * @param rcBusy The status code to return when we're in RC or R0 132 */ 133 static int pdmR3R0CritSectEnterContended(PVMCC pVM, PPDMCRITSECT pCritSect, RTNATIVETHREAD hNativeSelf, 134 PCRTLOCKVALSRCPOS pSrcPos, int rcBusy) 133 135 { 134 136 /* … … 169 171 * been signalled and the interruptible wait function returning 170 172 * immediately. In that case we do normal R0/RC rcBusy handling. 173 * 174 * We always do a timed wait here, so the event handle is revalidated 175 * regularly and we won't end up stuck waiting for a destroyed critsect. 171 176 */ 177 /** @todo Make SUPSemEventClose wake up all waiters. */ 172 178 # ifdef IN_RING3 173 179 # ifdef PDMCRITSECT_STRICT … … 180 186 RTThreadBlocking(hThreadSelf, RTTHREADSTATE_CRITSECT, true); 181 187 # endif 182 int rc = SUPSemEventWaitNoResume(pSession, hEvent, RT_ INDEFINITE_WAIT);188 int rc = SUPSemEventWaitNoResume(pSession, hEvent, RT_MS_5SEC); 183 189 RTThreadUnblocked(hThreadSelf, RTTHREADSTATE_CRITSECT); 184 190 # else /* IN_RING0 */ 185 int rc = SUPSemEventWaitNoResume(pSession, hEvent, RT_ INDEFINITE_WAIT);191 int rc = SUPSemEventWaitNoResume(pSession, hEvent, RT_MS_5SEC); 186 192 # endif /* IN_RING0 */ 187 193 … … 189 195 * Deal with the return code and critsect destruction. 190 196 */ 191 if (RT_UNLIKELY(pCritSect->s.Core.u32Magic != RTCRITSECT_MAGIC)) 197 if (RT_LIKELY(pCritSect->s.Core.u32Magic == RTCRITSECT_MAGIC)) 198 { /* likely */ } 199 else 192 200 return VERR_SEM_DESTROYED; 193 201 if (rc == VINF_SUCCESS) 194 202 return pdmCritSectEnterFirst(pCritSect, hNativeSelf, pSrcPos); 195 AssertMsg(rc == VERR_INTERRUPTED, ("rc=%Rrc\n", rc)); 203 if (RT_LIKELY(rc == VERR_TIMEOUT || rc == VERR_INTERRUPTED)) 204 { /* likely */ } 205 else 206 { 207 AssertMsgFailed(("rc=%Rrc\n", rc)); 208 return rc; 209 } 196 210 197 211 # ifdef IN_RING0 … … 202 216 it without creating a race with PDMCritSectLeave, resulting in 203 217 spurious wakeups. */ 218 RT_NOREF(rcBusy); 219 /** @todo eliminate this and return rcBusy instead. Guru if 220 * rcBusy is VINF_SUCCESS. */ 204 221 PVMCPUCC pVCpu = VMMGetCpu(pVM); AssertPtr(pVCpu); 205 222 rc = VMMRZCallRing3(pVM, pVCpu, VMMCALLRING3_VM_R0_PREEMPT, NULL); 206 223 AssertRC(rc); 207 224 # else 208 RT_NOREF(pVM );225 RT_NOREF(pVM, rcBusy); 209 226 # endif 210 227 } … … 218 235 * 219 236 * @returns VINF_SUCCESS if entered successfully. 220 * @returns rcBusy when encountering a busy critical section in GC/R0.237 * @returns rcBusy when encountering a busy critical section in RC/R0. 221 238 * @retval VERR_SEM_DESTROYED if the critical section is delete before or 222 239 * during the operation. … … 224 241 * @param pVM The cross context VM structure. 225 242 * @param pCritSect The PDM critical section to enter. 226 * @param rcBusy The status code to return when we're in GC or R0243 * @param rcBusy The status code to return when we're in RC or R0 227 244 * @param pSrcPos The source position of the lock operation. 228 245 */ … … 290 307 */ 291 308 NOREF(rcBusy); 292 return pdmR3R0CritSectEnterContended(pVM, pCritSect, hNativeSelf, pSrcPos );309 return pdmR3R0CritSectEnterContended(pVM, pCritSect, hNativeSelf, pSrcPos, rcBusy); 293 310 294 311 #elif defined(IN_RING0) … … 314 331 Assert(RTThreadPreemptIsEnabled(NIL_RTTHREAD)); 315 332 316 rc = pdmR3R0CritSectEnterContended(pVM, pCritSect, hNativeSelf, pSrcPos );333 rc = pdmR3R0CritSectEnterContended(pVM, pCritSect, hNativeSelf, pSrcPos, rcBusy); 317 334 318 335 VMMR0EmtResumeAfterBlocking(pVCpu, &Ctx); … … 325 342 /* Non-EMT. */ 326 343 Assert(RTThreadPreemptIsEnabled(NIL_RTTHREAD)); 327 return pdmR3R0CritSectEnterContended(pVM, pCritSect, hNativeSelf, pSrcPos );344 return pdmR3R0CritSectEnterContended(pVM, pCritSect, hNativeSelf, pSrcPos, rcBusy); 328 345 329 346 # else /* old code: */ … … 333 350 if ( RTThreadPreemptIsEnabled(NIL_RTTHREAD) 334 351 && ASMIntAreEnabled()) 335 return pdmR3R0CritSectEnterContended(pVM, pCritSect, hNativeSelf, pSrcPos );352 return pdmR3R0CritSectEnterContended(pVM, pCritSect, hNativeSelf, pSrcPos, rcBusy); 336 353 337 354 STAM_REL_COUNTER_INC(&pCritSect->s.StatContentionRZLock);
Note:
See TracChangeset
for help on using the changeset viewer.