VirtualBox

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


Ignore:
Timestamp:
Jan 18, 2017 1:14:05 PM (8 years ago)
Author:
vboxsync
Message:

xpcom/server.cpp: use a guaranteed safe sequence (never decreasing the refcount speculatively) for figuring out if some API client is racing against the 5 seconds idle timeout

File:
1 edited

Legend:

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

    r65247 r65361  
    55
    66/*
    7  * Copyright (C) 2004-2016 Oracle Corporation
     7 * Copyright (C) 2004-2017 Oracle Corporation
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    234234            RTCritSectEnter(&sLock);
    235235
    236             nsrefcnt count = 0;
     236            nsrefcnt count = 1;
    237237
    238238            /* sInstance is NULL here if it was deleted immediately after
     
    240240            if (sInstance != NULL)
    241241            {
    242                 /* Release the guard reference added in GetInstance() */
     242                /* Safe way to get current refcount is by first increasing and
     243                 * then decreasing. Keep in mind that the Release is overloaded
     244                 * (see VirtualBoxClassFactory::Release) and will start the
     245                 * timer again if the returned count is 1. It won't do harm,
     246                 * but also serves no purpose, so stop it ASAP. */
     247                sInstance->AddRef();
    243248                count = sInstance->Release();
    244             }
    245 
    246             if (count == 0)
     249                if (count == 1)
     250                {
     251                    RTTimerLRStop(sTimer);
     252                    /* Release the guard reference added in GetInstance() */
     253                    sInstance->Release();
     254                }
     255            }
     256
     257            if (count == 1)
    247258            {
    248259                if (gAutoShutdown || m_fSignal)
     
    262273                 * but before it started to process it. */
    263274                LogRel(("Destruction is canceled (refcnt=%d).\n", count));
    264                 /* Important: restore previous refcount, we decreased it
    265                  * above based on the assumption that the object is unused! */
    266                 sInstance->AddRef();
    267275            }
    268276
     
    408416            Assert(count > 1);
    409417
    410             if (count == 2)
     418            if (count >= 2)
    411419            {
    412420                LogFlowFunc(("Another client has requested a reference to VirtualBox, canceling destruction...\n"));
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