VirtualBox

Changeset 43943 in vbox for trunk/src/VBox/Main


Ignore:
Timestamp:
Nov 22, 2012 5:00:42 PM (12 years ago)
Author:
vboxsync
Message:

Main/glue: bad_alloc handling for event queue, todos.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/glue/EventQueue.cpp

    r41015 r43943  
    66
    77/*
    8  * Copyright (C) 2006-2010 Oracle Corporation
     8 * Copyright (C) 2006-2012 Oracle Corporation
    99 *
    1010 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    118118EventQueue::EventQueue()
    119119{
     120    /** @todo r=andy This constructor does way too much. In case of failure
     121     *               it's up to the caller to verify all sorts of stuff. Why
     122     *               isn't this done in init() and moving the main queue
     123     *               creation/deletion stuff to a dedicated function? */
    120124#ifndef VBOX_WITH_XPCOM
    121125
     
    212216    Assert(sMainQueue == NULL);
    213217    Assert(RTThreadIsMain(RTThreadSelf()));
    214     sMainQueue = new EventQueue();
     218
     219    try
     220    {
     221        sMainQueue = new EventQueue();
    215222
    216223#ifdef VBOX_WITH_XPCOM
    217     /* Check that it actually is the main event queue, i.e. that
    218        we're called on the right thread. */
    219     nsCOMPtr<nsIEventQueue> q;
    220     nsresult rv = NS_GetMainEventQ(getter_AddRefs(q));
    221     Assert(NS_SUCCEEDED(rv));
    222     Assert(q == sMainQueue->mEventQ);
    223 
    224     /* Check that it's a native queue. */
    225     PRBool fIsNative = PR_FALSE;
    226     rv = sMainQueue->mEventQ->IsQueueNative(&fIsNative);
    227     Assert(NS_SUCCEEDED(rv) && fIsNative);
    228 #endif // VBOX_WITH_XPCOM
     224        /* Check that it actually is the main event queue, i.e. that
     225           we're called on the right thread. */
     226        nsCOMPtr<nsIEventQueue> q;
     227        nsresult rv = NS_GetMainEventQ(getter_AddRefs(q));
     228        Assert(NS_SUCCEEDED(rv));
     229        Assert(q == sMainQueue->mEventQ);
     230
     231        /* Check that it's a native queue. */
     232        PRBool fIsNative = PR_FALSE;
     233        rv = sMainQueue->mEventQ->IsQueueNative(&fIsNative);
     234        Assert(NS_SUCCEEDED(rv) && fIsNative);
     235#endif // VBOX_WITH_XPCOM
     236    }
     237    catch (bad_alloc &ba)
     238    {
     239        return VERR_NO_MEMORY;
     240    }
    229241
    230242    return VINF_SUCCESS;
     
    589601 *  @return         TRUE if successful and false otherwise
    590602 */
    591 BOOL EventQueue::postEvent(Event *event)
     603BOOL EventQueue::postEvent(Event *pEvent)
    592604{
    593605#ifndef VBOX_WITH_XPCOM
    594606    /* Note! The event == NULL case is duplicated in vboxapi/PlatformMSCOM::interruptWaitEvents(). */
    595     return PostThreadMessage(mThreadId, WM_USER, (WPARAM)event, EVENTQUEUE_WIN_LPARAM_MAGIC);
     607    return PostThreadMessage(mThreadId, WM_USER, (WPARAM)pEvent, EVENTQUEUE_WIN_LPARAM_MAGIC);
    596608
    597609#else // VBOX_WITH_XPCOM
     
    600612        return FALSE;
    601613
    602     MyPLEvent *ev = new MyPLEvent(event);
    603     mEventQ->InitEvent(ev, this, com::EventQueue::plEventHandler,
    604                        com::EventQueue::plEventDestructor);
    605     HRESULT rc = mEventQ->PostEvent(ev);
    606     return NS_SUCCEEDED(rc);
    607 
     614    try
     615    {
     616        MyPLEvent *pMyEvent = new MyPLEvent(pEvent);
     617        mEventQ->InitEvent(pMyEvent, this, com::EventQueue::plEventHandler,
     618                           com::EventQueue::plEventDestructor);
     619        HRESULT rc = mEventQ->PostEvent(pMyEvent);
     620        return NS_SUCCEEDED(rc);
     621    }
     622    catch (bad_alloc &ba)
     623    {
     624        AssertMsgFailed(("Out of memory while allocating memory for event=%p: %s\n",
     625                         pEvent, ba.what()));
     626    }
     627
     628    return FALSE;
    608629#endif // VBOX_WITH_XPCOM
    609630}
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