VirtualBox

Changeset 28361 in vbox


Ignore:
Timestamp:
Apr 15, 2010 1:46:02 PM (15 years ago)
Author:
vboxsync
Message:

Runtime/runtime-loader: use RTOnce again

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/iprt/runtime-loader.h

    r28357 r28361  
    6464 * probably be preferable. */
    6565
    66 #include <iprt/asm.h>
    67 #include <iprt/assert.h>
    68 #include <iprt/cdefs.h>
    69 #include <iprt/err.h>
    7066#include <iprt/ldr.h>
    7167#include <iprt/log.h>
    72 #include <iprt/thread.h>
    73 #include <iprt/types.h>
     68#include <iprt/once.h>
    7469
    7570#ifdef RT_RUNTIME_LOADER_GENERATE_BODY_STUBS
     
    9994# undef RT_PROXY_STUB
    10095
    101 enum RT_RTLDR_LOAD_STATE
     96/* The function which does the actual work for RT_RUNTIME_LOADER_FUNCTION,
     97 * serialised for thread safety. */
     98static int rtldrLoadOnce(void *, void *)
    10299{
    103     UNLOADED = 0,
    104     LOADING,
    105     DONE
    106 };
     100    RTLDRMOD hLib;
    107101
    108 static uint32_t rtldrState = UNLOADED;
    109 static uint32_t rtldrRC = VERR_WRONG_ORDER;
     102    LogFlowFunc(("\n"));
     103    int rc = RTLdrLoad(RT_RUNTIME_LOADER_LIB_NAME, &hLib);
     104    for (unsigned i = 0; RT_SUCCESS(rc) && SharedFuncs[i].name != NULL; ++i)
     105        rc = RTLdrGetSymbol(hLib, SharedFuncs[i].name, (void**)SharedFuncs[i].fn);
     106    LogFlowFunc(("rc = %Rrc\n", rc));
     107    return rc;
     108}
    110109
    111110/** Load the shared library RT_RUNTIME_LOADER_LIB_NAME and resolve the symbols
     
    115114RTR3DECL(int) RT_RUNTIME_LOADER_FUNCTION(void)
    116115{
    117     int rc;
     116    static RTONCE sOnce = RTONCE_INITIALIZER;
    118117
    119118    LogFlowFunc(("\n"));
    120     if (ASMAtomicCmpXchgU32(&rtldrState, LOADING, UNLOADED))
    121     {
    122         RTLDRMOD hLib;
    123 
    124         rc = RTLdrLoad(RT_RUNTIME_LOADER_LIB_NAME, &hLib);
    125         for (unsigned i = 0; RT_SUCCESS(rc) && SharedFuncs[i].name != NULL; ++i)
    126             rc = RTLdrGetSymbol(hLib, SharedFuncs[i].name, (void**)SharedFuncs[i].fn);
    127         rtldrRC = rc;
    128         rtldrState = DONE;
    129     }
    130     else
    131     {
    132         while(rtldrState == LOADING)
    133             RTThreadYield();
    134         rc = rtldrRC;
    135     }
    136     Assert(rtldrState == DONE);
     119    int rc = RTOnce (&sOnce, rtldrLoadOnce, NULL, NULL);
    137120    LogFlowFunc(("rc = %Rrc\n", rc));
    138121    return rc;
    139122}
     123
    140124#elif defined(RT_RUNTIME_LOADER_GENERATE_HEADER)
    141125# ifdef RT_RUNTIME_LOADER_GENERATE_DECLS
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