VirtualBox

Changeset 46649 in vbox for trunk/include/VBox


Ignore:
Timestamp:
Jun 19, 2013 11:47:32 AM (11 years ago)
Author:
vboxsync
Message:

Forward ported r85941 and required build fixes (Main: Implemented new event queue to separate system's native event queue and our own. Also, XPCOM is not needed for handling our own events. On Windows this also fixes the system's queue quota limitation).

Location:
trunk
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/include/VBox/com/EventQueue.h

    r45125 r46649  
     1/* $Id$ */
    12/** @file
    2  * MS COM / XPCOM Abstraction Layer - Event and EventQueue class declaration.
     3 * Event queue class declaration.
    34 */
    45
    56/*
    6  * Copyright (C) 2006-2012 Oracle Corporation
     7 * Copyright (C) 2013 Oracle Corporation
    78 *
    89 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    2728#define ___VBox_com_EventQueue_h
    2829
    29 #ifndef VBOX_WITH_XPCOM
    30 # include <Windows.h>
    31 #else // VBOX_WITH_XPCOM
    32 # include <nsEventQueueUtils.h>
    33 #endif // VBOX_WITH_XPCOM
     30#include <list>
     31
     32#include <iprt/asm.h>
     33#include <iprt/critsect.h>
    3434
    3535#include <VBox/com/defs.h>
     
    5252public:
    5353
    54     Event() {}
    55     virtual ~Event() {};
     54    Event(void) :
     55        mRefCount(0) { }
     56    virtual ~Event(void) { AssertMsg(!mRefCount,
     57                                     ("Reference count of event=%p not 0 on destruction (is %RU32)\n",
     58                                      this, mRefCount)); }
     59public:
     60
     61    uint32_t AddRef(void) { return ASMAtomicIncU32(&mRefCount); }
     62    void     Release(void)
     63    {
     64        Assert(mRefCount);
     65        uint32_t cRefs = ASMAtomicDecU32(&mRefCount);
     66        if (!cRefs)
     67            delete this;
     68    }
    5669
    5770protected:
     
    6376     *  @return reserved, should be NULL.
    6477     */
    65     virtual void *handler() { return NULL; }
     78    virtual void *handler(void) { return NULL; }
    6679
    6780    friend class EventQueue;
     81
     82protected:
     83
     84    /** The event's reference count. */
     85    uint32_t mRefCount;
    6886};
     87
     88typedef std::list< Event* >                 EventQueueList;
     89typedef std::list< Event* >::iterator       EventQueueListIterator;
     90typedef std::list< Event* >::const_iterator EventQueueListIteratorConst;
    6991
    7092/**
    7193 *  Simple event queue.
    72  *
    73  *  When using XPCOM, this will map onto the default XPCOM queue for the thread.
    74  *  So, if a queue is created on the main thread, it automatically processes
    75  *  XPCOM/IPC events while waiting.
    76  *
    77  *  When using Windows, Darwin and OS/2, this will map onto the native thread
    78  *  queue/runloop.  So, windows messages and what not will be processed while
    79  *  waiting for events.
    80  *
    81  *  @note It is intentional that there is no way to retrieve arbitrary
    82  *  events and controlling their processing. There is no use case which
    83  *  warrants introducing the complexity of platform independent events.
    8494 */
    8595class EventQueue
     
    8797public:
    8898
    89     EventQueue();
    90     ~EventQueue(); /** @todo r=andy Why not virtual? */
     99    EventQueue(void);
     100    virtual ~EventQueue(void);
     101
     102public:
    91103
    92104    BOOL postEvent(Event *event);
    93105    int processEventQueue(RTMSINTERVAL cMsTimeout);
    94106    int interruptEventQueueProcessing();
    95     int getSelectFD();
    96     static int init();
    97     static int uninit();
    98     static EventQueue *getMainEventQueue();
    99 
    100 #ifdef VBOX_WITH_XPCOM
    101     already_AddRefed<nsIEventQueue> getIEventQueue()
    102     {
    103         return mEventQ.get();
    104     }
    105 #else
    106     static int dispatchMessageOnWindows(MSG const *pMsg, int rc);
    107 #endif
    108107
    109108private:
    110     static EventQueue *sMainQueue;
    111109
    112 #ifndef VBOX_WITH_XPCOM
    113 
    114     /** The thread which the queue belongs to. */
    115     DWORD mThreadId;
    116     /** Duplicated thread handle for MsgWaitForMultipleObjects. */
    117     HANDLE mhThread;
    118 
    119 #else // VBOX_WITH_XPCOM
    120 
    121     /** Whether it was created (and thus needs destroying) or if a queue already
    122      *  associated with the thread was used. */
    123     bool mEQCreated;
    124 
    125     /** Whether event processing should be interrupted. */
    126     bool mInterrupted;
    127 
    128     nsCOMPtr <nsIEventQueue> mEventQ;
    129     nsCOMPtr <nsIEventQueueService> mEventQService;
    130 
    131     static void *PR_CALLBACK plEventHandler(PLEvent *self);
    132     static void PR_CALLBACK plEventDestructor(PLEvent *self);
    133 
    134 #endif // VBOX_WITH_XPCOM
     110    /** Critical section for serializing access to this
     111     *  event queue. */
     112    RTCRITSECT         mCritSect;
     113    /** Event semaphore for getting notified on new
     114     *  events being handled. */
     115    RTSEMEVENT         mSemEvent;
     116    /** The actual event queue, implemented as a list. */
     117    EventQueueList     mEvents;
     118    /** Shutdown indicator. */
     119    bool               mShutdown;
    135120};
    136121
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