Index: /trunk/src/VBox/Additions/common/VBoxGuest/VBoxGuest.cpp
===================================================================
--- /trunk/src/VBox/Additions/common/VBoxGuest/VBoxGuest.cpp	(revision 14310)
+++ /trunk/src/VBox/Additions/common/VBoxGuest/VBoxGuest.cpp	(revision 14311)
@@ -838,20 +838,12 @@
 }
 
-
 #ifdef VBOX_WITH_HGCM
 
-# ifndef HGCM_TIMEOUT
-/**
- * This is a callback for dealing with async waits.
- *
- * It operates in a manner similar to VBoxGuestCommonIOCtl_WaitEvent.
- */
-static DECLCALLBACK(void)
-VBoxGuestHGCMAsyncWaitCallback(VMMDevHGCMRequestHeader *pHdrNonVolatile, void *pvUser, uint32_t u32User)
+/** Worker for VBoxGuestHGCMAsyncWaitCallback*. */
+void
+VBoxGuestHGCMAsyncWaitCallbackWorker(VMMDevHGCMRequestHeader *pHdrNonVolatile, PVBOXGUESTDEVEXT pDevExt,
+                                     bool fInterruptible, uint32_t u32Timeout)
 {
     VMMDevHGCMRequestHeader volatile *pHdr = (VMMDevHGCMRequestHeader volatile *)pHdrNonVolatile;
-    const bool fInterruptible = (bool)u32User;
-    PVBOXGUESTDEVEXT pDevExt = (PVBOXGUESTDEVEXT)pvUser;
-    Log(("VBoxGuestHGCMAsyncWaitCallback: requestType=%d\n", pHdr->header.requestType));
 
     /*
@@ -901,7 +893,7 @@
     int rc;
     if (fInterruptible)
-        rc = RTSemEventMultiWaitNoResume(pWait->Event, RT_INDEFINITE_WAIT);
+        rc = RTSemEventMultiWaitNoResume(pWait->Event, u32Timeout);
     else
-        rc = RTSemEventMultiWait(pWait->Event, RT_INDEFINITE_WAIT);
+        rc = RTSemEventMultiWait(pWait->Event, u32Timeout);
 
     /*
@@ -920,77 +912,4 @@
 }
 
-# else /* HGCM_TIMEOUT */
-/** Worker for VBoxGuestHGCMAsyncWaitCallback* */
-void
-VBoxGuestHGCMAsyncWaitCallbackWorker(VMMDevHGCMRequestHeader *pHdrNonVolatile, PVBOXGUESTDEVEXT pDevExt,
-                                     bool fInterruptible, uint32_t u32Timeout)
-{
-    VMMDevHGCMRequestHeader volatile *pHdr = (VMMDevHGCMRequestHeader volatile *)pHdrNonVolatile;
-
-    /*
-     * Check to see if the condition was met by the time we got here.
-     *
-     * We create a simple poll loop here for dealing with out-of-memory
-     * conditions since the caller isn't necessarily able to deal with
-     * us returning too early.
-     */
-    RTSPINLOCKTMP Tmp = RTSPINLOCKTMP_INITIALIZER;
-    PVBOXGUESTWAIT pWait;
-    for (;;)
-    {
-        RTSpinlockAcquireNoInts(pDevExt->WaitSpinlock, &Tmp);
-        if ((pHdr->fu32Flags & VBOX_HGCM_REQ_DONE) != 0)
-        {
-            RTSpinlockReleaseNoInts(pDevExt->WaitSpinlock, &Tmp);
-            return;
-        }
-        RTSpinlockReleaseNoInts(pDevExt->WaitSpinlock, &Tmp);
-
-        pWait = VBoxGuestWaitAlloc(pDevExt);
-        if (pWait)
-            break;
-        if (fInterruptible)
-            return;
-        RTThreadSleep(1);
-    }
-    pWait->fReqEvents = VMMDEV_EVENT_HGCM;
-    pWait->pHGCMReq = pHdr;
-
-    /*
-     * Re-enter the spinlock and re-check for the condition.
-     * If the condition is met, return.
-     * Otherwise link us into the HGCM wait list and go to sleep.
-     */
-    RTSpinlockAcquireNoInts(pDevExt->WaitSpinlock, &Tmp);
-    if ((pHdr->fu32Flags & VBOX_HGCM_REQ_DONE) != 0)
-    {
-        VBoxGuestWaitFreeLocked(pDevExt, pWait);
-        RTSpinlockReleaseNoInts(pDevExt->WaitSpinlock, &Tmp);
-        return;
-    }
-    VBoxGuestWaitAppend(&pDevExt->HGCMWaitList, pWait);
-    RTSpinlockReleaseNoInts(pDevExt->WaitSpinlock, &Tmp);
-
-    int rc;
-    if (fInterruptible)
-        rc = RTSemEventMultiWaitNoResume(pWait->Event, u32Timeout);
-    else
-        rc = RTSemEventMultiWait(pWait->Event, u32Timeout);
-
-    /*
-     * This shouldn't ever return failure...
-     * Unlink, free and return.
-     */
-    if (rc == VERR_SEM_DESTROYED)
-        return;
-    if (RT_FAILURE(rc))
-        LogRel(("VBoxGuestHGCMAsyncWaitCallback: wait failed! %Rrc\n", rc));
-
-    RTSpinlockAcquireNoInts(pDevExt->WaitSpinlock, &Tmp);
-    VBoxGuestWaitUnlink(&pDevExt->HGCMWaitList, pWait);
-    VBoxGuestWaitFreeLocked(pDevExt, pWait);
-    RTSpinlockReleaseNoInts(pDevExt->WaitSpinlock, &Tmp);
-}
-
 
 /**
@@ -999,6 +918,6 @@
  * It operates in a manner similar to VBoxGuestCommonIOCtl_WaitEvent.
  */
-static DECLCALLBACK(void)
-VBoxGuestHGCMAsyncWaitCallback(VMMDevHGCMRequestHeader *pHdrNonVolatile, void *pvUser, uint32_t u32User)
+static DECLCALLBACK(void) VBoxGuestHGCMAsyncWaitCallback(VMMDevHGCMRequestHeader *pHdrNonVolatile,
+                                                         void *pvUser, uint32_t u32User)
 {
     VMMDevHGCMRequestHeader volatile *pHdr = (VMMDevHGCMRequestHeader volatile *)pHdrNonVolatile;
@@ -1015,7 +934,6 @@
  * It operates in a manner similar to VBoxGuestCommonIOCtl_WaitEvent.
  */
-static DECLCALLBACK(void)
-VBoxGuestHGCMAsyncWaitCallbackTimeoutInterruptible(VMMDevHGCMRequestHeader *pHdrNonVolatile,
-                                                   void *pvUser, uint32_t u32User)
+static DECLCALLBACK(void) VBoxGuestHGCMAsyncWaitCallbackTimeoutInterruptible(VMMDevHGCMRequestHeader *pHdrNonVolatile,
+                                                                             void *pvUser, uint32_t u32User)
 {
     PVBOXGUESTDEVEXT pDevExt = (PVBOXGUESTDEVEXT)pvUser;
@@ -1030,7 +948,6 @@
  * It operates in a manner similar to VBoxGuestCommonIOCtl_WaitEvent.
  */
-static DECLCALLBACK(void)
-VBoxGuestHGCMAsyncWaitCallbackTimeout(VMMDevHGCMRequestHeader *pHdrNonVolatile, void *pvUser,
-                                      uint32_t u32User)
+static DECLCALLBACK(void) VBoxGuestHGCMAsyncWaitCallbackTimeout(VMMDevHGCMRequestHeader *pHdrNonVolatile,
+                                                                void *pvUser, uint32_t u32User)
 {
     PVBOXGUESTDEVEXT pDevExt = (PVBOXGUESTDEVEXT)pvUser;
@@ -1038,5 +955,4 @@
     VBoxGuestHGCMAsyncWaitCallbackWorker(pHdrNonVolatile, pDevExt, false /* fInterruptible */, u32user);
 }
-# endif /* HGCM_TIMEOUT */
 
 
@@ -1202,5 +1118,6 @@
 
 # ifdef HGCM_TIMEOUT
-/** @remarks Identical to VBoxGuestCommonIOCtl_HGCMCall. */
+/** @remarks Identical to VBoxGuestCommonIOCtl_HGCMCall.
+ * @todo r=bird: merge the two.  */
 static int VBoxGuestCommonIOCtl_HGCMCallTimeout(PVBOXGUESTDEVEXT pDevExt, PVBOXGUESTSESSION pSession, VBoxGuestHGCMCallInfoTimeout *pInfoTimeout,
                                                 size_t cbData, size_t *pcbDataReturned)
@@ -1331,5 +1248,4 @@
 
 #endif /* VBOX_WITH_HGCM */
-
 
 /**
@@ -1413,4 +1329,5 @@
      * These ones are tricky and can be done later.
      */
+/**@todo r=bird: Merge the handling of these two. The only difference is that the 2nd has one or two extra argument preceeding the call info. */
     else if (VBOXGUEST_IOCTL_STRIP_SIZE(iFunction) == VBOXGUEST_IOCTL_STRIP_SIZE(VBOXGUEST_IOCTL_HGCM_CALL(0)))
     {
