Changeset 89225 in vbox for trunk/src/VBox/Devices/Audio
- Timestamp:
- May 21, 2021 1:04:46 PM (4 years ago)
- svn:sync-xref-src-repo-rev:
- 144567
- Location:
- trunk/src/VBox/Devices/Audio
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/Audio/AudioTestService.cpp
r89215 r89225 602 602 unsigned cClientsCur = 0; 603 603 PATSCLIENTINST *papClients = NULL; 604 RTPOLLSET hPollSet;605 606 int rc = RTPollSetCreate(&hPollSet);607 if (RT_FAILURE(rc))608 return rc;609 604 610 605 /* 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); 612 607 if (RT_SUCCESS(rc)) 613 608 { … … 616 611 uint32_t fEvts; 617 612 uint32_t uId; 618 rc = RTPoll( hPollSet, RT_INDEFINITE_WAIT, &fEvts, &uId);613 rc = RTPoll(pThis->hPollSet, RT_INDEFINITE_WAIT, &fEvts, &uId); 619 614 if (RT_SUCCESS(rc)) 620 615 { … … 657 652 idxSlt++; 658 653 659 rc = pThis->pTransport->pfnPollSetAdd( hPollSet, pIt->pTransportClient, idxSlt + 1);654 rc = pThis->pTransport->pfnPollSetAdd(pThis->hPollSet, pIt->pTransportClient, idxSlt + 1); 660 655 if (RT_SUCCESS(rc)) 661 656 { … … 689 684 { 690 685 /* 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); 692 687 AssertRC(rc); 693 688 … … 701 696 } 702 697 } 703 704 RTPollSetDestroy(hPollSet);705 698 706 699 return rc; … … 771 764 int AudioTestSvcInit(PATSSERVER pThis) 772 765 { 766 pThis->fStarted = false; 773 767 pThis->fTerminate = false; 774 768 RTListInit(&pThis->LstClientsNew); … … 788 782 if (RT_SUCCESS(rc)) 789 783 { 790 rc = RTP ipeCreate(&pThis->hPipeR, &pThis->hPipeW, 0);784 rc = RTPollSetCreate(&pThis->hPollSet); 791 785 if (RT_SUCCESS(rc)) 792 786 { 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); 796 788 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 } 798 801 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); 803 805 } 804 806 else 805 RTMsgError("Creating communications pipefailed with %Rrc\n", rc);807 RTMsgError("Creating pollset failed with %Rrc\n", rc); 806 808 807 809 RTCritSectDelete(&pThis->CritSectClients); … … 825 827 { 826 828 /* 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, 828 830 "AUDTSTSRVM"); 831 if (RT_SUCCESS(rc)) 832 pThis->fStarted = true; 829 833 830 834 return rc; … … 839 843 int AudioTestSvcShutdown(PATSSERVER pThis) 840 844 { 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 */ 887 static 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 */ 934 int AudioTestSvcDestroy(PATSSERVER pThis) 935 { 936 return audioTestSvcDestroyInternal(pThis); 937 } 938 -
trunk/src/VBox/Devices/Audio/AudioTestService.h
r89215 r89225 32 32 /** The selected transport layer. */ 33 33 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. */ 36 37 bool volatile fTerminate; 38 /** The main thread's poll set to handle new clients. */ 39 RTPOLLSET hPollSet; 37 40 /** Pipe for communicating with the serving thread about new clients. - read end */ 38 41 RTPIPE hPipeR; … … 53 56 54 57 int AudioTestSvcInit(PATSSERVER pThis); 58 int AudioTestSvcDestroy(PATSSERVER pThis); 55 59 int AudioTestSvcStart(PATSSERVER pThis); 56 60 int AudioTestSvcShutdown(PATSSERVER pThis);
Note:
See TracChangeset
for help on using the changeset viewer.