VirtualBox

Changeset 39720 in vbox


Ignore:
Timestamp:
Jan 7, 2012 2:56:25 AM (13 years ago)
Author:
vboxsync
Message:

ConsoleImpl.cpp: Try avoid holding the console lock (read or write) while firing off events.

Location:
trunk/src/VBox/Main
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/include/ConsoleImpl.h

    r39711 r39720  
    694694    const ComObjPtr<MachineDebugger> mDebugger;
    695695    const ComObjPtr<VRDEServerInfo> mVRDEServerInfo;
     696    /** This can safely be used without holding any locks.
     697     * An AutoCaller suffices to prevent it being destroy while in use and
     698     * internally there is a lock providing the necessary serialization. */
    696699    const ComObjPtr<EventSource> mEventSource;
    697700#ifdef VBOX_WITH_EXTPACK
  • trunk/src/VBox/Main/src-client/ConsoleImpl.cpp

    r39711 r39720  
    55
    66/*
    7  * Copyright (C) 2006-2011 Oracle Corporation
     7 * Copyright (C) 2006-2012 Oracle Corporation
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    18531853
    18541854    AutoCaller autoCaller(this);
    1855     if (FAILED(autoCaller.rc())) return autoCaller.rc();
    1856 
    1857     // no need to lock - lifetime constant
    1858     mEventSource.queryInterfaceTo(aEventSource);
    1859 
    1860     return S_OK;
     1855    HRESULT hrc = autoCaller.rc();
     1856    if (SUCCEEDED(hrc))
     1857    {
     1858        // no need to lock - lifetime constant
     1859        mEventSource.queryInterfaceTo(aEventSource);
     1860    }
     1861
     1862    return hrc;
    18611863}
    18621864
     
    31003102    m_mapSharedFolders.insert(std::make_pair(aName, pSharedFolder));
    31013103
    3102     /* notify console callbacks after the folder is added to the list */
     3104    /* Notify console callbacks after the folder is added to the list. */
     3105    alock.release();
    31033106    fireSharedFolderChangedEvent(mEventSource, Scope_Session);
    31043107
     
    31653168    m_mapSharedFolders.erase(strName);
    31663169
    3167     /* notify console callbacks after the folder is removed to the list */
     3170    /* Notify console callbacks after the folder is removed from the list. */
     3171    alock.release();
    31683172    fireSharedFolderChangedEvent(mEventSource, Scope_Session);
    31693173
     
    43524356    /* notify console callbacks on success */
    43534357    if (SUCCEEDED(rc))
     4358    {
     4359        alock.release(); /** @todo 101% safe? */
    43544360        fireNetworkAdapterChangedEvent(mEventSource, aNetworkAdapter);
     4361    }
    43554362
    43564363    LogFlowThisFunc(("Leaving rc=%#x\n", rc));
     
    46394646/**
    46404647 * Called by IInternalSessionControl::OnSerialPortChange().
    4641  *
    4642  * @note Locks this object for writing.
    46434648 */
    46444649HRESULT Console::onSerialPortChange(ISerialPort *aSerialPort)
     
    46494654    AssertComRCReturnRC(autoCaller.rc());
    46504655
    4651     AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
    4652 
    4653     HRESULT rc = S_OK;
    4654 
    4655     /* don't trigger serial port change if the VM isn't running */
    4656     SafeVMPtrQuiet ptrVM(this);
    4657     if (ptrVM.isOk())
    4658     {
    4659         /* nothing to do so far */
    4660         ptrVM.release();
    4661     }
    4662 
    4663     /* notify console callbacks on success */
    4664     if (SUCCEEDED(rc))
    4665         fireSerialPortChangedEvent(mEventSource, aSerialPort);
    4666 
    4667     LogFlowThisFunc(("Leaving rc=%#x\n", rc));
    4668     return rc;
     4656    fireSerialPortChangedEvent(mEventSource, aSerialPort);
     4657
     4658    LogFlowThisFunc(("Leaving rc=%#x\n", S_OK));
     4659    return S_OK;
    46694660}
    46704661
    46714662/**
    46724663 * Called by IInternalSessionControl::OnParallelPortChange().
    4673  *
    4674  * @note Locks this object for writing.
    46754664 */
    46764665HRESULT Console::onParallelPortChange(IParallelPort *aParallelPort)
     
    46814670    AssertComRCReturnRC(autoCaller.rc());
    46824671
    4683     AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
    4684 
    4685     HRESULT rc = S_OK;
    4686 
    4687     /* don't trigger parallel port change if the VM isn't running */
    4688     SafeVMPtrQuiet ptrVM(this);
    4689     if (ptrVM.isOk())
    4690     {
    4691         /* nothing to do so far */
    4692         ptrVM.release();
    4693     }
    4694 
    4695     /* notify console callbacks on success */
    4696     if (SUCCEEDED(rc))
    4697         fireParallelPortChangedEvent(mEventSource, aParallelPort);
    4698 
    4699     LogFlowThisFunc(("Leaving rc=%#x\n", rc));
    4700     return rc;
     4672    fireParallelPortChangedEvent(mEventSource, aParallelPort);
     4673
     4674    LogFlowThisFunc(("Leaving rc=%#x\n", S_OK));
     4675    return S_OK;
    47014676}
    47024677
    47034678/**
    47044679 * Called by IInternalSessionControl::OnStorageControllerChange().
    4705  *
    4706  * @note Locks this object for writing.
    47074680 */
    47084681HRESULT Console::onStorageControllerChange()
     
    47134686    AssertComRCReturnRC(autoCaller.rc());
    47144687
    4715     AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
    4716 
    4717     HRESULT rc = S_OK;
    4718 
    4719     /* don't trigger storage controller change if the VM isn't running */
    4720     SafeVMPtrQuiet ptrVM(this);
    4721     if (ptrVM.isOk())
    4722     {
    4723         /* nothing to do so far */
    4724         ptrVM.release();
    4725     }
    4726 
    4727     /* notify console callbacks on success */
    4728     if (SUCCEEDED(rc))
    4729         fireStorageControllerChangedEvent(mEventSource);
    4730 
    4731     LogFlowThisFunc(("Leaving rc=%#x\n", rc));
    4732     return rc;
     4688    fireStorageControllerChangedEvent(mEventSource);
     4689
     4690    LogFlowThisFunc(("Leaving rc=%#x\n", S_OK));
     4691    return S_OK;
    47334692}
    47344693
     
    47594718    /* notify console callbacks on success */
    47604719    if (SUCCEEDED(rc))
     4720    {
     4721        alock.release(); /** @todo 101% safe? */
    47614722        fireMediumChangedEvent(mEventSource, aMediumAttachment);
     4723    }
    47624724
    47634725    LogFlowThisFunc(("Leaving rc=%#x\n", rc));
     
    48334795    /* notify console callbacks on success */
    48344796    if (SUCCEEDED(rc))
     4797    {
     4798        alock.release();
    48354799        fireCPUExecutionCapChangedEvent(mEventSource, aExecutionCap);
     4800    }
    48364801
    48374802    LogFlowThisFunc(("Leaving rc=%#x\n", rc));
     
    48934858    /* notify console callbacks on success */
    48944859    if (SUCCEEDED(rc))
     4860    {
     4861        alock.release();
    48954862        fireVRDEServerChangedEvent(mEventSource);
     4863    }
    48964864
    48974865    return rc;
    48984866}
    48994867
    4900 /**
    4901  * @note Locks this object for reading.
    4902  */
    49034868void Console::onVRDEServerInfoChange()
    49044869{
     
    49064871    AssertComRCReturnVoid(autoCaller.rc());
    49074872
    4908     AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
    4909 
    49104873    fireVRDEServerInfoChangedEvent(mEventSource);
    49114874}
     
    49144877/**
    49154878 * Called by IInternalSessionControl::OnUSBControllerChange().
    4916  *
    4917  * @note Locks this object for writing.
    49184879 */
    49194880HRESULT Console::onUSBControllerChange()
     
    49244885    AssertComRCReturnRC(autoCaller.rc());
    49254886
    4926     AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
    4927 
    4928     HRESULT rc = S_OK;
    4929 
    4930     /* don't trigger USB controller change if the VM isn't running */
    4931     SafeVMPtrQuiet ptrVM(this);
    4932     if (ptrVM.isOk())
    4933     {
    4934         /// @todo implement one day.
    4935         // Anyway, if we want to query the machine's USB Controller we need
    4936         // to cache it to mUSBController in #init() (similar to mDVDDrive).
    4937         //
    4938         // bird: While the VM supports hot-plugging, I doubt any guest can
    4939         // handle it at this time... :-)
    4940 
    4941         /* nothing to do so far */
    4942         ptrVM.release();
    4943     }
    4944 
    4945     /* notify console callbacks on success */
    4946     if (SUCCEEDED(rc))
    4947         fireUSBControllerChangedEvent(mEventSource);
    4948 
    4949     return rc;
     4887    fireUSBControllerChangedEvent(mEventSource);
     4888
     4889    return S_OK;
    49504890}
    49514891
     
    49694909    if (SUCCEEDED(rc))
    49704910    {
     4911        alock.release();
    49714912        fireSharedFolderChangedEvent(mEventSource, aGlobal ? (Scope_T)Scope_Global : (Scope_T)Scope_Machine);
    49724913    }
     
    51795120    /* notify console callbacks on success */
    51805121    if (SUCCEEDED(rc))
     5122    {
     5123        alock.release();
    51815124        fireBandwidthGroupChangedEvent(mEventSource, aBandwidthGroup);
     5125    }
    51825126
    51835127    LogFlowThisFunc(("Leaving rc=%#x\n", rc));
     
    52145158    /* notify console callbacks on success */
    52155159    if (SUCCEEDED(rc))
     5160    {
     5161        alock.release(); /** @todo 101% safe? */
    52165162        fireStorageDeviceChangedEvent(mEventSource, aMediumAttachment, aRemove);
     5163    }
    52175164
    52185165    LogFlowThisFunc(("Leaving rc=%#x\n", rc));
     
    56855632}
    56865633
     5634#ifdef CONSOLE_WITH_EVENT_CACHE
    56875635/**
    56885636 * @note Locks this object for writing.
    56895637 */
     5638#endif
    56905639void Console::onMousePointerShapeChange(bool fVisible, bool fAlpha,
    56915640                                        uint32_t xHot, uint32_t yHot,
     
    57025651    AssertComRCReturnVoid(autoCaller.rc());
    57035652
    5704 #ifndef CONSOLE_WITH_EVENT_CACHE
    5705     AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
    5706 #else
    5707     /* We need a write lock because we alter the cached callback data */
    5708     AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
    5709 
    5710     /* Save the callback arguments */
    5711     mCallbackData.mpsc.visible = fVisible;
    5712     mCallbackData.mpsc.alpha = fAlpha;
    5713     mCallbackData.mpsc.xHot = xHot;
    5714     mCallbackData.mpsc.yHot = yHot;
    5715     mCallbackData.mpsc.width = width;
    5716     mCallbackData.mpsc.height = height;
    5717 
    5718     /* start with not valid */
    5719     bool wasValid = mCallbackData.mpsc.valid;
    5720     mCallbackData.mpsc.valid = false;
    5721 
    5722     com::SafeArray<BYTE> aShape(ComSafeArrayInArg(pShape));
    5723     if (aShape.size() != 0)
    5724         mCallbackData.mpsc.shape.initFrom(aShape);
    5725     else
    5726         mCallbackData.mpsc.shape.resize(0);
    5727     mCallbackData.mpsc.valid = true;
     5653#ifdef CONSOLE_WITH_EVENT_CACHE
     5654    {
     5655        /* We need a write lock because we alter the cached callback data */
     5656        AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
     5657
     5658        /* Save the callback arguments */
     5659        mCallbackData.mpsc.visible = fVisible;
     5660        mCallbackData.mpsc.alpha = fAlpha;
     5661        mCallbackData.mpsc.xHot = xHot;
     5662        mCallbackData.mpsc.yHot = yHot;
     5663        mCallbackData.mpsc.width = width;
     5664        mCallbackData.mpsc.height = height;
     5665
     5666        /* start with not valid */
     5667        bool wasValid = mCallbackData.mpsc.valid;
     5668        mCallbackData.mpsc.valid = false;
     5669
     5670        com::SafeArray<BYTE> aShape(ComSafeArrayInArg(pShape));
     5671        if (aShape.size() != 0)
     5672            mCallbackData.mpsc.shape.initFrom(aShape);
     5673        else
     5674            mCallbackData.mpsc.shape.resize(0);
     5675        mCallbackData.mpsc.valid = true;
     5676    }
    57285677#endif
    57295678
     
    57355684}
    57365685
     5686#ifdef CONSOLE_WITH_EVENT_CACHE
    57375687/**
    57385688 * @note Locks this object for writing.
    57395689 */
     5690#endif
    57405691void Console::onMouseCapabilityChange(BOOL supportsAbsolute, BOOL supportsRelative, BOOL needsHostCursor)
    57415692{
     
    57465697    AssertComRCReturnVoid(autoCaller.rc());
    57475698
    5748 #ifndef CONSOLE_WITH_EVENT_CACHE
    5749     AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
    5750 #else
    5751     /* We need a write lock because we alter the cached callback data */
    5752     AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
    5753 
    5754     /* save the callback arguments */
    5755     mCallbackData.mcc.supportsAbsolute = supportsAbsolute;
    5756     mCallbackData.mcc.supportsRelative = supportsRelative;
    5757     mCallbackData.mcc.needsHostCursor = needsHostCursor;
    5758     mCallbackData.mcc.valid = true;
     5699#ifdef CONSOLE_WITH_EVENT_CACHE
     5700    {
     5701        /* We need a write lock because we alter the cached callback data */
     5702        AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
     5703
     5704        /* save the callback arguments */
     5705        mCallbackData.mcc.supportsAbsolute = supportsAbsolute;
     5706        mCallbackData.mcc.supportsRelative = supportsRelative;
     5707        mCallbackData.mcc.needsHostCursor = needsHostCursor;
     5708        mCallbackData.mcc.valid = true;
     5709    }
    57595710#endif
    57605711
     
    57625713}
    57635714
    5764 /**
    5765  * @note Locks this object for reading.
    5766  */
    57675715void Console::onStateChange(MachineState_T machineState)
    57685716{
     
    57705718    AssertComRCReturnVoid(autoCaller.rc());
    57715719
    5772     AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
    57735720    fireStateChangedEvent(mEventSource, machineState);
    57745721}
    57755722
    5776 /**
    5777  * @note Locks this object for reading.
    5778  */
    57795723void Console::onAdditionsStateChange()
    57805724{
     
    57825726    AssertComRCReturnVoid(autoCaller.rc());
    57835727
    5784     AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
    57855728    fireAdditionsStateChangedEvent(mEventSource);
    57865729}
    57875730
    57885731/**
    5789  * @note Locks this object for reading.
    5790  *       This notification only is for reporting an incompatible
    5791  *       Guest Additions interface, *not* the Guest Additions version!
    5792  *
    5793  *       The user will be notified inside the guest if new Guest
    5794  *       Additions are available (via VBoxTray/VBoxClient).
     5732 * @remarks This notification only is for reporting an incompatible
     5733 *          Guest Additions interface, *not* the Guest Additions version!
     5734 *
     5735 *          The user will be notified inside the guest if new Guest
     5736 *          Additions are available (via VBoxTray/VBoxClient).
    57955737 */
    57965738void Console::onAdditionsOutdated()
     
    57995741    AssertComRCReturnVoid(autoCaller.rc());
    58005742
    5801     AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
    5802 }
    5803 
     5743    /** @todo implement this */
     5744}
     5745
     5746#ifdef CONSOLE_WITH_EVENT_CACHE
    58045747/**
    58055748 * @note Locks this object for writing.
    58065749 */
     5750#endif
    58075751void Console::onKeyboardLedsChange(bool fNumLock, bool fCapsLock, bool fScrollLock)
    58085752{
     
    58105754    AssertComRCReturnVoid(autoCaller.rc());
    58115755
    5812 #ifndef CONSOLE_WITH_EVENT_CACHE
    5813     AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
    5814 #else
    5815     /* We need a write lock because we alter the cached callback data */
    5816     AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
    5817 
    5818     /* save the callback arguments */
    5819     mCallbackData.klc.numLock = fNumLock;
    5820     mCallbackData.klc.capsLock = fCapsLock;
    5821     mCallbackData.klc.scrollLock = fScrollLock;
    5822     mCallbackData.klc.valid = true;
     5756#ifdef CONSOLE_WITH_EVENT_CACHE
     5757    {
     5758        /* We need a write lock because we alter the cached callback data */
     5759        AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
     5760
     5761        /* save the callback arguments */
     5762        mCallbackData.klc.numLock = fNumLock;
     5763        mCallbackData.klc.capsLock = fCapsLock;
     5764        mCallbackData.klc.scrollLock = fScrollLock;
     5765        mCallbackData.klc.valid = true;
     5766    }
    58235767#endif
    58245768
     
    58265770}
    58275771
    5828 /**
    5829  * @note Locks this object for reading.
    5830  */
    58315772void Console::onUSBDeviceStateChange(IUSBDevice *aDevice, bool aAttached,
    58325773                                     IVirtualBoxErrorInfo *aError)
     
    58355776    AssertComRCReturnVoid(autoCaller.rc());
    58365777
    5837     AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
    58385778    fireUSBDeviceStateChangedEvent(mEventSource, aDevice, aAttached, aError);
    58395779}
    58405780
    5841 /**
    5842  * @note Locks this object for reading.
    5843  */
    58445781void Console::onRuntimeError(BOOL aFatal, IN_BSTR aErrorID, IN_BSTR aMessage)
    58455782{
     
    58475784    AssertComRCReturnVoid(autoCaller.rc());
    58485785
    5849     AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
    58505786    fireRuntimeErrorEvent(mEventSource, aFatal, aErrorID, aMessage);
    58515787}
    58525788
    5853 /**
    5854  * @note Locks this object for reading.
    5855  */
    58565789HRESULT Console::onShowWindow(BOOL aCheck, BOOL *aCanShow, LONG64 *aWinId)
    58575790{
     
    58655798    AssertComRCReturnRC(autoCaller.rc());
    58665799
    5867     AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
    58685800    VBoxEventDesc evDesc;
    5869 
    58705801    if (aCheck)
    58715802    {
     
    58875818            else
    58885819            {
    5889                 Assert(FALSE);
     5820                AssertFailed();
    58905821                *aCanShow = TRUE;
    58915822            }
     
    59045835            evDesc.getEvent(pEvent.asOutParam());
    59055836            ComPtr<IShowWindowEvent> pShowEvent = pEvent;
    5906             LONG64 aEvWinId = 0;
    59075837            if (pShowEvent)
    59085838            {
    5909                 pShowEvent->COMGETTER(WinId)(&aEvWinId);
    5910                 if ((aEvWinId != 0) && (*aWinId == 0))
    5911                     *aWinId = aEvWinId;
     5839                LONG64 iEvWinId = 0;
     5840                pShowEvent->COMGETTER(WinId)(&iEvWinId);
     5841                if (iEvWinId != 0 && *aWinId == 0)
     5842                    *aWinId = iEvWinId;
    59125843            }
    59135844            else
    5914                 Assert(FALSE);
     5845                AssertFailed();
    59155846        }
    59165847    }
Note: See TracChangeset for help on using the changeset viewer.

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