VirtualBox

Changeset 107720 in vbox


Ignore:
Timestamp:
Jan 13, 2025 6:52:47 PM (2 months ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
166820
Message:

Audio/DrvAudio.cpp: Added some more sanity checks. bugref:10801

File:
1 edited

Legend:

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

    r106061 r107720  
    14901490     * Release our stream reference.
    14911491     */
    1492     uint32_t cRefs = drvAudioStreamReleaseInternal(pThis, pStreamEx, true /*fMayDestroy*/);
     1492    uint32_t const cRefs = drvAudioStreamReleaseInternal(pThis, pStreamEx, true /*fMayDestroy*/);
    14931493    LogFlowFunc(("returns (fDestroyed=%d, cRefs=%u)\n", fDestroyed, cRefs)); RT_NOREF(cRefs);
    14941494}
     
    21202120 * @param   pStreamEx       The stream to reference.
    21212121 * @param   fMayDestroy     Whether the caller is allowed to implicitly destroy
    2122  *                          the stream or not.
     2122 *                          the stream or not.  The reference count must _not_
     2123 *                          reach zero if this is false!
    21232124 */
    21242125static uint32_t drvAudioStreamReleaseInternal(PDRVAUDIO pThis, PDRVAUDIOSTREAM pStreamEx, bool fMayDestroy)
     
    21562157
    21572158            drvAudioStreamFree(pStreamEx);
     2159            pStreamEx = NULL;
    21582160        }
    21592161        else
     
    21692171    }
    21702172
    2171     Log12Func(("returns %u (%s)\n", cRefs, cRefs > 0 ? pStreamEx->Core.Cfg.szName : "destroyed"));
     2173    Log12Func(("returns %u (%s)\n", cRefs, cRefs > 0 ? pStreamEx->Core.Cfg.szName : "destroyed")); /* Not 101% safe, but it's logging. */
    21722174    return cRefs;
    21732175}
     
    22622264                    LogFlowFunc(("Successfully cancelled pending pfnStreamInitAsync call (hReqInitAsync=%p).\n",
    22632265                                 pStreamEx->hReqInitAsync));
    2264                     drvAudioStreamReleaseInternal(pThis, pStreamEx, true /*fMayDestroy*/);
     2266                    uint32_t const cRefs = drvAudioStreamReleaseInternal(pThis, pStreamEx, true /*fMayDestroy*/);
     2267                    AssertStmt(cRefs > 0, pStreamEx = NULL);
    22652268                }
    22662269                else
     
    22742277                RTCritSectLeave(&pStreamEx->Core.CritSect);
    22752278
    2276             /*
    2277              * Now, if the backend requests asynchronous disabling and destruction
    2278              * push the disabling and destroying over to a worker thread.
    2279              *
    2280              * This is a general offloading feature that all backends should make use of,
    2281              * however it's rather precarious on macs where stopping an already draining
    2282              * stream may take 8-10ms which naturally isn't something we should be doing
    2283              * on an EMT.
    2284              */
    2285             if (!(pThis->BackendCfg.fFlags & PDMAUDIOBACKEND_F_ASYNC_STREAM_DESTROY))
    2286                 drvAudioStreamDestroyAsync(pThis, pStreamEx, fImmediate);
    2287             else
     2279            if (RT_LIKELY(pStreamEx != NULL)) /* paranoia^2 */
    22882280            {
    2289                 int rc2 = RTReqPoolCallEx(pThis->hReqPool, 0 /*cMillies*/, NULL /*phReq*/,
    2290                                           RTREQFLAGS_VOID | RTREQFLAGS_NO_WAIT,
    2291                                           (PFNRT)drvAudioStreamDestroyAsync, 3, pThis, pStreamEx, fImmediate);
    2292                 LogFlowFunc(("hReqInitAsync=%p rc2=%Rrc\n", pStreamEx->hReqInitAsync, rc2));
    2293                 AssertRCStmt(rc2, drvAudioStreamDestroyAsync(pThis, pStreamEx, fImmediate));
     2281                /*
     2282                 * Now, if the backend requests asynchronous disabling and destruction
     2283                 * push the disabling and destroying over to a worker thread.
     2284                 *
     2285                 * This is a general offloading feature that all backends should make use of,
     2286                 * however it's rather precarious on macs where stopping an already draining
     2287                 * stream may take 8-10ms which naturally isn't something we should be doing
     2288                 * on an EMT.
     2289                 */
     2290                if (!(pThis->BackendCfg.fFlags & PDMAUDIOBACKEND_F_ASYNC_STREAM_DESTROY))
     2291                    drvAudioStreamDestroyAsync(pThis, pStreamEx, fImmediate);
     2292                else
     2293                {
     2294                    int rc2 = RTReqPoolCallEx(pThis->hReqPool, 0 /*cMillies*/, NULL /*phReq*/,
     2295                                              RTREQFLAGS_VOID | RTREQFLAGS_NO_WAIT,
     2296                                              (PFNRT)drvAudioStreamDestroyAsync, 3, pThis, pStreamEx, fImmediate);
     2297                    LogFlowFunc(("hReqInitAsync=%p rc2=%Rrc\n", pStreamEx->hReqInitAsync, rc2));
     2298                    AssertRCStmt(rc2, drvAudioStreamDestroyAsync(pThis, pStreamEx, fImmediate));
     2299                }
    22942300            }
    22952301        }
     
    39503956    pIHostDrvAudio->pfnDoOnWorkerThread(pIHostDrvAudio, pStreamEx->pBackend, uUser, pvUser);
    39513957
    3952     drvAudioStreamReleaseInternal(pThis, pStreamEx, true /*fMayDestroy*/);
    3953     LogFlowFunc(("returns\n"));
     3958    uint32_t const cRefs = drvAudioStreamReleaseInternal(pThis, pStreamEx, true /*fMayDestroy*/);
     3959    LogFlowFunc(("returns (cRefs=%u)\n", cRefs)); RT_NOREF(cRefs);
    39543960}
    39553961
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette