VirtualBox

Changeset 6635 in vbox for trunk/src


Ignore:
Timestamp:
Jan 30, 2008 9:45:30 PM (17 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
27696
Message:

Wrap locking and unlocking of the two semaphores to make it easier to debug deadlocks.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/VMM/VMMR0/GVMMR0.cpp

    r6542 r6635  
    390390
    391391/**
     392 * Try acquire the 'used' lock.
     393 *
     394 * @returns IPRT status code, see RTSemFastMutexRequest.
     395 * @param   pGVMM   The GVMM instance data.
     396 */
     397DECLINLINE(int) gvmmR0UsedLock(PGVMM pGVMM)
     398{
     399    LogFlow(("++gvmmR0UsedLock(%p)\n", pGVMM));
     400    int rc = RTSemFastMutexRequest(pGVMM->UsedLock);
     401    LogFlow(("gvmmR0UsedLock(%p)->%Rrc\n", pGVMM, rc));
     402    return rc;
     403}
     404
     405
     406/**
     407 * Release the 'used' lock.
     408 *
     409 * @returns IPRT status code, see RTSemFastMutexRelease.
     410 * @param   pGVMM   The GVMM instance data.
     411 */
     412DECLINLINE(int) gvmmR0UsedUnlock(PGVMM pGVMM)
     413{
     414    LogFlow(("--gvmmR0UsedUnlock(%p)\n", pGVMM));
     415    int rc = RTSemFastMutexRelease(pGVMM->UsedLock);
     416    AssertRC(rc);
     417    return rc;
     418}
     419
     420
     421/**
     422 * Try acquire the 'create & destroy' lock.
     423 *
     424 * @returns IPRT status code, see RTSemFastMutexRequest.
     425 * @param   pGVMM   The GVMM instance data.
     426 */
     427DECLINLINE(int) gvmmR0CreateDestroyLock(PGVMM pGVMM)
     428{
     429    LogFlow(("++gvmmR0CreateDestroyLock(%p)\n", pGVMM));
     430    int rc = RTSemFastMutexRequest(pGVMM->CreateDestroyLock);
     431    LogFlow(("gvmmR0CreateDestroyLock(%p)->%Rrc\n", pGVMM, rc));
     432    return rc;
     433}
     434
     435
     436/**
     437 * Release the 'create & destroy' lock.
     438 *
     439 * @returns IPRT status code, see RTSemFastMutexRequest.
     440 * @param   pGVMM   The GVMM instance data.
     441 */
     442DECLINLINE(int) gvmmR0CreateDestroyUnlock(PGVMM pGVMM)
     443{
     444    LogFlow(("--gvmmR0CreateDestroyUnlock(%p)\n", pGVMM));
     445    int rc = RTSemFastMutexRelease(pGVMM->CreateDestroyLock);
     446    AssertRC(rc);
     447    return rc;
     448}
     449
     450
     451/**
    392452 * Request wrapper for the GVMMR0CreateVM API.
    393453 *
     
    446506     * The whole allocation process is protected by the lock.
    447507     */
    448     int rc = RTSemFastMutexRequest(pGVMM->CreateDestroyLock);
     508    int rc = gvmmR0CreateDestroyLock(pGVMM);
    449509    AssertRCReturn(rc, rc);
    450510
     
    469529                 * Move the handle from the free to used list and perform permission checks.
    470530                 */
    471                 rc = RTSemFastMutexRequest(pGVMM->UsedLock);
     531                rc = gvmmR0UsedLock(pGVMM);
    472532                AssertRC(rc);
    473533
     
    482542                pHandle->hEMT = NIL_RTNATIVETHREAD;
    483543
    484                 RTSemFastMutexRelease(pGVMM->UsedLock);
     544                gvmmR0UsedUnlock(pGVMM);
    485545
    486546                rc = SUPR0ObjVerifyAccess(pHandle->pvObj, pSession, NULL);
     
    544604
    545605                                        /* complete the handle - take the UsedLock sem just to be careful. */
    546                                         rc = RTSemFastMutexRequest(pGVMM->UsedLock);
     606                                        rc = gvmmR0UsedLock(pGVMM);
    547607                                        AssertRC(rc);
    548608
     
    552612
    553613
    554                                         RTSemFastMutexRelease(pGVMM->UsedLock);
    555                                         RTSemFastMutexRelease(pGVMM->CreateDestroyLock);
     614                                        gvmmR0UsedUnlock(pGVMM);
     615                                        gvmmR0CreateDestroyUnlock(pGVMM);
    556616
    557617                                        *ppVM = pVM;
     
    579639                void *pvObj = pHandle->pvObj;
    580640                pHandle->pvObj = NULL;
    581                 RTSemFastMutexRelease(pGVMM->CreateDestroyLock);
     641                gvmmR0CreateDestroyUnlock(pGVMM);
    582642
    583643                SUPR0ObjRelease(pvObj, pSession);
     
    595655        rc = VERR_GVM_TOO_MANY_VMS;
    596656
    597     RTSemFastMutexRelease(pGVMM->CreateDestroyLock);
     657    gvmmR0CreateDestroyUnlock(pGVMM);
    598658    return rc;
    599659}
     
    654714     * Take the lock, validate the handle and update the structure members.
    655715     */
    656     int rc = RTSemFastMutexRequest(pGVMM->CreateDestroyLock);
     716    int rc = gvmmR0CreateDestroyLock(pGVMM);
    657717    AssertRCReturn(rc, rc);
    658     rc = RTSemFastMutexRequest(pGVMM->UsedLock);
     718    rc = gvmmR0UsedLock(pGVMM);
    659719    AssertRC(rc);
    660720
     
    671731        rc = VERR_INTERNAL_ERROR;
    672732
    673     RTSemFastMutexRelease(pGVMM->UsedLock);
    674     RTSemFastMutexRelease(pGVMM->CreateDestroyLock);
     733    gvmmR0UsedUnlock(pGVMM);
     734    gvmmR0CreateDestroyUnlock(pGVMM);
    675735    LogFlow(("GVMMR0AssociateEMTWithVM: returns %Vrc (hEMT=%RTnthrd)\n", rc, hEMT));
    676736    return rc;
     
    750810     * Take the lock, validate the handle and update the structure members.
    751811     */
    752     int rc = RTSemFastMutexRequest(pGVMM->CreateDestroyLock);
     812    int rc = gvmmR0CreateDestroyLock(pGVMM);
    753813    AssertRCReturn(rc, rc);
    754     rc = RTSemFastMutexRequest(pGVMM->UsedLock);
     814    rc = gvmmR0UsedLock(pGVMM);
    755815    AssertRC(rc);
    756816
     
    772832        rc = VERR_INVALID_HANDLE;
    773833
    774     RTSemFastMutexRelease(pGVMM->UsedLock);
    775     RTSemFastMutexRelease(pGVMM->CreateDestroyLock);
     834    gvmmR0UsedUnlock(pGVMM);
     835    gvmmR0CreateDestroyUnlock(pGVMM);
    776836    LogFlow(("GVMMR0DisassociateEMTFromVM: returns %Vrc (hEMT=%RTnthrd)\n", rc, hEMT));
    777837    return rc;
     
    821881     * object, we take some precautions against racing callers just in case...
    822882     */
    823     int rc = RTSemFastMutexRequest(pGVMM->CreateDestroyLock);
     883    int rc = gvmmR0CreateDestroyLock(pGVMM);
    824884    AssertRC(rc);
    825885
     
    835895        void *pvObj = pHandle->pvObj;
    836896        pHandle->pvObj = NULL;
    837         RTSemFastMutexRelease(pGVMM->CreateDestroyLock);
     897        gvmmR0CreateDestroyUnlock(pGVMM);
    838898
    839899        SUPR0ObjRelease(pvObj, pHandle->pSession);
     
    843903        SUPR0Printf("GVMMR0DestroyVM: pHandle=%p:{.pVM=%p, hEMT=%p, .pvObj=%p} pVM=%p hSelf=%p\n",
    844904                    pHandle, pHandle->pVM, pHandle->hEMT, pHandle->pvObj, pVM, hSelf);
    845         RTSemFastMutexRelease(pGVMM->CreateDestroyLock);
     905        gvmmR0CreateDestroyUnlock(pGVMM);
    846906        rc = VERR_INTERNAL_ERROR;
    847907    }
     
    877937    }
    878938
    879     int rc = RTSemFastMutexRequest(pGVMM->CreateDestroyLock);
     939    int rc = gvmmR0CreateDestroyLock(pGVMM);
    880940    AssertRC(rc);
    881     rc = RTSemFastMutexRequest(pGVMM->UsedLock);
     941    rc = gvmmR0UsedLock(pGVMM);
    882942    AssertRC(rc);
    883943
     
    888948    {
    889949        SUPR0Printf("GVM: used list index %d is out of range!\n", pHandle->iNext);
    890         RTSemFastMutexRelease(pGVMM->UsedLock);
    891         RTSemFastMutexRelease(pGVMM->CreateDestroyLock);
     950        gvmmR0UsedUnlock(pGVMM);
     951        gvmmR0CreateDestroyUnlock(pGVMM);
    892952        return;
    893953    }
     
    904964            {
    905965                SUPR0Printf("GVM: used list index %d is out of range!\n");
    906                 RTSemFastMutexRelease(pGVMM->UsedLock);
    907                 RTSemFastMutexRelease(pGVMM->CreateDestroyLock);
     966                gvmmR0UsedUnlock(pGVMM);
     967                gvmmR0CreateDestroyUnlock(pGVMM);
    908968                return;
    909969            }
     
    921981        {
    922982            SUPR0Printf("GVM: can't find the handle previous previous of %d!\n", pHandle->iSelf);
    923             RTSemFastMutexRelease(pGVMM->UsedLock);
    924             RTSemFastMutexRelease(pGVMM->CreateDestroyLock);
     983            gvmmR0UsedUnlock(pGVMM);
     984            gvmmR0CreateDestroyUnlock(pGVMM);
    925985            return;
    926986        }
     
    931991    pGVMM->cVMs--;
    932992
    933     RTSemFastMutexRelease(pGVMM->UsedLock);
     993    gvmmR0UsedUnlock(pGVMM);
    934994
    935995    /*
     
    9801040     * Reacquire the UsedLock here to since we're updating handle fields.
    9811041     */
    982     rc = RTSemFastMutexRequest(pGVMM->UsedLock);
     1042    rc = gvmmR0UsedLock(pGVMM);
    9831043    AssertRC(rc);
    9841044
     
    9911051    ASMAtomicXchgSize(&pHandle->hEMT, NIL_RTNATIVETHREAD);
    9921052
    993     RTSemFastMutexRelease(pGVMM->UsedLock);
    994     RTSemFastMutexRelease(pGVMM->CreateDestroyLock);
     1053    gvmmR0UsedUnlock(pGVMM);
     1054    gvmmR0CreateDestroyUnlock(pGVMM);
    9951055    LogFlow(("gvmmR0HandleObjDestructor: returns\n"));
    9961056}
     
    10681128    if (fTakeUsedLock)
    10691129    {
    1070         int rc = RTSemFastMutexRequest(pGVMM->UsedLock);
     1130        int rc = gvmmR0UsedLock(pGVMM);
    10711131        AssertRCReturn(rc, rc);
    10721132
     
    10771137                        ||  pGVM->pVM != pVM))
    10781138        {
    1079             RTSemFastMutexRelease(pGVMM->UsedLock);
     1139            gvmmR0UsedUnlock(pGVMM);
    10801140            return VERR_INVALID_HANDLE;
    10811141        }
     
    10891149
    10901150        pGVM = pHandle->pGVM;
    1091         if (!RT_UNLIKELY(!VALID_PTR(pGVM)))
     1151        if (RT_UNLIKELY(!VALID_PTR(pGVM)))
    10921152            return VERR_INVALID_HANDLE;
    1093         if (!RT_UNLIKELY(pGVM->pVM != pVM))
     1153        if (RT_UNLIKELY(pGVM->pVM != pVM))
    10941154            return VERR_INVALID_HANDLE;
    10951155    }
     
    13651425     * Interrupts must NOT be disabled at this point because we ask for GIP time!
    13661426     */
    1367     rc = RTSemFastMutexRequest(pGVMM->UsedLock);
     1427    rc = gvmmR0UsedLock(pGVMM);
    13681428    AssertRC(rc);
    13691429
     
    13841444        pGVM->gvmm.s.StatsSched.cHaltBlocking++;
    13851445        ASMAtomicXchgU64(&pGVM->gvmm.s.u64HaltExpire, u64ExpireGipTime);
    1386         RTSemFastMutexRelease(pGVMM->UsedLock);
     1446        gvmmR0UsedUnlock(pGVMM);
    13871447
    13881448        uint32_t cMillies = (u64ExpireGipTime - u64Now) / 1000000;
     
    13981458    {
    13991459        pGVM->gvmm.s.StatsSched.cHaltNotBlocking++;
    1400         RTSemFastMutexRelease(pGVMM->UsedLock);
     1460        gvmmR0UsedUnlock(pGVMM);
    14011461    }
    14021462
     
    14581518
    14591519
    1460         rc2 = RTSemFastMutexRelease(pGVMM->UsedLock);
     1520        rc2 = gvmmR0UsedUnlock(pGVMM);
    14611521        AssertRC(rc2);
    14621522    }
     
    14911551    if (RT_SUCCESS(rc))
    14921552    {
    1493         rc = RTSemFastMutexRequest(pGVMM->UsedLock);
     1553        rc = gvmmR0UsedLock(pGVMM);
    14941554        AssertRC(rc);
    14951555        pGVM->gvmm.s.StatsSched.cPollCalls++;
     
    15061566        }
    15071567
    1508         RTSemFastMutexRelease(pGVMM->UsedLock);
     1568        gvmmR0UsedUnlock(pGVMM);
    15091569    }
    15101570
     
    15521612        memset(&pStats->SchedVM, 0, sizeof(pStats->SchedVM));
    15531613
    1554         int rc = RTSemFastMutexRequest(pGVMM->UsedLock);
     1614        int rc = gvmmR0UsedLock(pGVMM);
    15551615        AssertRCReturn(rc, rc);
    15561616    }
     
    15911651    }
    15921652
    1593     RTSemFastMutexRelease(pGVMM->UsedLock);
     1653    gvmmR0UsedUnlock(pGVMM);
    15941654
    15951655    return VINF_SUCCESS;
     
    16641724        GVMM_GET_VALID_INSTANCE(pGVMM, VERR_INTERNAL_ERROR);
    16651725
    1666         int rc = RTSemFastMutexRequest(pGVMM->UsedLock);
     1726        int rc = gvmmR0UsedLock(pGVMM);
    16671727        AssertRCReturn(rc, rc);
    16681728    }
     
    17021762    }
    17031763
    1704     RTSemFastMutexRelease(pGVMM->UsedLock);
     1764    gvmmR0UsedUnlock(pGVMM);
    17051765
    17061766    return VINF_SUCCESS;
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette