VirtualBox

Changeset 30477 in vbox


Ignore:
Timestamp:
Jun 28, 2010 4:56:57 PM (15 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
63160
Message:

Main: finer events locks

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

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/EventImpl.cpp

    r30476 r30477  
    239239    HRESULT process(IEvent* aEvent, BOOL aWaitable, PendingEventsMap::iterator& pit, AutoLockBase& alock);
    240240    HRESULT enqueue(IEvent* aEvent);
    241     HRESULT dequeue(IEvent* *aEvent, LONG aTimeout);
     241    HRESULT dequeue(IEvent* *aEvent, LONG aTimeout, AutoLockBase& aAlock);
    242242    HRESULT eventProcessed(IEvent * aEvent, PendingEventsMap::iterator& pit);
    243243    void addRef()
     
    397397}
    398398
    399 HRESULT ListenerRecord::process(IEvent* aEvent, BOOL aWaitable, PendingEventsMap::iterator& pit, AutoLockBase& alock)
     399HRESULT ListenerRecord::process(IEvent*                     aEvent,
     400                                BOOL                        aWaitable,
     401                                PendingEventsMap::iterator& pit,
     402                                AutoLockBase&               aAlock)
    400403{
    401404    if (mActive)
     
    407410        if (mListener)
    408411        {
    409             alock.release();
     412            aAlock.release();
    410413            rc =  mListener->HandleEvent(aEvent);
    411             alock.acquire();
     414            aAlock.acquire();
    412415        }
    413416        if (aWaitable)
     
    434437}
    435438
    436 HRESULT ListenerRecord::dequeue (IEvent* *aEvent, LONG aTimeout)
     439HRESULT ListenerRecord::dequeue (IEvent*       *aEvent,
     440                                 LONG          aTimeout,
     441                                 AutoLockBase& aAlock)
    437442{
    438443    AssertMsg(!mActive, ("must be passive\n"));
     
    441446    if (mQueue.empty())
    442447    {
    443         ::RTCritSectLeave(&mcsQLock);
     448        // retain listener record
     449        ListenerRecordHolder holder(this);
     450        ::RTCritSectLeave(&mcsQLock);       
    444451        // Speed up common case
    445452        if (aTimeout == 0)
     
    448455            return S_OK;
    449456        }
     457        // release lock while waiting, listener will not go away due to above holder
     458        aAlock.release();
    450459        ::RTSemEventWait(mQEvent, aTimeout);
     460        // reacquire lock
     461        aAlock.acquire();
    451462        ::RTCritSectEnter(&mcsQLock);
    452463    }
     
    510521{
    511522    m->mListeners.clear();
    512     // m->mEvMap shall be cleared at this point too by destructors
     523    // m->mEvMap shall be cleared at this point too by destructors, assert?
    513524}
    514525
     
    644655     * here, to make this wait preemptible, thus both take read lock (write
    645656     * lock in FireEvent() would do too, and probably is a bit stricter),
    646      * but will interfere with .
     657     * but will be unable to .
    647658     */
    648659    AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
     
    652663
    653664    if (it != m->mListeners.end())
    654         rc = it->second.obj()->dequeue(aEvent, aTimeout);
     665        rc = it->second.obj()->dequeue(aEvent, aTimeout, alock);
    655666    else
    656667        rc = setError(VBOX_E_OBJECT_NOT_FOUND,
  • trunk/src/VBox/Main/idl/autogen.xsl

    r30476 r30477  
    401401<xsl:template name="genCommonEventCode">
    402402  <xsl:text><![CDATA[
    403 void VBoxEventDesc::getEvent(IEvent ** aEvent)
    404 {
    405     mEvent.queryInterfaceTo(aEvent);
    406 }
    407403HRESULT VBoxEventDesc::init(IEventSource* source, VBoxEventType_T aType, ...)
    408404{
  • trunk/src/VBox/Main/include/EventImpl.h

    r30381 r30477  
    132132 {}
    133133
     134 /**
     135  * This function to be used with some care, as arguments order must match attribute declaration order
     136  * event class and its superclasses up to IEvent. If unsure, consult implementation in
     137  * generated VBoxEvents.cpp.
     138  */
    134139 HRESULT init(IEventSource* aSource, VBoxEventType_T aType, ...);
    135  void getEvent(IEvent ** aEvent);
     140
     141 void getEvent(IEvent ** aEvent)
     142 {
     143     mEvent.queryInterfaceTo(aEvent);
     144 }
    136145
    137146private:
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