Index: trunk/src/VBox/VMM/VMMR0/GVMMR0.cpp
===================================================================
--- trunk/src/VBox/VMM/VMMR0/GVMMR0.cpp	(revision 6634)
+++ trunk/src/VBox/VMM/VMMR0/GVMMR0.cpp	(revision 6635)
@@ -390,4 +390,64 @@
 
 /**
+ * Try acquire the 'used' lock.
+ *
+ * @returns IPRT status code, see RTSemFastMutexRequest.
+ * @param   pGVMM   The GVMM instance data.
+ */
+DECLINLINE(int) gvmmR0UsedLock(PGVMM pGVMM)
+{
+    LogFlow(("++gvmmR0UsedLock(%p)\n", pGVMM));
+    int rc = RTSemFastMutexRequest(pGVMM->UsedLock);
+    LogFlow(("gvmmR0UsedLock(%p)->%Rrc\n", pGVMM, rc));
+    return rc;
+}
+
+
+/**
+ * Release the 'used' lock.
+ *
+ * @returns IPRT status code, see RTSemFastMutexRelease.
+ * @param   pGVMM   The GVMM instance data.
+ */
+DECLINLINE(int) gvmmR0UsedUnlock(PGVMM pGVMM)
+{
+    LogFlow(("--gvmmR0UsedUnlock(%p)\n", pGVMM));
+    int rc = RTSemFastMutexRelease(pGVMM->UsedLock);
+    AssertRC(rc);
+    return rc;
+}
+
+
+/**
+ * Try acquire the 'create & destroy' lock.
+ *
+ * @returns IPRT status code, see RTSemFastMutexRequest.
+ * @param   pGVMM   The GVMM instance data.
+ */
+DECLINLINE(int) gvmmR0CreateDestroyLock(PGVMM pGVMM)
+{
+    LogFlow(("++gvmmR0CreateDestroyLock(%p)\n", pGVMM));
+    int rc = RTSemFastMutexRequest(pGVMM->CreateDestroyLock);
+    LogFlow(("gvmmR0CreateDestroyLock(%p)->%Rrc\n", pGVMM, rc));
+    return rc;
+}
+
+
+/**
+ * Release the 'create & destroy' lock.
+ *
+ * @returns IPRT status code, see RTSemFastMutexRequest.
+ * @param   pGVMM   The GVMM instance data.
+ */
+DECLINLINE(int) gvmmR0CreateDestroyUnlock(PGVMM pGVMM)
+{
+    LogFlow(("--gvmmR0CreateDestroyUnlock(%p)\n", pGVMM));
+    int rc = RTSemFastMutexRelease(pGVMM->CreateDestroyLock);
+    AssertRC(rc);
+    return rc;
+}
+
+
+/**
  * Request wrapper for the GVMMR0CreateVM API.
  *
@@ -446,5 +506,5 @@
      * The whole allocation process is protected by the lock.
      */
-    int rc = RTSemFastMutexRequest(pGVMM->CreateDestroyLock);
+    int rc = gvmmR0CreateDestroyLock(pGVMM);
     AssertRCReturn(rc, rc);
 
@@ -469,5 +529,5 @@
                  * Move the handle from the free to used list and perform permission checks.
                  */
-                rc = RTSemFastMutexRequest(pGVMM->UsedLock);
+                rc = gvmmR0UsedLock(pGVMM);
                 AssertRC(rc);
 
@@ -482,5 +542,5 @@
                 pHandle->hEMT = NIL_RTNATIVETHREAD;
 
-                RTSemFastMutexRelease(pGVMM->UsedLock);
+                gvmmR0UsedUnlock(pGVMM);
 
                 rc = SUPR0ObjVerifyAccess(pHandle->pvObj, pSession, NULL);
@@ -544,5 +604,5 @@
 
                                         /* complete the handle - take the UsedLock sem just to be careful. */
-                                        rc = RTSemFastMutexRequest(pGVMM->UsedLock);
+                                        rc = gvmmR0UsedLock(pGVMM);
                                         AssertRC(rc);
 
@@ -552,6 +612,6 @@
 
 
-                                        RTSemFastMutexRelease(pGVMM->UsedLock);
-                                        RTSemFastMutexRelease(pGVMM->CreateDestroyLock);
+                                        gvmmR0UsedUnlock(pGVMM);
+                                        gvmmR0CreateDestroyUnlock(pGVMM);
 
                                         *ppVM = pVM;
@@ -579,5 +639,5 @@
                 void *pvObj = pHandle->pvObj;
                 pHandle->pvObj = NULL;
-                RTSemFastMutexRelease(pGVMM->CreateDestroyLock);
+                gvmmR0CreateDestroyUnlock(pGVMM);
 
                 SUPR0ObjRelease(pvObj, pSession);
@@ -595,5 +655,5 @@
         rc = VERR_GVM_TOO_MANY_VMS;
 
-    RTSemFastMutexRelease(pGVMM->CreateDestroyLock);
+    gvmmR0CreateDestroyUnlock(pGVMM);
     return rc;
 }
