VirtualBox

Ignore:
Timestamp:
Apr 27, 2015 4:38:40 PM (10 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
99805
Message:

Main/src-server/xpcom/server.cpp: make the event queue handling and the critsect destruction a bit more robust

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/src-server/xpcom/server.cpp

    r51498 r55458  
    132132static uint32_t gShutdownDelayMs = 5000;
    133133
    134 static nsIEventQueue  *gEventQ          = nsnull;
     134static nsCOMPtr<nsIEventQueue> gEventQ  = nsnull;
    135135static PRBool volatile gKeepRunning     = PR_TRUE;
    136136static PRBool volatile gAllowSigUsrQuit = PR_TRUE;
     
    232232
    233233            PRBool onMainThread = PR_TRUE;
    234             if (gEventQ)
    235                 gEventQ->IsOnCurrentThread(&onMainThread);
     234            nsCOMPtr<nsIEventQueue> q(gEventQ);
     235            if (q)
     236            {
     237                q->IsOnCurrentThread(&onMainThread);
     238                q = nsnull;
     239            }
    236240
    237241            PRBool timerStarted = PR_FALSE;
     
    289293                     */
    290294
    291                     Assert(gEventQ == NULL);
     295                    Assert(!gEventQ);
    292296                }
    293297            }
     
    356360         * and this method was so lucky that it got a chance to run before
    357361         * the timer was killed. */
    358         AssertReturnVoid(gEventQ);
     362        nsCOMPtr<nsIEventQueue> q(gEventQ);
     363        AssertReturnVoid(q);
    359364
    360365        /* post a quit event to the main queue */
    361366        MaybeQuitEvent *ev = new MaybeQuitEvent();
    362         nsresult rv = ev->postTo(gEventQ);
     367        nsresult rv = ev->postTo(q);
    363368        NOREF(rv);
    364369
     
    392397        RTTimerLRDestroy(sTimer);
    393398        sTimer = NULL;
    394 
    395         RTCritSectDelete(&sLock);
    396399
    397400        if (sInstance != NULL)
     
    404407            sInstance->Release();
    405408        }
     409
     410        /* Destroy lock after releasing the VirtualBox instance, otherwise
     411         * there are races with cleanup. */
     412        RTCritSectDelete(&sLock);
    406413
    407414        return NS_OK;
     
    594601static void signal_handler(int sig)
    595602{
    596     if (gEventQ && gKeepRunning)
     603    nsCOMPtr<nsIEventQueue> q(gEventQ);
     604    if (q && gKeepRunning)
    597605    {
    598606        if (sig == SIGUSR1)
     
    601609            {
    602610                VirtualBoxClassFactory::MaybeQuitEvent *ev = new VirtualBoxClassFactory::MaybeQuitEvent();
    603                 ev->postTo(gEventQ);
     611                ev->postTo(q);
    604612            }
    605613            /* else do nothing */
     
    609617            /* post a force quit event to the queue */
    610618            ForceQuitEvent *ev = new ForceQuitEvent();
    611             ev->postTo(gEventQ);
     619            ev->postTo(q);
    612620        }
    613621    }
     
    863871         * gets created upon XPCOM startup, so it will use the main (this)
    864872         * thread's event queue to receive IPC events) */
    865         rc = NS_GetMainEventQ(&gEventQ);
     873        rc = NS_GetMainEventQ(getter_AddRefs(gEventQ));
    866874        if (NS_FAILED(rc))
    867875        {
     
    9921000
    9931001    NS_IF_RELEASE(gIpcServ);
    994     NS_IF_RELEASE(gEventQ);
     1002    gEventQ = nsnull;
    9951003
    9961004    /* no nsCOMPtrs are allowed to be alive when you call com::Shutdown(). */
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