VirtualBox

Changeset 77079 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Jan 31, 2019 4:05:05 PM (6 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
128532
Message:

Guest Control/Main: Fixed GuestWaitEvent initialization by now having dedicated Init() functions and use proper memory / exception handling in GuestBase::registerWaitEventEx().

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

Legend:

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

    r76958 r77079  
    10661066public:
    10671067
    1068     GuestWaitEvent(uint32_t uCID);
    1069     GuestWaitEvent(uint32_t uCID, const GuestEventTypes &lstEvents);
     1068    GuestWaitEvent(void);
    10701069    virtual ~GuestWaitEvent(void);
    10711070
    10721071public:
    10731072
     1073    int                              Init(uint32_t uCID);
     1074    int                              Init(uint32_t uCID, const GuestEventTypes &lstEvents);
    10741075    int                              Cancel(void);
    10751076    const ComPtr<IEvent>             Event(void) { return mEvent; }
     
    10791080    const GuestEventTypes           &Types(void) { return mEventTypes; }
    10801081    size_t                           TypeCount(void) { return mEventTypes.size(); }
    1081 
    1082 protected:
    1083 
    1084     int                              Init(uint32_t uCID);
    10851082
    10861083protected:
  • trunk/src/VBox/Main/src-client/GuestCtrlPrivate.cpp

    r76958 r77079  
    939939    AssertRCReturn(rc, rc);
    940940
    941 #if 1 /** @todo r=bird: Incorrect exception and memory handling, no strategy for dealing with duplicate IDs: */
    942     rc = RTCritSectEnter(&mWaitEventCritSect);
    943     if (RT_SUCCESS(rc))
    944     {
    945         try
    946         {
    947             GuestWaitEvent *pEvent = new GuestWaitEvent(idContext, lstEvents);
    948             AssertPtr(pEvent);
    949 
    950             LogFlowThisFunc(("New event=%p, CID=%RU32\n", pEvent, idContext));
    951 
    952             /* Insert event into matching event group. This is for faster per-group
    953              * lookup of all events later. */
    954             for (GuestEventTypes::const_iterator itEvents = lstEvents.begin();
    955                  itEvents != lstEvents.end(); ++itEvents)
    956             {
    957                 /* Check if the event group already has an event with the same
    958                  * context ID in it (collision). */
    959                 GuestWaitEvents eventGroup = mWaitEventGroups[(*itEvents)]; /** @todo r=bird: Why copy it? */
    960                 if (eventGroup.find(idContext) == eventGroup.end())
    961                 {
    962                     /* No, insert. */
    963                     mWaitEventGroups[(*itEvents)].insert(std::pair<uint32_t, GuestWaitEvent *>(idContext, pEvent));
    964                 }
    965                 else
    966                 {
    967                     rc = VERR_ALREADY_EXISTS;
    968                     break;
    969                 }
    970             }
    971 
    972             if (RT_SUCCESS(rc))
    973             {
    974                 /* Register event in regular event list. */
    975                 if (mWaitEvents.find(idContext) == mWaitEvents.end())
    976                 {
    977                     mWaitEvents[idContext] = pEvent;
    978                 }
    979                 else
    980                     rc  = VERR_ALREADY_EXISTS;
    981             }
    982 
    983             if (RT_SUCCESS(rc))
    984                 *ppEvent = pEvent;
    985         }
    986         catch(std::bad_alloc &)
    987         {
    988             rc = VERR_NO_MEMORY;
    989         }
    990 
    991         int rc2 = RTCritSectLeave(&mWaitEventCritSect);
    992         if (RT_SUCCESS(rc))
    993             rc = rc2;
    994     }
    995     return rc;
    996 
    997 #else /** @todo r=bird: Version with proper exception handling, no leaks and limited duplicate CID handling:  */
    998 
    999     GuestWaitEvent *pEvent = new GuestWaitEvent(idContext, lstEvents);
    1000     AssertReturn(pEvent, VERR_NO_MEMORY);
     941    GuestWaitEvent *pEvent = new GuestWaitEvent();
     942    AssertPtrReturn(pEvent, VERR_NO_MEMORY);
     943
     944    rc = pEvent->Init(idContext, lstEvents);
     945    AssertRCReturn(rc, rc);
     946
    1001947    LogFlowThisFunc(("New event=%p, CID=%RU32\n", pEvent, idContext));
    1002948
     
    10551001            {
    10561002                Assert(cInserts > 0);
    1057                 NOREF(cInserts);
     1003                RT_NOREF(cInserts);
    10581004
    10591005                /*
     
    10801026    delete pEvent;
    10811027    return rc;
    1082 #endif
    10831028}
    10841029
     
    15281473}
    15291474
    1530 GuestWaitEvent::GuestWaitEvent(uint32_t uCID,
    1531                                const GuestEventTypes &lstEvents)
    1532 {
    1533     int rc2 = Init(uCID);
    1534     AssertRC(rc2); /** @todo Throw exception here. */ /** @todo r=bird: add+use Init() instead. Will cause weird VERR_CANCELLED errors in GuestBase::signalWaitEvent. */
    1535 
    1536     mEventTypes = lstEvents;
    1537 }
    1538 
    1539 GuestWaitEvent::GuestWaitEvent(uint32_t uCID)
    1540 {
    1541     int rc2 = Init(uCID);
    1542     AssertRC(rc2); /** @todo Throw exception here. */ /** @todo r=bird: add+use Init() instead. Will cause weird VERR_CANCELLED errors in GuestBase::signalWaitEvent. */
     1475GuestWaitEvent::GuestWaitEvent(void)
     1476{
    15431477}
    15441478
     
    15621496}
    15631497
     1498/**
     1499 * Initializes a wait event with a given context ID (CID).
     1500 *
     1501 * @returns IPRT status code.
     1502 * @param   uCID                Context ID to initialize wait event with.
     1503 */
    15641504int GuestWaitEvent::Init(uint32_t uCID)
    15651505{
    15661506    return GuestWaitEventBase::Init(uCID);
     1507}
     1508
     1509/**
     1510 * Initializes a wait event with a given context ID (CID) and a list of event types to wait for.
     1511 *
     1512 * @returns IPRT status code.
     1513 * @param   uCID                Context ID to initialize wait event with.
     1514 * @param   lstEvent            List of event types to wait for this wait event to get signalled.
     1515 */
     1516int GuestWaitEvent::Init(uint32_t uCID, const GuestEventTypes &lstEvents)
     1517{
     1518    int rc = GuestWaitEventBase::Init(uCID);
     1519    if (RT_SUCCESS(rc))
     1520    {
     1521        mEventTypes = lstEvents;
     1522    }
     1523
     1524    return rc;
    15671525}
    15681526
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