@@ -654,7 +714,7 @@
      * Take the lock, validate the handle and update the structure members.
      */
-    int rc = RTSemFastMutexRequest(pGVMM->CreateDestroyLock);
+    int rc = gvmmR0CreateDestroyLock(pGVMM);
     AssertRCReturn(rc, rc);
-    rc = RTSemFastMutexRequest(pGVMM->UsedLock);
+    rc = gvmmR0UsedLock(pGVMM);
     AssertRC(rc);
 
@@ -671,6 +731,6 @@
         rc = VERR_INTERNAL_ERROR;
 
-    RTSemFastMutexRelease(pGVMM->UsedLock);
-    RTSemFastMutexRelease(pGVMM->CreateDestroyLock);
+    gvmmR0UsedUnlock(pGVMM);
+    gvmmR0CreateDestroyUnlock(pGVMM);
     LogFlow(("GVMMR0AssociateEMTWithVM: returns %Vrc (hEMT=%RTnthrd)\n", rc, hEMT));
     return rc;
@@ -750,7 +810,7 @@
      * Take the lock, validate the handle and update the structure members.
      */
-    int rc = RTSemFastMutexRequest(pGVMM->CreateDestroyLock);
+    int rc = gvmmR0CreateDestroyLock(pGVMM);
     AssertRCReturn(rc, rc);
-    rc = RTSemFastMutexRequest(pGVMM->UsedLock);
+    rc = gvmmR0UsedLock(pGVMM);
     AssertRC(rc);
 
@@ -772,6 +832,6 @@
         rc = VERR_INVALID_HANDLE;
 
-    RTSemFastMutexRelease(pGVMM->UsedLock);
-    RTSemFastMutexRelease(pGVMM->CreateDestroyLock);
+    gvmmR0UsedUnlock(pGVMM);
+    gvmmR0CreateDestroyUnlock(pGVMM);
     LogFlow(("GVMMR0DisassociateEMTFromVM: returns %Vrc (hEMT=%RTnthrd)\n", rc, hEMT));
     return rc;
@@ -821,5 +881,5 @@
      * object, we take some precautions against racing callers just in case...
      */
-    int rc = RTSemFastMutexRequest(pGVMM->CreateDestroyLock);
+    int rc = gvmmR0CreateDestroyLock(pGVMM);
     AssertRC(rc);
 
@@ -835,5 +895,5 @@
         void *pvObj = pHandle->pvObj;
         pHandle->pvObj = NULL;
-        RTSemFastMutexRelease(pGVMM->CreateDestroyLock);
+        gvmmR0CreateDestroyUnlock(pGVMM);
 
         SUPR0ObjRelease(pvObj, pHandle->pSession);
@@ -843,5 +903,5 @@
         SUPR0Printf("GVMMR0DestroyVM: pHandle=%p:{.pVM=%p, hEMT=%p, .pvObj=%p} pVM=%p hSelf=%p\n",
                     pHandle, pHandle->pVM, pHandle->hEMT, pHandle->pvObj, pVM, hSelf);
-        RTSemFastMutexRelease(pGVMM->CreateDestroyLock);
+        gvmmR0CreateDestroyUnlock(pGVMM);
         rc = VERR_INTERNAL_ERROR;
     }
@@ -877,7 +937,7 @@
     }
 
-    int rc = RTSemFastMutexRequest(pGVMM->CreateDestroyLock);
+    int rc = gvmmR0CreateDestroyLock(pGVMM);
     AssertRC(rc);
-    rc = RTSemFastMutexRequest(pGVMM->UsedLock);
+    rc = gvmmR0UsedLock(pGVMM);
     AssertRC(rc);
 
@@ -888,6 +948,6 @@
     {
         SUPR0Printf("GVM: used list index %d is out of range!\n", pHandle->iNext);
-        RTSemFastMutexRelease(pGVMM->UsedLock);
-        RTSemFastMutexRelease(pGVMM->CreateDestroyLock);
+        gvmmR0UsedUnlock(pGVMM);
+        gvmmR0CreateDestroyUnlock(pGVMM);
         return;
     }
@@ -904,6 +964,6 @@
             {
                 SUPR0Printf("GVM: used list index %d is out of range!\n");
-                RTSemFastMutexRelease(pGVMM->UsedLock);
-                RTSemFastMutexRelease(pGVMM->CreateDestroyLock);
+                gvmmR0UsedUnlock(pGVMM);
+                gvmmR0CreateDestroyUnlock(pGVMM);
                 return;
             }
@@ -921,6 +981,6 @@
         {
             SUPR0Printf("GVM: can't find the handle previous previous of %d!\n", pHandle->iSelf);
-            RTSemFastMutexRelease(pGVMM->UsedLock);
-            RTSemFastMutexRelease(pGVMM->CreateDestroyLock);
+            gvmmR0UsedUnlock(pGVMM);
+            gvmmR0CreateDestroyUnlock(pGVMM);
             return;
         }
