VirtualBox

Changeset 89225 in vbox for trunk/src/VBox/Devices/Audio


Ignore:
Timestamp:
May 21, 2021 1:04:46 PM (4 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
144567
Message:

Audio/ValKit: Implemented audio test execution service (ATS) shutdown handling + testing. bugref:10008

Location:
trunk/src/VBox/Devices/Audio
Files:
2 edited

Legend:

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

    r89215 r89225  
    602602    unsigned    cClientsCur = 0;
    603603    PATSCLIENTINST *papClients  = NULL;
    604     RTPOLLSET   hPollSet;
    605 
    606     int rc = RTPollSetCreate(&hPollSet);
    607     if (RT_FAILURE(rc))
    608         return rc;
    609604
    610605    /* Add the pipe to the poll set. */
    611     rc = RTPollSetAddPipe(hPollSet, pThis->hPipeR, RTPOLL_EVT_READ | RTPOLL_EVT_ERROR, 0);
     606    int rc = RTPollSetAddPipe(pThis->hPollSet, pThis->hPipeR, RTPOLL_EVT_READ | RTPOLL_EVT_ERROR, 0);
    612607    if (RT_SUCCESS(rc))
    613608    {
     
    616611            uint32_t fEvts;
    617612            uint32_t uId;
    618             rc = RTPoll(hPollSet, RT_INDEFINITE_WAIT, &fEvts, &uId);
     613            rc = RTPoll(pThis->hPollSet, RT_INDEFINITE_WAIT, &fEvts, &uId);
    619614            if (RT_SUCCESS(rc))
    620615            {
     
    657652                                idxSlt++;
    658653
    659                             rc = pThis->pTransport->pfnPollSetAdd(hPollSet, pIt->pTransportClient, idxSlt + 1);
     654                            rc = pThis->pTransport->pfnPollSetAdd(pThis->hPollSet, pIt->pTransportClient, idxSlt + 1);
    660655                            if (RT_SUCCESS(rc))
    661656                            {
     
    689684                    {
    690685                        /* Close connection and remove client from array. */
    691                         rc = pThis->pTransport->pfnPollSetRemove(hPollSet, pClient->pTransportClient, uId);
     686                        rc = pThis->pTransport->pfnPollSetRemove(pThis->hPollSet, pClient->pTransportClient, uId);
    692687                        AssertRC(rc);
    693688
     
    701696        }
    702697    }
    703 
    704     RTPollSetDestroy(hPollSet);
    705698
    706699    return rc;
     
    771764int AudioTestSvcInit(PATSSERVER pThis)
    772765{
     766    pThis->fStarted   = false;
    773767    pThis->fTerminate = false;
    774768    RTListInit(&pThis->LstClientsNew);
     
    788782        if (RT_SUCCESS(rc))
    789783        {
    790             rc = RTPipeCreate(&pThis->hPipeR, &pThis->hPipeW, 0);
     784            rc = RTPollSetCreate(&pThis->hPollSet);
    791785            if (RT_SUCCESS(rc))
    792786            {
    793                 /* Spin off the thread serving connections. */
    794                 rc = RTThreadCreate(&pThis->hThreadServing, atsClientWorker, pThis, 0, RTTHREADTYPE_IO, RTTHREADFLAGS_WAITABLE,
    795                                     "AUDTSTSRVC");
     787                rc = RTPipeCreate(&pThis->hPipeR, &pThis->hPipeW, 0);
    796788                if (RT_SUCCESS(rc))
    797                     return VINF_SUCCESS;
     789                {
     790                    /* Spin off the thread serving connections. */
     791                    rc = RTThreadCreate(&pThis->hThreadServing, atsClientWorker, pThis, 0, RTTHREADTYPE_IO, RTTHREADFLAGS_WAITABLE,
     792                                        "AUDTSTSRVC");
     793                    if (RT_SUCCESS(rc))
     794                        return VINF_SUCCESS;
     795                    else
     796                        RTMsgError("Creating the client worker thread failed with %Rrc\n", rc);
     797
     798                    RTPipeClose(pThis->hPipeR);
     799                    RTPipeClose(pThis->hPipeW);
     800                }
    798801                else
    799                     RTMsgError("Creating the client worker thread failed with %Rrc\n", rc);
    800 
    801                 RTPipeClose(pThis->hPipeR);
    802                 RTPipeClose(pThis->hPipeW);
     802                    RTMsgError("Creating communications pipe failed with %Rrc\n", rc);
     803
     804                RTPollSetDestroy(pThis->hPollSet);
    803805            }
    804806            else
    805                 RTMsgError("Creating communications pipe failed with %Rrc\n", rc);
     807                RTMsgError("Creating pollset failed with %Rrc\n", rc);
    806808
    807809            RTCritSectDelete(&pThis->CritSectClients);
     
    825827{
    826828    /* Spin off the main thread. */
    827     int rc = RTThreadCreate(&pThis->hThreadMain, atsMainThread, NULL, 0, RTTHREADTYPE_DEFAULT, RTTHREADFLAGS_WAITABLE,
     829    int rc = RTThreadCreate(&pThis->hThreadMain, atsMainThread, pThis, 0, RTTHREADTYPE_DEFAULT, RTTHREADFLAGS_WAITABLE,
    828830                            "AUDTSTSRVM");
     831    if (RT_SUCCESS(rc))
     832        pThis->fStarted = true;
    829833
    830834    return rc;
     
    839843int AudioTestSvcShutdown(PATSSERVER pThis)
    840844{
    841     RT_NOREF(pThis);
    842     return 0;
    843 }
    844 
     845    if (!pThis->fStarted)
     846        return VINF_SUCCESS;
     847
     848    ASMAtomicXchgBool(&pThis->fTerminate, true);
     849
     850    if (pThis->pTransport)
     851        pThis->pTransport->pfnTerm();
     852
     853    size_t cbWritten;
     854    int rc = RTPipeWrite(pThis->hPipeW, "", 1, &cbWritten);
     855    AssertRCReturn(rc, rc);
     856
     857    /* First close serving thread. */
     858    int rcThread;
     859    rc = RTThreadWait(pThis->hThreadServing, RT_MS_30SEC, &rcThread);
     860    if (RT_SUCCESS(rc))
     861    {
     862        rc = rcThread;
     863        if (RT_SUCCESS(rc))
     864        {
     865            /* Close the main thread last. */
     866            rc = RTThreadWait(pThis->hThreadMain, RT_MS_30SEC, &rcThread);
     867            if (RT_SUCCESS(rc))
     868                rc = rcThread;
     869
     870            if (rc == VERR_TCP_SERVER_DESTROYED)
     871                rc = VINF_SUCCESS;
     872        }
     873    }
     874
     875    if (RT_SUCCESS(rc))
     876        pThis->fStarted = false;
     877
     878    return rc;
     879}
     880
     881/**
     882 * Destroys an ATS instance, internal version.
     883 *
     884 * @returns VBox status code.
     885 * @param   pThis               ATS instance to destroy.
     886 */
     887static int audioTestSvcDestroyInternal(PATSSERVER pThis)
     888{
     889    int rc = VINF_SUCCESS;
     890
     891    if (pThis->hPipeR != NIL_RTPIPE)
     892    {
     893        rc = RTPipeClose(pThis->hPipeR);
     894        AssertRCReturn(rc, rc);
     895        pThis->hPipeR = NIL_RTPIPE;
     896    }
     897
     898    if (pThis->hPipeW != NIL_RTPIPE)
     899    {
     900        rc = RTPipeClose(pThis->hPipeW);
     901        AssertRCReturn(rc, rc);
     902        pThis->hPipeW = NIL_RTPIPE;
     903    }
     904
     905    RTPollSetDestroy(pThis->hPollSet);
     906    pThis->hPollSet = NIL_RTPOLLSET;
     907
     908    pThis->pTransport = NULL;
     909
     910    PATSCLIENTINST pIt, pItNext;
     911    RTListForEachSafe(&pThis->LstClientsNew, pIt, pItNext, ATSCLIENTINST, NdLst)
     912    {
     913        RTListNodeRemove(&pIt->NdLst);
     914
     915        RTMemFree(pIt);
     916        pIt = NULL;
     917    }
     918
     919    if (RTCritSectIsInitialized(&pThis->CritSectClients))
     920    {
     921        rc = RTCritSectDelete(&pThis->CritSectClients);
     922        AssertRCReturn(rc, rc);
     923    }
     924
     925    return rc;
     926}
     927
     928/**
     929 * Destroys an ATS instance.
     930 *
     931 * @returns VBox status code.
     932 * @param   pThis               ATS instance to destroy.
     933 */
     934int AudioTestSvcDestroy(PATSSERVER pThis)
     935{
     936    return audioTestSvcDestroyInternal(pThis);
     937}
     938
  • trunk/src/VBox/Devices/Audio/AudioTestService.h

    r89215 r89225  
    3232    /** The selected transport layer. */
    3333    PCATSTRANSPORT       pTransport;
    34     /** Whether to terminate or not.
    35      * @todo implement signals and stuff.  */
     34    /** Whether server is in started state or not. */
     35    bool volatile        fStarted;
     36    /** Whether to terminate or not. */
    3637    bool volatile        fTerminate;
     38    /** The main thread's poll set to handle new clients. */
     39    RTPOLLSET            hPollSet;
    3740    /** Pipe for communicating with the serving thread about new clients. - read end */
    3841    RTPIPE               hPipeR;
     
    5356
    5457int AudioTestSvcInit(PATSSERVER pThis);
     58int AudioTestSvcDestroy(PATSSERVER pThis);
    5559int AudioTestSvcStart(PATSSERVER pThis);
    5660int AudioTestSvcShutdown(PATSSERVER pThis);
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