VirtualBox

Changeset 11597 in vbox


Ignore:
Timestamp:
Aug 23, 2008 11:33:52 PM (16 years ago)
Author:
vboxsync
Message:

iprt: RTR3Init is called more than once (IPC and now nspr init), so do proper reference counting.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/r3/init.cpp

    r8245 r11597  
    6464*   Global Variables                                                           *
    6565*******************************************************************************/
     66/** The number of calls to RTR3Init. */
     67static int32_t volatile g_cUsers = 0;
     68/** Whether we're currently initializing the IPRT. */
     69static bool volatile    g_fInitializing = false;
     70
    6671/** Program path.
    6772 * The size is hardcoded, so we'll have to check for overflow when setting it
     
    115120    /* no entry log flow, because prefixes and thread may freak out. */
    116121
     122    /*
     123     * Do reference counting, only initialize the first time around.
     124     *
     125     * We are ASSUMING that nobody will be able to race RTR3Init calls when the
     126     * first one, the real init, is running (second assertion).
     127     */
     128    int32_t cUsers = ASMAtomicIncS32(&g_cUsers);
     129    if (cUsers != 1)
     130    {
     131        AssertMsg(cUsers > 1, ("%d\n", cUsers));
     132        Assert(!g_fInitializing);
     133#if !defined(IN_GUEST) && !defined(RT_NO_GIP)
     134        if (fInitSUPLib)
     135            SUPInit(NULL, cbReserve);
     136#endif
     137    }
     138    ASMAtomicWriteBool(&g_fInitializing, true);
     139
    117140#if !defined(IN_GUEST) && !defined(RT_NO_GIP)
    118141# ifdef VBOX
     
    142165    {
    143166        AssertMsgFailed(("Failed to get executable directory path, rc=%d!\n", rc));
     167        ASMAtomicWriteBool(&g_fInitializing, false);
     168        ASMAtomicDecS32(&g_cUsers);
    144169        return rc;
    145170    }
     
    187212    {
    188213        AssertMsgFailed(("Failed to get executable directory path, rc=%d!\n", rc));
     214        ASMAtomicWriteBool(&g_fInitializing, false);
     215        ASMAtomicDecS32(&g_cUsers);
    189216        return rc;
    190217    }
     
    204231
    205232    LogFlow(("RTR3Init: returns VINF_SUCCESS\n"));
     233    ASMAtomicWriteBool(&g_fInitializing, false);
    206234    return VINF_SUCCESS;
    207235}
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