@@ -931,5 +991,5 @@
     pGVMM->cVMs--;
 
-    RTSemFastMutexRelease(pGVMM->UsedLock);
+    gvmmR0UsedUnlock(pGVMM);
 
     /*
@@ -980,5 +1040,5 @@
      * Reacquire the UsedLock here to since we're updating handle fields.
      */
-    rc = RTSemFastMutexRequest(pGVMM->UsedLock);
+    rc = gvmmR0UsedLock(pGVMM);
     AssertRC(rc);
 
@@ -991,6 +1051,6 @@
     ASMAtomicXchgSize(&pHandle->hEMT, NIL_RTNATIVETHREAD);
 
-    RTSemFastMutexRelease(pGVMM->UsedLock);
-    RTSemFastMutexRelease(pGVMM->CreateDestroyLock);
+    gvmmR0UsedUnlock(pGVMM);
+    gvmmR0CreateDestroyUnlock(pGVMM);
     LogFlow(("gvmmR0HandleObjDestructor: returns\n"));
 }
@@ -1068,5 +1128,5 @@
     if (fTakeUsedLock)
     {
-        int rc = RTSemFastMutexRequest(pGVMM->UsedLock);
+        int rc = gvmmR0UsedLock(pGVMM);
         AssertRCReturn(rc, rc);
 
@@ -1077,5 +1137,5 @@
                         ||  pGVM->pVM != pVM))
         {
-            RTSemFastMutexRelease(pGVMM->UsedLock);
+            gvmmR0UsedUnlock(pGVMM);
             return VERR_INVALID_HANDLE;
         }
@@ -1089,7 +1149,7 @@
 
         pGVM = pHandle->pGVM;
-        if (!RT_UNLIKELY(!VALID_PTR(pGVM)))
+        if (RT_UNLIKELY(!VALID_PTR(pGVM)))
             return VERR_INVALID_HANDLE;
-        if (!RT_UNLIKELY(pGVM->pVM != pVM))
+        if (RT_UNLIKELY(pGVM->pVM != pVM))
             return VERR_INVALID_HANDLE;
     }
@@ -1365,5 +1425,5 @@
      * Interrupts must NOT be disabled at this point because we ask for GIP time!
      */
-    rc = RTSemFastMutexRequest(pGVMM->UsedLock);
+    rc = gvmmR0UsedLock(pGVMM);
     AssertRC(rc);
 
@@ -1384,5 +1444,5 @@
         pGVM->gvmm.s.StatsSched.cHaltBlocking++;
         ASMAtomicXchgU64(&pGVM->gvmm.s.u64HaltExpire, u64ExpireGipTime);
-        RTSemFastMutexRelease(pGVMM->UsedLock);
+        gvmmR0UsedUnlock(pGVMM);
 
         uint32_t cMillies = (u64ExpireGipTime - u64Now) / 1000000;
@@ -1398,5 +1458,5 @@
     {
         pGVM->gvmm.s.StatsSched.cHaltNotBlocking++;
-        RTSemFastMutexRelease(pGVMM->UsedLock);
+        gvmmR0UsedUnlock(pGVMM);
     }
 
@@ -1458,5 +1518,5 @@
 
 
-        rc2 = RTSemFastMutexRelease(pGVMM->UsedLock);
+        rc2 = gvmmR0UsedUnlock(pGVMM);
         AssertRC(rc2);
     }
@@ -1491,5 +1551,5 @@
     if (RT_SUCCESS(rc))
     {
-        rc = RTSemFastMutexRequest(pGVMM->UsedLock);
+        rc = gvmmR0UsedLock(pGVMM);
         AssertRC(rc);
         pGVM->gvmm.s.StatsSched.cPollCalls++;
@@ -1506,5 +1566,5 @@
         }
 
-        RTSemFastMutexRelease(pGVMM->UsedLock);
+        gvmmR0UsedUnlock(pGVMM);
     }
 
@@ -1552,5 +1612,5 @@
         memset(&pStats->SchedVM, 0, sizeof(pStats->SchedVM));
 
-        int rc = RTSemFastMutexRequest(pGVMM->UsedLock);
+        int rc = gvmmR0UsedLock(pGVMM);
         AssertRCReturn(rc, rc);
     }
@@ -1591,5 +1651,5 @@
     }
 
-    RTSemFastMutexRelease(pGVMM->UsedLock);
+    gvmmR0UsedUnlock(pGVMM);
 
     return VINF_SUCCESS;
@@ -1664,5 +1724,5 @@
         GVMM_GET_VALID_INSTANCE(pGVMM, VERR_INTERNAL_ERROR);
 
-        int rc = RTSemFastMutexRequest(pGVMM->UsedLock);
+        int rc = gvmmR0UsedLock(pGVMM);
         AssertRCReturn(rc, rc);
     }
@@ -1702,5 +1762,5 @@
     }
 
-    RTSemFastMutexRelease(pGVMM->UsedLock);
+    gvmmR0UsedUnlock(pGVMM);
 
     return VINF_SUCCESS;
