VirtualBox

Changeset 28625 in vbox


Ignore:
Timestamp:
Apr 23, 2010 7:57:16 AM (15 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
60476
Message:

Guest Control: Update (no buffered host waiting anymore, fixed a couple of deadlocks and shutdown crashes).

Location:
trunk/src/VBox
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VBoxManage/VBoxManageGuestCtrl.cpp

    r28557 r28625  
    6565             "                            <path to program> [--arguments \"<arguments>\"] [--environment \"<NAME=VALUE NAME=VALUE>\"]\n"
    6666             "                            [--flags <flags>] [--timeout <msec>] [--username <name> [--password <password>]]\n"
    67              "                            [--verbose] [--wait-for exit]\n"
     67             "                            [--verbose] [--wait-for exit,stdout,stderr||]\n"
    6868             "\n");
    6969}
  • trunk/src/VBox/HostServices/GuestControl/service.cpp

    r28557 r28625  
    531531    int rc = VINF_SUCCESS;
    532532
    533     HostCmd newCmd;
    534     rc = paramBufferAllocate(&newCmd.parmBuf, eFunction, cParms, paParms);
    535     if (RT_SUCCESS(rc))
    536     {
    537         mHostCmds.push_back(newCmd);
    538 
    539         /* Limit list size by deleting oldest element. */
    540         if (mHostCmds.size() > 256) /** @todo Use a define! */
    541             mHostCmds.pop_front();
    542     }
    543 
    544533    /* Some lazy guests to wake up which can process this command right now? */
    545534    if (!mGuestWaiters.empty())
    546535    {
    547         GuestCall curCall = mGuestWaiters.front();
    548         rc = notifyGuest(&curCall, eFunction, cParms, paParms);
    549         mGuestWaiters.pop_front();
    550     }
     536        HostCmd newCmd;
     537        rc = paramBufferAllocate(&newCmd.parmBuf, eFunction, cParms, paParms);
     538        if (RT_SUCCESS(rc))
     539        {
     540            mHostCmds.push_back(newCmd);
     541   
     542            /* Limit list size by deleting oldest element. */
     543            if (mHostCmds.size() > 256) /** @todo Use a define! */
     544                mHostCmds.pop_front();
     545
     546            GuestCall curCall = mGuestWaiters.front();
     547            rc = notifyGuest(&curCall, eFunction, cParms, paParms);
     548            mGuestWaiters.pop_front();
     549        }
     550    }
     551    else /* No guest waiting, don't bother ... */
     552        rc = VERR_TIMEOUT;
    551553    return rc;
    552554}
  • trunk/src/VBox/Main/GuestImpl.cpp

    r28571 r28625  
    111111
    112112#ifdef VBOX_WITH_GUEST_CONTROL
     113    AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
     114
    113115    /* Clean up callback data. */
    114116    CallbackListIter it;
     
    508510    int rc = VINF_SUCCESS;
    509511
     512    AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
     513
    510514    AssertPtr(pData);
    511515    CallbackListIter it = getCtrlCallbackContextByID(pData->hdr.u32ContextID);
     
    580584    int rc = VINF_SUCCESS;
    581585
     586    AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
     587
    582588    AssertPtr(pData);
    583589    CallbackListIter it = getCtrlCallbackContextByID(pData->hdr.u32ContextID);
     
    600606            pCBData->cbData = pData->cbData;
    601607        }
    602 
    603608        ASMAtomicWriteBool(&it->bCalled, true);
    604609    }
     
    611616Guest::CallbackListIter Guest::getCtrlCallbackContextByID(uint32_t u32ContextID)
    612617{
     618    AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
     619
    613620    /** @todo Maybe use a map instead of list for fast context lookup. */
    614621    CallbackListIter it;
     
    623630Guest::CallbackListIter Guest::getCtrlCallbackContextByPID(uint32_t u32PID)
    624631{
     632    AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
     633
    625634    /** @todo Maybe use a map instead of list for fast context lookup. */
    626635    CallbackListIter it;
     
    637646{
    638647    LogFlowFuncEnter();
     648    AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
    639649    if (it->cbData)
    640650    {
     
    650660        }
    651661    }
    652     mCallbackList.erase(it);
    653662    LogFlowFuncLeave();
    654663}
     
    657666 * to the callback list. A callback is identified by a unique context ID which is used
    658667 * to identify a callback from the guest side. */
    659 uint32_t Guest::addCtrlCallbackContext(void *pvData, uint32_t cbData, Progress* pProgress)
     668uint32_t Guest::addCtrlCallbackContext(void *pvData, uint32_t cbData, Progress *pProgress)
    660669{
    661670    LogFlowFuncEnter();
    662 
     671    AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
    663672    uint32_t uNewContext = ASMAtomicIncU32(&mNextContextID);
    664673    if (uNewContext == UINT32_MAX)
     
    674683    mCallbackList.push_back(context);
    675684    if (mCallbackList.size() > 256) /* Don't let the container size get too big! */
    676         removeCtrlCallbackContext(mCallbackList.begin());
     685    {
     686        Guest::CallbackListIter it = mCallbackList.begin();
     687        removeCtrlCallbackContext(it);
     688        mCallbackList.erase(it);
     689    }
    677690
    678691    LogFlowFuncLeave();
     
    704717        AutoCaller autoCaller(this);
    705718        if (FAILED(autoCaller.rc())) return autoCaller.rc();
    706 
    707         AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
    708719
    709720        /*
     
    733744        char **papszArgv = NULL;
    734745        uint32_t uNumArgs = 0;
    735         if(aArguments > 0)
     746        if (aArguments > 0)
    736747        {
    737748            com::SafeArray<IN_BSTR> args(ComSafeArrayInArg(aArguments));
     
    800811                    paParms[i++].setUInt32(aTimeoutMS);
    801812
     813                    /* Make sure mParent is valid, so set a read lock in this scope. */
     814                    AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
     815
    802816                    /* Forward the information to the VMM device. */
    803817                    AssertPtr(mParent);
     
    809823                                                   i, paParms);
    810824                    }
     825                    else
     826                        vrc = VERR_INVALID_VM_HANDLE;
    811827                    RTMemFree(pvEnv);
    812828                }
     
    823839                 */
    824840                CallbackListIter it = getCtrlCallbackContextByID(uContextID);
    825                 uint64_t u64Started = RTTimeMilliTS();
    826                 do
     841                if (it != mCallbackList.end())
    827842                {
    828                     unsigned cMsWait;
    829                     if (aTimeoutMS == RT_INDEFINITE_WAIT)
    830                         cMsWait = 1000;
    831                     else
     843                    uint64_t u64Started = RTTimeMilliTS();
     844                    do
    832845                    {
    833                         uint64_t cMsElapsed = RTTimeMilliTS() - u64Started;
    834                         if (cMsElapsed >= aTimeoutMS)
    835                             break; /* timed out */
    836                         cMsWait = RT_MIN(1000, aTimeoutMS - (uint32_t)cMsElapsed);
    837                     }
    838                     RTThreadSleep(100);
    839                 } while (it != mCallbackList.end() && !it->bCalled);
     846                        unsigned cMsWait;
     847                        if (aTimeoutMS == RT_INDEFINITE_WAIT)
     848                            cMsWait = 1000;
     849                        else
     850                        {
     851                            uint64_t cMsElapsed = RTTimeMilliTS() - u64Started;
     852                            if (cMsElapsed >= aTimeoutMS)
     853                                break; /* Timed out. */
     854                            cMsWait = RT_MIN(1000, aTimeoutMS - (uint32_t)cMsElapsed);
     855                        }
     856                        RTThreadSleep(100);
     857                    } while (!it->bCalled);
     858                }
     859
     860                AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
    840861
    841862                /* Did we get some status? */
     
    862883                else /* If callback not called within time ... well, that's a timeout! */
    863884                    vrc = VERR_TIMEOUT;
     885
     886                alock.release();
    864887
    865888                /*
     
    903926            else
    904927            {
    905                 /* HGCM call went wrong. */
    906                 rc = setError(E_UNEXPECTED,
    907                               tr("The service call failed with error %Rrc"), vrc);
     928                if (vrc == VERR_INVALID_VM_HANDLE)
     929                {
     930                    rc = setError(VBOX_E_VM_ERROR,
     931                                  tr("VMM device is not available (is the VM running?)"));
     932                }
     933                else if (vrc == VERR_TIMEOUT)
     934                {
     935                    rc = setError(VBOX_E_VM_ERROR,
     936                                  tr("The guest execution service is not ready"));
     937                }
     938                else /* HGCM call went wrong. */
     939                {
     940                    rc = setError(E_UNEXPECTED,
     941                                  tr("The service call failed with error %Rrc"), vrc);
     942                }
    908943            }
    909944
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