VirtualBox

Ignore:
Timestamp:
May 22, 2020 9:29:40 AM (5 years ago)
Author:
vboxsync
Message:

Audio/AC97: Revived / fixed async I/O code after driver interface revamp (disabled by default for now).

File:
1 edited

Legend:

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

    r82988 r84447  
    286286*   Structures and Typedefs                                                                                                      *
    287287*********************************************************************************************************************************/
    288 /** The ICH AC'97 (Intel) controller. */
     288/** The ICH AC'97 (Intel) controller (shared). */
    289289typedef struct AC97STATE *PAC97STATE;
     290/** The ICH AC'97 (Intel) controller (ring-3). */
     291typedef struct AC97STATER3 *PAC97STATER3;
    290292
    291293/**
     
    457459typedef struct AC97STREAMTHREADCTX
    458460{
     461    /** The AC'97 device state (shared). */
    459462    PAC97STATE              pThis;
     463    /** The AC'97 device state (ring-3). */
     464    PAC97STATER3            pThisCC;
     465    /** The AC'97 stream state (shared). */
    460466    PAC97STREAM             pStream;
     467    /** The AC'97 stream state (ring-3). */
     468    PAC97STREAMR3           pStreamCC;
    461469} AC97STREAMTHREADCTX;
    462470/** Pointer to the context for an async I/O thread. */
     
    688696
    689697# ifdef VBOX_WITH_AUDIO_AC97_ASYNC_IO
    690 static int                ichac97R3StreamAsyncIOCreate(PAC97STATE pThis, PAC97STREAM pStream);
    691 static int                ichac97R3StreamAsyncIODestroy(PAC97STATE pThis, PAC97STREAM pStream);
    692 static void               ichac97R3StreamAsyncIOLock(PAC97STREAM pStream);
    693 static void               ichac97R3StreamAsyncIOUnlock(PAC97STREAM pStream);
     698static int                ichac97R3StreamAsyncIOCreate(PAC97STATE pThis, PAC97STATER3 pThisCC, PAC97STREAM pStream, PAC97STREAMR3 pStreamCC);
     699static int                ichac97R3StreamAsyncIODestroy(PAC97STATE pThis, PAC97STREAMR3 pStreamCC);
     700static void               ichac97R3StreamAsyncIOLock(PAC97STREAMR3 pStreamCC);
     701static void               ichac97R3StreamAsyncIOUnlock(PAC97STREAMR3 pStreamCC);
    694702/*static void               ichac97R3StreamAsyncIOEnable(PAC97STREAM pStream, bool fEnable); Unused */
    695703# endif
     
    971979# ifdef VBOX_WITH_AUDIO_AC97_ASYNC_IO
    972980    if (fEnable)
    973         rc = ichac97R3StreamAsyncIOCreate(pThis, pStream);
     981        rc = ichac97R3StreamAsyncIOCreate(pThis, pThisCC, pStream, pStreamCC);
    974982    if (RT_SUCCESS(rc))
    975         ichac97R3StreamAsyncIOLock(pStream);
     983        ichac97R3StreamAsyncIOLock(pStreamCC);
    976984# endif
    977985
     
    10131021
    10141022# ifdef VBOX_WITH_AUDIO_AC97_ASYNC_IO
    1015     ichac97R3StreamAsyncIOUnlock(pStream);
     1023    ichac97R3StreamAsyncIOUnlock(pStreamCC);
    10161024# endif
    10171025
     
    11331141
    11341142# ifdef VBOX_WITH_AUDIO_AC97_ASYNC_IO
    1135     rc2 = ichac97R3StreamAsyncIODestroy(pThis, pStream);
     1143    rc2 = ichac97R3StreamAsyncIODestroy(pThis, pStreamCC);
    11361144    AssertRC(rc2);
    11371145# else
     
    13331341    AssertPtr(pThis);
    13341342
     1343    PAC97STATER3 pThisCC = pCtx->pThisCC;
     1344    AssertPtr(pThisCC);
     1345
    13351346    PAC97STREAM pStream = pCtx->pStream;
    13361347    AssertPtr(pStream);
    13371348
    1338     PAC97STREAMSTATEAIO pAIO = &pCtx->pStreamCC->State.AIO;
     1349    PAC97STREAMR3 pStreamCC = pCtx->pStreamCC;
     1350    AssertPtr(pStreamCC);
     1351
     1352    PAC97STREAMSTATEAIO pAIO = &pStreamCC->State.AIO;
    13391353
    13401354    ASMAtomicXchgBool(&pAIO->fStarted, true);
    13411355
    13421356    RTThreadUserSignal(hThreadSelf);
    1343 
    1344     /** @todo r=bird: What wasn't mentioned by the original author of this
    1345      *        code, is that pCtx is now invalid as it must be assumed to be out
    1346      *        of scope in the parent thread.  It is a 'ing stack object! */
    13471357
    13481358    LogFunc(("[SD%RU8] Started\n", pStream->u8SD));
     
    13681378            }
    13691379
    1370             ichac97R3StreamUpdate(pDevIns, pThis, pThisCC, pStream, pStreamCC, false /* fInTimer */);
     1380            ichac97R3StreamUpdate(pThisCC->pDevIns, pThis, pThisCC, pStream, pStreamCC, false /* fInTimer */);
    13711381
    13721382            int rc3 = RTCritSectLeave(&pAIO->CritSect);
     
    13811391    ASMAtomicXchgBool(&pAIO->fStarted, false);
    13821392
     1393    RTMemFree(pCtx);
     1394    pCtx = NULL;
     1395
    13831396    return VINF_SUCCESS;
    13841397}
     
    13881401 *
    13891402 * @returns IPRT status code.
    1390  * @param   pThis               The shared AC'97 state.
    1391  * @param   pStream             AC'97 audio stream to create the async I/O thread for.
    1392  */
    1393 static int ichac97R3StreamAsyncIOCreate(PAC97STATE pThis, PAC97STREAM pStream)
     1403 * @param   pThis               The shared AC'97 state (shared).
     1404 * @param   pThisCC             The shared AC'97 state (ring-3).
     1405 * @param   pStream             AC'97 audio stream to create the async I/O thread for (shared).
     1406 * @param   pStreamCC           AC'97 audio stream to create the async I/O thread for (ring-3).
     1407 */
     1408static int ichac97R3StreamAsyncIOCreate(PAC97STATE pThis, PAC97STATER3 pThisCC, PAC97STREAM pStream, PAC97STREAMR3 pStreamCC)
    13941409{
    13951410    PAC97STREAMSTATEAIO pAIO = &pStreamCC->State.AIO;
     
    14081423            if (RT_SUCCESS(rc))
    14091424            {
    1410 /** @todo r=bird: Why is Ctx on the stack?  There is no mention of this in
    1411  *        the thread structure.  Besides, you only wait 10seconds, if the
    1412  *        host is totally overloaded, it may go out of scope before the new
    1413  *        thread has finished with it and it will like crash and burn.
    1414  *
    1415  *        Also, there is RTThreadCreateF for giving threads complicated
    1416  *        names.
    1417  *
     1425/** @todo r=bird:
    14181426 *        Why aren't this code using the PDM threads (PDMDevHlpThreadCreate)?
    14191427 *        They would help you with managing stuff like VM suspending, resuming
     
    14211429 *
    14221430 *        Finally, just create the threads at construction time. */
    1423                 AC97STREAMTHREADCTX Ctx = { pThis, pStream };
    1424 # error "Busted code! Do not pass a structure living on the parent stack to the poor thread!"
    1425 
    1426                 char szThreadName[64];
    1427                 RTStrPrintf2(szThreadName, sizeof(szThreadName), "ac97AIO%RU8", pStream->u8SD);
    1428 
    1429                 rc = RTThreadCreate(&pAIO->Thread, ichac97R3StreamAsyncIOThread, &Ctx,
    1430                                     0, RTTHREADTYPE_IO, RTTHREADFLAGS_WAITABLE, szThreadName);
    1431                 if (RT_SUCCESS(rc))
    1432                     rc = RTThreadUserWait(pAIO->Thread, 10 * 1000 /* 10s timeout */);
     1431                PAC97STREAMTHREADCTX pCtx = (PAC97STREAMTHREADCTX)RTMemAllocZ(sizeof(AC97STREAMTHREADCTX));
     1432                if (pCtx)
     1433                {
     1434                    pCtx->pStream   = pStream;
     1435                    pCtx->pStreamCC = pStreamCC;
     1436                    pCtx->pThis     = pThis;
     1437                    pCtx->pThisCC   = pThisCC;
     1438
     1439                    rc = RTThreadCreateF(&pAIO->Thread, ichac97R3StreamAsyncIOThread, pCtx,
     1440                                         0, RTTHREADTYPE_IO, RTTHREADFLAGS_WAITABLE, "ac97AIO%RU8", pStreamCC->u8SD);
     1441                    if (RT_SUCCESS(rc))
     1442                        rc = RTThreadUserWait(pAIO->Thread, 30 * 1000 /* 30s timeout */);
     1443                }
     1444                else
     1445                    rc = VERR_NO_MEMORY;
    14331446            }
    14341447        }
     
    14371450        rc = VINF_SUCCESS;
    14381451
    1439     LogFunc(("[SD%RU8] Returning %Rrc\n", pStream->u8SD, rc));
     1452    LogFunc(("[SD%RU8] Returning %Rrc\n", pStreamCC->u8SD, rc));
    14401453    return rc;
    14411454}
     
    14481461 *                                for (ring-3).
    14491462 */
    1450 static int ichac97R3StreamAsyncIONotify(PAC97STREAM pStreamCC)
     1463static int ichac97R3StreamAsyncIONotify(PAC97STREAMR3 pStreamCC)
    14511464{
    14521465    LogFunc(("[SD%RU8]\n", pStreamCC->u8SD));
     
    14591472 * @returns IPRT status code.
    14601473 * @param   pThis               The shared AC'97 state.
    1461  * @param   pStream             AC'97 audio stream to destroy the async I/O thread for.
    1462  */
    1463 static int ichac97R3StreamAsyncIODestroy(PAC97STATE pThis, PAC97STREAM pStream)
    1464 {
    1465     PAC97STREAMSTATEAIO pAIO = &pStreamCC->State.AIO;
     1474 * @param   pStreamCC           AC'97 audio stream to destroy the async I/O thread for.
     1475 */
     1476static int ichac97R3StreamAsyncIODestroy(PAC97STATE pThis, PAC97STREAMR3 pStreamR3)
     1477{
     1478    RT_NOREF(pThis);
     1479
     1480    PAC97STREAMSTATEAIO pAIO = &pStreamR3->State.AIO;
    14661481
    14671482    if (!ASMAtomicReadBool(&pAIO->fStarted))
     
    14701485    ASMAtomicWriteBool(&pAIO->fShutdown, true);
    14711486
    1472     int rc = ichac97R3StreamAsyncIONotify(pStreamCC);
     1487    int rc = ichac97R3StreamAsyncIONotify(pStreamR3);
    14731488    AssertRC(rc);
    14741489
     
    14901505    }
    14911506
    1492     LogFunc(("[SD%RU8] Returning %Rrc\n", pStream->u8SD, rc));
     1507    LogFunc(("[SD%RU8] Returning %Rrc\n", pStreamR3->u8SD, rc));
    14931508    return rc;
    14941509}
     
    14971512 * Locks the async I/O thread of a specific AC'97 audio stream.
    14981513 *
    1499  * @param   pStream             AC'97 stream to lock async I/O thread for.
    1500  */
    1501 static void ichac97R3StreamAsyncIOLock(PAC97STREAM pStream)
     1514 * @param   pStreamCC           AC'97 stream to lock async I/O thread for.
     1515 */
     1516static void ichac97R3StreamAsyncIOLock(PAC97STREAMR3 pStreamCC)
    15021517{
    15031518    PAC97STREAMSTATEAIO pAIO = &pStreamCC->State.AIO;
     
    15131528 * Unlocks the async I/O thread of a specific AC'97 audio stream.
    15141529 *
    1515  * @param   pStream             AC'97 stream to unlock async I/O thread for.
    1516  */
    1517 static void ichac97R3StreamAsyncIOUnlock(PAC97STREAM pStream)
     1530 * @param   pStreamCC           AC'97 stream to unlock async I/O thread for.
     1531 */
     1532static void ichac97R3StreamAsyncIOUnlock(PAC97STREAMR3 pStreamCC)
    15181533{
    15191534    PAC97STREAMSTATEAIO pAIO = &pStreamCC->State.AIO;
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