VirtualBox

Changeset 10390 in vbox for trunk


Ignore:
Timestamp:
Jul 8, 2008 9:29:43 PM (16 years ago)
Author:
vboxsync
Message:

We need to do reference counting becuase the ring-0 IPRT may be shared among several kexts depending on the way we link it and which OS it is.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/r0drv/initterm-r0drv.cpp

    r9602 r10390  
    3434*******************************************************************************/
    3535#include <iprt/initterm.h>
     36#include <iprt/asm.h>
    3637#include <iprt/assert.h>
    3738#include <iprt/err.h>
     
    4243#include "internal/initterm.h"
    4344#include "internal/thread.h"
     45
     46
     47/*******************************************************************************
     48*   Global Variables                                                           *
     49*******************************************************************************/
     50/** Count of current IPRT users.
     51 * In ring-0 several drivers / kmods / kexts / wossnames may share the
     52 * same runtime code. So, we need to keep count in order not to terminate
     53 * it prematurely. */
     54static int32_t volatile g_crtR0Users = 0;
    4455
    4556
     
    5465    int rc;
    5566    Assert(fReserved == 0);
     67
     68    /*
     69     * The first user initializes it.
     70     * We rely on the module loader to ensure that there are no
     71     * initialization races should two modules share the IPRT.
     72     */
     73    if (ASMAtomicIncS32(&g_crtR0Users) != 1)
     74        return VINF_SUCCESS;
     75
    5676    rc = rtR0InitNative();
    5777    if (RT_SUCCESS(rc))
     
    80100RTR0DECL(void) RTR0Term(void)
    81101{
     102    /*
     103     * Last user does the cleanup.
     104     */
     105    int32_t cNewUsers = ASMAtomicDecS32(&g_crtR0Users);
     106    Assert(cNewUsers >= 0);
     107    if (cNewUsers != 0)
     108        return;
     109
    82110#if !defined(RT_OS_LINUX) && !defined(RT_OS_WINDOWS)
    83111    rtThreadTerm();
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