Changeset 84447 in vbox for trunk/src/VBox/Devices/Audio/DevIchAc97.cpp
- Timestamp:
- May 22, 2020 9:29:40 AM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/Audio/DevIchAc97.cpp
r82988 r84447 286 286 * Structures and Typedefs * 287 287 *********************************************************************************************************************************/ 288 /** The ICH AC'97 (Intel) controller . */288 /** The ICH AC'97 (Intel) controller (shared). */ 289 289 typedef struct AC97STATE *PAC97STATE; 290 /** The ICH AC'97 (Intel) controller (ring-3). */ 291 typedef struct AC97STATER3 *PAC97STATER3; 290 292 291 293 /** … … 457 459 typedef struct AC97STREAMTHREADCTX 458 460 { 461 /** The AC'97 device state (shared). */ 459 462 PAC97STATE pThis; 463 /** The AC'97 device state (ring-3). */ 464 PAC97STATER3 pThisCC; 465 /** The AC'97 stream state (shared). */ 460 466 PAC97STREAM pStream; 467 /** The AC'97 stream state (ring-3). */ 468 PAC97STREAMR3 pStreamCC; 461 469 } AC97STREAMTHREADCTX; 462 470 /** Pointer to the context for an async I/O thread. */ … … 688 696 689 697 # ifdef VBOX_WITH_AUDIO_AC97_ASYNC_IO 690 static int ichac97R3StreamAsyncIOCreate(PAC97STATE pThis, PAC97ST REAM pStream);691 static int ichac97R3StreamAsyncIODestroy(PAC97STATE pThis, PAC97STREAM pStream);692 static void ichac97R3StreamAsyncIOLock(PAC97STREAM pStream);693 static void ichac97R3StreamAsyncIOUnlock(PAC97STREAM pStream);698 static int ichac97R3StreamAsyncIOCreate(PAC97STATE pThis, PAC97STATER3 pThisCC, PAC97STREAM pStream, PAC97STREAMR3 pStreamCC); 699 static int ichac97R3StreamAsyncIODestroy(PAC97STATE pThis, PAC97STREAMR3 pStreamCC); 700 static void ichac97R3StreamAsyncIOLock(PAC97STREAMR3 pStreamCC); 701 static void ichac97R3StreamAsyncIOUnlock(PAC97STREAMR3 pStreamCC); 694 702 /*static void ichac97R3StreamAsyncIOEnable(PAC97STREAM pStream, bool fEnable); Unused */ 695 703 # endif … … 971 979 # ifdef VBOX_WITH_AUDIO_AC97_ASYNC_IO 972 980 if (fEnable) 973 rc = ichac97R3StreamAsyncIOCreate(pThis, p Stream);981 rc = ichac97R3StreamAsyncIOCreate(pThis, pThisCC, pStream, pStreamCC); 974 982 if (RT_SUCCESS(rc)) 975 ichac97R3StreamAsyncIOLock(pStream );983 ichac97R3StreamAsyncIOLock(pStreamCC); 976 984 # endif 977 985 … … 1013 1021 1014 1022 # ifdef VBOX_WITH_AUDIO_AC97_ASYNC_IO 1015 ichac97R3StreamAsyncIOUnlock(pStream );1023 ichac97R3StreamAsyncIOUnlock(pStreamCC); 1016 1024 # endif 1017 1025 … … 1133 1141 1134 1142 # ifdef VBOX_WITH_AUDIO_AC97_ASYNC_IO 1135 rc2 = ichac97R3StreamAsyncIODestroy(pThis, pStream );1143 rc2 = ichac97R3StreamAsyncIODestroy(pThis, pStreamCC); 1136 1144 AssertRC(rc2); 1137 1145 # else … … 1333 1341 AssertPtr(pThis); 1334 1342 1343 PAC97STATER3 pThisCC = pCtx->pThisCC; 1344 AssertPtr(pThisCC); 1345 1335 1346 PAC97STREAM pStream = pCtx->pStream; 1336 1347 AssertPtr(pStream); 1337 1348 1338 PAC97STREAMSTATEAIO pAIO = &pCtx->pStreamCC->State.AIO; 1349 PAC97STREAMR3 pStreamCC = pCtx->pStreamCC; 1350 AssertPtr(pStreamCC); 1351 1352 PAC97STREAMSTATEAIO pAIO = &pStreamCC->State.AIO; 1339 1353 1340 1354 ASMAtomicXchgBool(&pAIO->fStarted, true); 1341 1355 1342 1356 RTThreadUserSignal(hThreadSelf); 1343 1344 /** @todo r=bird: What wasn't mentioned by the original author of this1345 * code, is that pCtx is now invalid as it must be assumed to be out1346 * of scope in the parent thread. It is a 'ing stack object! */1347 1357 1348 1358 LogFunc(("[SD%RU8] Started\n", pStream->u8SD)); … … 1368 1378 } 1369 1379 1370 ichac97R3StreamUpdate(p DevIns, pThis, pThisCC, pStream, pStreamCC, false /* fInTimer */);1380 ichac97R3StreamUpdate(pThisCC->pDevIns, pThis, pThisCC, pStream, pStreamCC, false /* fInTimer */); 1371 1381 1372 1382 int rc3 = RTCritSectLeave(&pAIO->CritSect); … … 1381 1391 ASMAtomicXchgBool(&pAIO->fStarted, false); 1382 1392 1393 RTMemFree(pCtx); 1394 pCtx = NULL; 1395 1383 1396 return VINF_SUCCESS; 1384 1397 } … … 1388 1401 * 1389 1402 * @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 */ 1408 static int ichac97R3StreamAsyncIOCreate(PAC97STATE pThis, PAC97STATER3 pThisCC, PAC97STREAM pStream, PAC97STREAMR3 pStreamCC) 1394 1409 { 1395 1410 PAC97STREAMSTATEAIO pAIO = &pStreamCC->State.AIO; … … 1408 1423 if (RT_SUCCESS(rc)) 1409 1424 { 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: 1418 1426 * Why aren't this code using the PDM threads (PDMDevHlpThreadCreate)? 1419 1427 * They would help you with managing stuff like VM suspending, resuming … … 1421 1429 * 1422 1430 * 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; 1433 1446 } 1434 1447 } … … 1437 1450 rc = VINF_SUCCESS; 1438 1451 1439 LogFunc(("[SD%RU8] Returning %Rrc\n", pStream ->u8SD, rc));1452 LogFunc(("[SD%RU8] Returning %Rrc\n", pStreamCC->u8SD, rc)); 1440 1453 return rc; 1441 1454 } … … 1448 1461 * for (ring-3). 1449 1462 */ 1450 static int ichac97R3StreamAsyncIONotify(PAC97STREAM pStreamCC)1463 static int ichac97R3StreamAsyncIONotify(PAC97STREAMR3 pStreamCC) 1451 1464 { 1452 1465 LogFunc(("[SD%RU8]\n", pStreamCC->u8SD)); … … 1459 1472 * @returns IPRT status code. 1460 1473 * @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 */ 1476 static int ichac97R3StreamAsyncIODestroy(PAC97STATE pThis, PAC97STREAMR3 pStreamR3) 1477 { 1478 RT_NOREF(pThis); 1479 1480 PAC97STREAMSTATEAIO pAIO = &pStreamR3->State.AIO; 1466 1481 1467 1482 if (!ASMAtomicReadBool(&pAIO->fStarted)) … … 1470 1485 ASMAtomicWriteBool(&pAIO->fShutdown, true); 1471 1486 1472 int rc = ichac97R3StreamAsyncIONotify(pStream CC);1487 int rc = ichac97R3StreamAsyncIONotify(pStreamR3); 1473 1488 AssertRC(rc); 1474 1489 … … 1490 1505 } 1491 1506 1492 LogFunc(("[SD%RU8] Returning %Rrc\n", pStream ->u8SD, rc));1507 LogFunc(("[SD%RU8] Returning %Rrc\n", pStreamR3->u8SD, rc)); 1493 1508 return rc; 1494 1509 } … … 1497 1512 * Locks the async I/O thread of a specific AC'97 audio stream. 1498 1513 * 1499 * @param pStream 1500 */ 1501 static void ichac97R3StreamAsyncIOLock(PAC97STREAM pStream)1514 * @param pStreamCC AC'97 stream to lock async I/O thread for. 1515 */ 1516 static void ichac97R3StreamAsyncIOLock(PAC97STREAMR3 pStreamCC) 1502 1517 { 1503 1518 PAC97STREAMSTATEAIO pAIO = &pStreamCC->State.AIO; … … 1513 1528 * Unlocks the async I/O thread of a specific AC'97 audio stream. 1514 1529 * 1515 * @param pStream 1516 */ 1517 static void ichac97R3StreamAsyncIOUnlock(PAC97STREAM pStream)1530 * @param pStreamCC AC'97 stream to unlock async I/O thread for. 1531 */ 1532 static void ichac97R3StreamAsyncIOUnlock(PAC97STREAMR3 pStreamCC) 1518 1533 { 1519 1534 PAC97STREAMSTATEAIO pAIO = &pStreamCC->State.AIO;
Note:
See TracChangeset
for help on using the changeset viewer.