VirtualBox

Changeset 89422 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Jun 1, 2021 10:13:34 AM (4 years ago)
Author:
vboxsync
Message:

DrvHostAudioPulseAudioStubs: Use RTOnce to make the init thread-safe and all. bugref:9890

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Devices/Audio/DrvHostAudioPulseAudioStubs.cpp

    r88478 r89422  
    2424#include <iprt/ldr.h>
    2525#include <VBox/log.h>
     26#include <iprt/once.h>
    2627#include <iprt/err.h>
    2728
     
    322323#undef FUNC_ENTRY
    323324
    324 /**
    325  * Try to dynamically load the PulseAudio libraries.  This function is not
    326  * thread-safe, and should be called before attempting to use any of the
    327  * PulseAudio functions.
    328  *
    329  * @returns iprt status code
    330  */
    331 int audioLoadPulseLib(void)
     325/** Init once.   */
     326static RTONCE g_PulseAudioInitOnce = RTONCE_INITIALIZER;
     327
     328/** @callback_method_impl{FNRTONCE} */
     329static DECLCALLBACK(int32_t) drvHostAudioPusleInitOnce(void *pvUser)
    332330{
    333     static volatile int g_rc = VERR_IPE_UNINITIALIZED_STATUS;
    334     RTLDRMOD hLib;
    335     int rc;
    336 
     331    RT_NOREF(pvUser);
    337332    LogFlowFunc(("\n"));
    338333
    339     /* If this is not VERR_IPE_UNINITIALIZED_STATUS then the function has
    340        obviously been called twice, which is likely to be a bug. */
    341     rc = g_rc;
    342     AssertMsgReturn(rc == VERR_IPE_UNINITIALIZED_STATUS, ("g_rc=%Rrc\n", rc), rc);
    343 
    344     rc = RTLdrLoadSystemEx(VBOX_PULSE_LIB, RTLDRLOAD_FLAGS_NO_UNLOAD, &hLib);
     334    RTLDRMOD hLib = NIL_RTLDRMOD;
     335    int rc = RTLdrLoadSystemEx(VBOX_PULSE_LIB, RTLDRLOAD_FLAGS_NO_UNLOAD, &hLib);
    345336    if (RT_SUCCESS(rc))
    346337    {
    347         unsigned i;
    348         for (i = 0; i < RT_ELEMENTS(g_aImportedFunctions); i++)
     338        for (unsigned i = 0; i < RT_ELEMENTS(g_aImportedFunctions); i++)
    349339        {
    350340            rc = RTLdrGetSymbol(hLib, g_aImportedFunctions[i].pszName, (void **)g_aImportedFunctions[i].pfn);
     
    358348    else
    359349        LogRelFunc(("Failed to load library %s: %Rrc\n", VBOX_PULSE_LIB, rc));
    360     g_rc = rc;
    361350    return rc;
    362351}
    363352
     353/**
     354 * Try to dynamically load the PulseAudio libraries.
     355 *
     356 * @returns VBox status code
     357 */
     358int audioLoadPulseLib(void)
     359{
     360    LogFlowFunc(("\n"));
     361    return RTOnce(&g_PulseAudioInitOnce, drvHostAudioPusleInitOnce, NULL);
     362}
     363
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