VirtualBox

Changeset 75541 in vbox for trunk/src/VBox/Main/src-client


Ignore:
Timestamp:
Nov 17, 2018 3:50:40 AM (6 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
126699
Message:

Main/HGCM: Skip the handle stuff for the HGCMMsgCore class, it just add overhead. bugref:9172

Location:
trunk/src/VBox/Main/src-client
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/src-client/HGCM.cpp

    r75539 r75541  
    438438{
    439439    public:
     440        HGCMMsgCall() {}
     441
     442        HGCMMsgCall(HGCMThread *pThread)
     443        {
     444            InitializeCore(SVC_MSG_GUESTCALL, pThread);
     445            Initialize();
     446        }
     447        ~HGCMMsgCall() { Log(("~HGCMMsgCall %p\n", this)); }
     448
    440449        /* client identifier */
    441450        uint32_t u32ClientId;
     
    947956
    948957            /* Execute the load request on the service thread. */
    949             HGCMMSGHANDLE hMsg;
    950             rc = hgcmMsgAlloc(m_pThread, &hMsg, SVC_MSG_LOAD, hgcmMessageAllocSvc);
     958            HGCMMsgCore *pCoreMsg;
     959            rc = hgcmMsgAlloc(m_pThread, &pCoreMsg, SVC_MSG_LOAD, hgcmMessageAllocSvc);
    951960
    952961            if (RT_SUCCESS(rc))
    953962            {
    954                 HGCMMsgSvcLoad *pMsg = (HGCMMsgSvcLoad *)hgcmObjReference(hMsg, HGCMOBJ_MSG);
    955                 AssertRelease(pMsg);
     963                HGCMMsgSvcLoad *pMsg = (HGCMMsgSvcLoad *)pCoreMsg;
     964
    956965                pMsg->pUVM = pUVM;
    957                 hgcmObjDereference(pMsg);
    958 
    959                 rc = hgcmMsgSend(hMsg);
     966
     967                rc = hgcmMsgSend(pMsg);
    960968            }
    961969        }
     
    975983    LogFlowFunc(("%s\n", m_pszSvcName));
    976984
    977     HGCMMSGHANDLE hMsg;
    978     int rc = hgcmMsgAlloc(m_pThread, &hMsg, SVC_MSG_UNLOAD, hgcmMessageAllocSvc);
     985    HGCMMsgCore *pMsg;
     986    int rc = hgcmMsgAlloc(m_pThread, &pMsg, SVC_MSG_UNLOAD, hgcmMessageAllocSvc);
    979987
    980988    if (RT_SUCCESS(rc))
    981989    {
    982         rc = hgcmMsgSend(hMsg);
     990        rc = hgcmMsgSend(pMsg);
    983991
    984992        if (RT_SUCCESS(rc))
     
    10011009    LogFlowFunc(("%s\n", m_pszSvcName));
    10021010
    1003     HGCMMSGHANDLE hMsg;
    1004     int rc = hgcmMsgAlloc(m_pThread, &hMsg, SVC_MSG_SAVESTATE, hgcmMessageAllocSvc);
     1011    HGCMMsgCore *pCoreMsg;
     1012    int rc = hgcmMsgAlloc(m_pThread, &pCoreMsg, SVC_MSG_SAVESTATE, hgcmMessageAllocSvc);
    10051013
    10061014    if (RT_SUCCESS(rc))
    10071015    {
    1008         HGCMMsgLoadSaveStateClient *pMsg = (HGCMMsgLoadSaveStateClient *)hgcmObjReference(hMsg, HGCMOBJ_MSG);
    1009         AssertRelease(pMsg);
     1016        HGCMMsgLoadSaveStateClient *pMsg = (HGCMMsgLoadSaveStateClient *)pCoreMsg;
    10101017
    10111018        pMsg->u32ClientId = u32ClientId;
    10121019        pMsg->pSSM        = pSSM;
    10131020
    1014         hgcmObjDereference(pMsg);
    1015 
    1016         rc = hgcmMsgSend(hMsg);
     1021        rc = hgcmMsgSend(pMsg);
    10171022    }
    10181023
     
    10251030    LogFlowFunc(("%s\n", m_pszSvcName));
    10261031
    1027     HGCMMSGHANDLE hMsg;
    1028     int rc = hgcmMsgAlloc(m_pThread, &hMsg, SVC_MSG_LOADSTATE, hgcmMessageAllocSvc);
     1032    HGCMMsgCore *pCoreMsg;
     1033    int rc = hgcmMsgAlloc(m_pThread, &pCoreMsg, SVC_MSG_LOADSTATE, hgcmMessageAllocSvc);
    10291034
    10301035    if (RT_SUCCESS(rc))
    10311036    {
    1032         HGCMMsgLoadSaveStateClient *pMsg = (HGCMMsgLoadSaveStateClient *)hgcmObjReference(hMsg, HGCMOBJ_MSG);
    1033 
    1034         AssertRelease(pMsg);
     1037        HGCMMsgLoadSaveStateClient *pMsg = (HGCMMsgLoadSaveStateClient *)pCoreMsg;
    10351038
    10361039        pMsg->u32ClientId = u32ClientId;
    10371040        pMsg->pSSM        = pSSM;
    10381041
    1039         hgcmObjDereference(pMsg);
    1040 
    1041         rc = hgcmMsgSend(hMsg);
     1042        rc = hgcmMsgSend(pMsg);
    10421043    }
    10431044
     
    14711472    {
    14721473        /* Call the service. */
    1473         HGCMMSGHANDLE hMsg;
    1474 
    1475         rc = hgcmMsgAlloc(m_pThread, &hMsg, SVC_MSG_CONNECT, hgcmMessageAllocSvc);
     1474        HGCMMsgCore *pCoreMsg;
     1475
     1476        rc = hgcmMsgAlloc(m_pThread, &pCoreMsg, SVC_MSG_CONNECT, hgcmMessageAllocSvc);
    14761477
    14771478        if (RT_SUCCESS(rc))
    14781479        {
    1479             HGCMMsgSvcConnect *pMsg = (HGCMMsgSvcConnect *)hgcmObjReference(hMsg, HGCMOBJ_MSG);
    1480             AssertRelease(pMsg);
     1480            HGCMMsgSvcConnect *pMsg = (HGCMMsgSvcConnect *)pCoreMsg;
    14811481
    14821482            pMsg->u32ClientId = handle;
    14831483
    1484             hgcmObjDereference(pMsg);
    1485 
    1486             rc = hgcmMsgSend(hMsg);
     1484            rc = hgcmMsgSend(pMsg);
    14871485
    14881486            if (RT_SUCCESS(rc))
     
    14981496                        uint32_t *paClientIdsNew;
    14991497
    1500                         paClientIdsNew = (uint32_t *)RTMemRealloc(m_paClientIds, (m_cClientsAllocated + cDelta) *
    1501                             sizeof(m_paClientIds[0]));
     1498                        paClientIdsNew = (uint32_t *)RTMemRealloc(m_paClientIds,
     1499                                                                  (m_cClientsAllocated + cDelta) * sizeof(m_paClientIds[0]));
    15021500                        Assert(paClientIdsNew);
    15031501
     
    15561554    {
    15571555        /* Call the service. */
    1558         HGCMMSGHANDLE hMsg;
    1559 
    1560         rc = hgcmMsgAlloc(m_pThread, &hMsg, SVC_MSG_DISCONNECT, hgcmMessageAllocSvc);
     1556        HGCMMsgCore *pCoreMsg;
     1557
     1558        rc = hgcmMsgAlloc(m_pThread, &pCoreMsg, SVC_MSG_DISCONNECT, hgcmMessageAllocSvc);
    15611559
    15621560        if (RT_SUCCESS(rc))
    15631561        {
    1564             HGCMMsgSvcDisconnect *pMsg = (HGCMMsgSvcDisconnect *)hgcmObjReference(hMsg, HGCMOBJ_MSG);
    1565             AssertRelease(pMsg);
     1562            HGCMMsgSvcDisconnect *pMsg = (HGCMMsgSvcDisconnect *)pCoreMsg;
    15661563
    15671564            pMsg->u32ClientId = u32ClientId;
    15681565
    1569             hgcmObjDereference(pMsg);
    1570 
    1571             rc = hgcmMsgSend(hMsg);
     1566            rc = hgcmMsgSend(pMsg);
    15721567        }
    15731568        else
     
    16111606
    16121607    /* Forward the message to the service thread. */
    1613     HGCMMSGHANDLE hMsg = 0;
    1614     int rc = hgcmMsgAlloc(m_pThread, &hMsg, SVC_MSG_REGEXT, hgcmMessageAllocSvc);
     1608    HGCMMsgCore *pCoreMsg;
     1609    int rc = hgcmMsgAlloc(m_pThread, &pCoreMsg, SVC_MSG_REGEXT, hgcmMessageAllocSvc);
    16151610
    16161611    if (RT_SUCCESS(rc))
    16171612    {
    1618         HGCMMsgSvcRegisterExtension *pMsg = (HGCMMsgSvcRegisterExtension *)hgcmObjReference(hMsg, HGCMOBJ_MSG);
    1619         AssertRelease(pMsg);
     1613        HGCMMsgSvcRegisterExtension *pMsg = (HGCMMsgSvcRegisterExtension *)pCoreMsg;
    16201614
    16211615        pMsg->handle       = handle;
     
    16231617        pMsg->pvExtension  = pvExtension;
    16241618
    1625         hgcmObjDereference(pMsg);
    1626 
    1627         rc = hgcmMsgSend(hMsg);
     1619        rc = hgcmMsgSend(pMsg);
    16281620    }
    16291621
     
    16351627{
    16361628    /* Forward the message to the service thread. */
    1637     HGCMMSGHANDLE hMsg = 0;
    1638     int rc = hgcmMsgAlloc(m_pThread, &hMsg, SVC_MSG_UNREGEXT, hgcmMessageAllocSvc);
     1629    HGCMMsgCore *pCoreMsg;
     1630    int rc = hgcmMsgAlloc(m_pThread, &pCoreMsg, SVC_MSG_UNREGEXT, hgcmMessageAllocSvc);
    16391631
    16401632    if (RT_SUCCESS(rc))
    16411633    {
    1642         HGCMMsgSvcUnregisterExtension *pMsg = (HGCMMsgSvcUnregisterExtension *)hgcmObjReference(hMsg, HGCMOBJ_MSG);
    1643         AssertRelease(pMsg);
     1634        HGCMMsgSvcUnregisterExtension *pMsg = (HGCMMsgSvcUnregisterExtension *)pCoreMsg;
    16441635
    16451636        pMsg->handle = handle;
    16461637
    1647         hgcmObjDereference(pMsg);
    1648 
    1649         rc = hgcmMsgSend(hMsg);
     1638        rc = hgcmMsgSend(pMsg);
    16501639    }
    16511640
     
    16531642}
    16541643
    1655 /* Perform a guest call to the service.
     1644/** Perform a guest call to the service.
    16561645 *
    16571646 * @param pHGCMPort      The port to be used for completion confirmation.
     
    16631652 * @param tsArrival      The STAM_GET_TS() value when the request arrived.
    16641653 * @return VBox rc.
     1654 * @retval VINF_HGCM_ASYNC_EXECUTE on success.
    16651655 */
    16661656int HGCMService::GuestCall(PPDMIHGCMPORT pHGCMPort, PVBOXHGCMCMD pCmd, uint32_t u32ClientId, uint32_t u32Function,
    16671657                           uint32_t cParms, VBOXHGCMSVCPARM paParms[], uint64_t tsArrival)
    16681658{
    1669     HGCMMSGHANDLE hMsg = 0;
    1670 
    16711659    LogFlow(("MAIN::HGCMService::Call\n"));
    16721660
    1673     int rc = hgcmMsgAlloc(m_pThread, &hMsg, SVC_MSG_GUESTCALL, hgcmMessageAllocSvc);
    1674 
    1675     if (RT_SUCCESS(rc))
    1676     {
    1677         HGCMMsgCall *pMsg = (HGCMMsgCall *)hgcmObjReference(hMsg, HGCMOBJ_MSG);
    1678 
    1679         AssertRelease(pMsg);
    1680 
    1681         pMsg->pCmd      = pCmd;
    1682         pMsg->pHGCMPort = pHGCMPort;
    1683 
     1661    int rc;
     1662    HGCMMsgCall *pMsg = new (std::nothrow) HGCMMsgCall(m_pThread);
     1663    if (pMsg)
     1664    {
     1665        pMsg->Reference();
     1666
     1667        pMsg->pCmd        = pCmd;
     1668        pMsg->pHGCMPort   = pHGCMPort;
    16841669        pMsg->u32ClientId = u32ClientId;
    16851670        pMsg->u32Function = u32Function;
     
    16881673        pMsg->tsArrival   = tsArrival;
    16891674
    1690         hgcmObjDereference(pMsg);
    1691 
    1692         rc = hgcmMsgPost(hMsg, hgcmMsgCompletionCallback);
     1675        rc = hgcmMsgPost(pMsg, hgcmMsgCompletionCallback);
    16931676    }
    16941677    else
    16951678    {
    1696         Log(("MAIN::HGCMService::Call: Message allocation failed: %Rrc\n", rc));
     1679        Log(("MAIN::HGCMService::Call: Message allocation failed\n"));
     1680        rc = VERR_NO_MEMORY;
    16971681    }
    16981682
     
    17011685}
    17021686
    1703 /* Perform a host call the service.
     1687/** Perform a host call the service.
    17041688 *
    17051689 * @param u32Function    The function number.
     
    17131697                 m_pszSvcName, u32Function, cParms, paParms));
    17141698
    1715     HGCMMSGHANDLE hMsg = 0;
    1716     int rc = hgcmMsgAlloc(m_pThread, &hMsg, SVC_MSG_HOSTCALL, hgcmMessageAllocSvc);
     1699    HGCMMsgCore *pCoreMsg;
     1700    int rc = hgcmMsgAlloc(m_pThread, &pCoreMsg, SVC_MSG_HOSTCALL, hgcmMessageAllocSvc);
    17171701
    17181702    if (RT_SUCCESS(rc))
    17191703    {
    1720         HGCMMsgHostCallSvc *pMsg = (HGCMMsgHostCallSvc *)hgcmObjReference(hMsg, HGCMOBJ_MSG);
    1721         AssertRelease(pMsg);
     1704        HGCMMsgHostCallSvc *pMsg = (HGCMMsgHostCallSvc *)pCoreMsg;
    17221705
    17231706        pMsg->u32Function      = u32Function;
     
    17251708        pMsg->paParms          = paParms;
    17261709
    1727         hgcmObjDereference(pMsg);
    1728 
    1729         rc = hgcmMsgSend(hMsg);
     1710        rc = hgcmMsgSend(pMsg);
    17301711    }
    17311712
     
    17351716
    17361717#ifdef VBOX_WITH_CRHGSMI
     1718
    17371719static DECLCALLBACK(void) hgcmMsgFastCallCompletionCallback(int32_t result, HGCMMsgCore *pMsgCore)
    17381720{
     
    17421724    HGCMMsgHostFastCallAsyncSvc *pMsg = (HGCMMsgHostFastCallAsyncSvc *)pMsgCore;
    17431725    if (pMsg->pfnCompletion)
    1744     {
    17451726        pMsg->pfnCompletion(result, pMsg->u32Function, &pMsg->Param, pMsg->pvCompletion);
    1746     }
    17471727}
    17481728
     
    17701750                 m_pszSvcName, u32Function, pParm));
    17711751
    1772     HGCMMSGHANDLE hMsg = 0;
    1773     int rc = hgcmMsgAlloc(m_pThread, &hMsg, SVC_MSG_HOSTFASTCALLASYNC, hgcmMessageAllocSvc);
     1752    HGCMMsgCore *pCoreMsg;
     1753    int rc = hgcmMsgAlloc(m_pThread, &pCoreMsg, SVC_MSG_HOSTFASTCALLASYNC, hgcmMessageAllocSvc);
    17741754
    17751755    if (RT_SUCCESS(rc))
    17761756    {
    1777         HGCMMsgHostFastCallAsyncSvc *pMsg = (HGCMMsgHostFastCallAsyncSvc *)hgcmObjReference(hMsg, HGCMOBJ_MSG);
    1778         AssertRelease(pMsg);
     1757        HGCMMsgHostFastCallAsyncSvc *pMsg = (HGCMMsgHostFastCallAsyncSvc *)pCoreMsg;
    17791758
    17801759        pMsg->u32Function      = u32Function;
     
    17831762        pMsg->pvCompletion = pvCompletion;
    17841763
    1785         hgcmObjDereference(pMsg);
    1786 
    1787         rc = hgcmMsgPost(hMsg, hgcmMsgFastCallCompletionCallback);
     1764        rc = hgcmMsgPost(pMsg, hgcmMsgFastCallCompletionCallback);
    17881765    }
    17891766
     
    17911768    return rc;
    17921769}
    1793 #endif
     1770
     1771#endif /* VBOX_WITH_CRHGSMI */
    17941772
    17951773/*
     
    19221900        case HGCM_MSG_UNREGEXT:   return new HGCMMsgMainUnregisterExtension();
    19231901#ifdef VBOX_WITH_CRHGSMI
    1924         case HGCM_MSG_SVCAQUIRE: return new HGCMMsgMainSvcAcquire();
     1902        case HGCM_MSG_SVCAQUIRE:  return new HGCMMsgMainSvcAcquire();
    19251903        case HGCM_MSG_SVCRELEASE: return new HGCMMsgMainSvcRelease();
    19261904#endif
     
    22172195
    22182196    /* Forward the request to the main hgcm thread. */
    2219     HGCMMSGHANDLE hMsg = 0;
    2220 
    2221     int rc = hgcmMsgAlloc(g_pHgcmThread, &hMsg, HGCM_MSG_LOAD, hgcmMainMessageAlloc);
     2197    HGCMMsgCore *pCoreMsg;
     2198    int rc = hgcmMsgAlloc(g_pHgcmThread, &pCoreMsg, HGCM_MSG_LOAD, hgcmMainMessageAlloc);
    22222199
    22232200    if (RT_SUCCESS(rc))
    22242201    {
    22252202        /* Initialize the message. Since the message is synchronous, use the supplied pointers. */
    2226         HGCMMsgMainLoad *pMsg = (HGCMMsgMainLoad *)hgcmObjReference(hMsg, HGCMOBJ_MSG);
    2227         AssertRelease(pMsg);
     2203        HGCMMsgMainLoad *pMsg = (HGCMMsgMainLoad *)pCoreMsg;
    22282204
    22292205        pMsg->pszServiceLibrary = pszServiceLibrary;
     
    22312207        pMsg->pUVM              = pUVM;
    22322208
    2233         hgcmObjDereference(pMsg);
    2234 
    2235         rc = hgcmMsgSend(hMsg);
     2209        rc = hgcmMsgSend(pMsg);
    22362210    }
    22372211
     
    22612235
    22622236    /* Forward the request to the main hgcm thread. */
    2263     HGCMMSGHANDLE hMsg = 0;
    2264 
    2265     int rc = hgcmMsgAlloc(g_pHgcmThread, &hMsg, HGCM_MSG_REGEXT, hgcmMainMessageAlloc);
     2237    HGCMMsgCore *pCoreMsg;
     2238    int rc = hgcmMsgAlloc(g_pHgcmThread, &pCoreMsg, HGCM_MSG_REGEXT, hgcmMainMessageAlloc);
    22662239
    22672240    if (RT_SUCCESS(rc))
    22682241    {
    22692242        /* Initialize the message. Since the message is synchronous, use the supplied pointers. */
    2270         HGCMMsgMainRegisterExtension *pMsg = (HGCMMsgMainRegisterExtension *)hgcmObjReference(hMsg, HGCMOBJ_MSG);
    2271         AssertRelease(pMsg);
     2243        HGCMMsgMainRegisterExtension *pMsg = (HGCMMsgMainRegisterExtension *)pCoreMsg;
    22722244
    22732245        pMsg->pHandle        = pHandle;
     
    22762248        pMsg->pvExtension    = pvExtension;
    22772249
    2278         hgcmObjDereference(pMsg);
    2279 
    2280         rc = hgcmMsgSend(hMsg);
     2250        rc = hgcmMsgSend(pMsg);
    22812251    }
    22822252
     
    22902260
    22912261    /* Forward the request to the main hgcm thread. */
    2292     HGCMMSGHANDLE hMsg = 0;
    2293 
    2294     int rc = hgcmMsgAlloc(g_pHgcmThread, &hMsg, HGCM_MSG_UNREGEXT, hgcmMainMessageAlloc);
     2262    HGCMMsgCore *pCoreMsg;
     2263    int rc = hgcmMsgAlloc(g_pHgcmThread, &pCoreMsg, HGCM_MSG_UNREGEXT, hgcmMainMessageAlloc);
    22952264
    22962265    if (RT_SUCCESS(rc))
    22972266    {
    22982267        /* Initialize the message. */
    2299         HGCMMsgMainUnregisterExtension *pMsg = (HGCMMsgMainUnregisterExtension *)hgcmObjReference(hMsg, HGCMOBJ_MSG);
    2300         AssertRelease(pMsg);
     2268        HGCMMsgMainUnregisterExtension *pMsg = (HGCMMsgMainUnregisterExtension *)pCoreMsg;
    23012269
    23022270        pMsg->handle = handle;
    23032271
    2304         hgcmObjDereference(pMsg);
    2305 
    2306         rc = hgcmMsgSend(hMsg);
     2272        rc = hgcmMsgSend(pMsg);
    23072273    }
    23082274
     
    23332299
    23342300    /* Forward the request to the main hgcm thread. */
    2335     HGCMMSGHANDLE hMsg = 0;
    2336 
    2337     int rc = hgcmMsgAlloc(g_pHgcmThread, &hMsg, HGCM_MSG_CONNECT, hgcmMainMessageAlloc);
     2301    HGCMMsgCore *pCoreMsg;
     2302    int rc = hgcmMsgAlloc(g_pHgcmThread, &pCoreMsg, HGCM_MSG_CONNECT, hgcmMainMessageAlloc);
    23382303
    23392304    if (RT_SUCCESS(rc))
     
    23432308         * use the supplied pointers.
    23442309         */
    2345         HGCMMsgMainConnect *pMsg = (HGCMMsgMainConnect *)hgcmObjReference(hMsg, HGCMOBJ_MSG);
    2346         AssertRelease(pMsg);
     2310        HGCMMsgMainConnect *pMsg = (HGCMMsgMainConnect *)pCoreMsg;
    23472311
    23482312        pMsg->pHGCMPort      = pHGCMPort;
     
    23512315        pMsg->pu32ClientId   = pu32ClientId;
    23522316
    2353         hgcmObjDereference(pMsg);
    2354 
    2355         rc = hgcmMsgPost(hMsg, hgcmMsgCompletionCallback);
     2317        rc = hgcmMsgPost(pMsg, hgcmMsgCompletionCallback);
    23562318    }
    23572319
     
    23802342
    23812343    /* Forward the request to the main hgcm thread. */
    2382     HGCMMSGHANDLE hMsg = 0;
    2383 
    2384     int rc = hgcmMsgAlloc(g_pHgcmThread, &hMsg, HGCM_MSG_DISCONNECT, hgcmMainMessageAlloc);
     2344    HGCMMsgCore *pCoreMsg;
     2345    int rc = hgcmMsgAlloc(g_pHgcmThread, &pCoreMsg, HGCM_MSG_DISCONNECT, hgcmMainMessageAlloc);
    23852346
    23862347    if (RT_SUCCESS(rc))
    23872348    {
    23882349        /* Initialize the message. */
    2389         HGCMMsgMainDisconnect *pMsg = (HGCMMsgMainDisconnect *)hgcmObjReference(hMsg, HGCMOBJ_MSG);
    2390         AssertRelease(pMsg);
     2350        HGCMMsgMainDisconnect *pMsg = (HGCMMsgMainDisconnect *)pCoreMsg;
    23912351
    23922352        pMsg->pCmd        = pCmd;
     
    23942354        pMsg->u32ClientId = u32ClientId;
    23952355
    2396         hgcmObjDereference(pMsg);
    2397 
    2398         rc = hgcmMsgPost(hMsg, hgcmMsgCompletionCallback);
     2356        rc = hgcmMsgPost(pMsg, hgcmMsgCompletionCallback);
    23992357    }
    24002358
     
    24142372    LogFlowFunc(("pSSM = %p, u32MsgId = %d\n", pSSM, u32MsgId));
    24152373
    2416     HGCMMSGHANDLE hMsg = 0;
    2417 
    2418     int rc = hgcmMsgAlloc(g_pHgcmThread, &hMsg, u32MsgId, hgcmMainMessageAlloc);
     2374    HGCMMsgCore *pCoreMsg;
     2375    int rc = hgcmMsgAlloc(g_pHgcmThread, &pCoreMsg, u32MsgId, hgcmMainMessageAlloc);
    24192376
    24202377    if (RT_SUCCESS(rc))
    24212378    {
    2422         HGCMMsgMainLoadSaveState *pMsg = (HGCMMsgMainLoadSaveState *)hgcmObjReference(hMsg, HGCMOBJ_MSG);
     2379        HGCMMsgMainLoadSaveState *pMsg = (HGCMMsgMainLoadSaveState *)pCoreMsg;
    24232380        AssertRelease(pMsg);
    24242381
    24252382        pMsg->pSSM = pSSM;
    24262383
    2427         hgcmObjDereference(pMsg);
    2428 
    2429         rc = hgcmMsgSend(hMsg);
     2384        rc = hgcmMsgSend(pMsg);
    24302385    }
    24312386
     
    25212476    }
    25222477
    2523     HGCMMSGHANDLE hMsg = 0;
    2524 
    25252478    /* Host calls go to main HGCM thread that resolves the service name to the
    25262479     * service instance pointer and then, using the service pointer, forwards
     
    25292482     * other non-time-critical functions.
    25302483     */
    2531     int rc = hgcmMsgAlloc(g_pHgcmThread, &hMsg, HGCM_MSG_HOSTCALL, hgcmMainMessageAlloc);
     2484    HGCMMsgCore *pCoreMsg;
     2485    int rc = hgcmMsgAlloc(g_pHgcmThread, &pCoreMsg, HGCM_MSG_HOSTCALL, hgcmMainMessageAlloc);
    25322486
    25332487    if (RT_SUCCESS(rc))
    25342488    {
    2535         HGCMMsgMainHostCall *pMsg = (HGCMMsgMainHostCall *)hgcmObjReference(hMsg, HGCMOBJ_MSG);
    2536         AssertRelease(pMsg);
     2489        HGCMMsgMainHostCall *pMsg = (HGCMMsgMainHostCall *)pCoreMsg;
    25372490
    25382491        pMsg->pszServiceName = (char *)pszServiceName;
     
    25412494        pMsg->paParms        = paParms;
    25422495
    2543         hgcmObjDereference(pMsg);
    2544 
    2545         rc = hgcmMsgSend(hMsg);
     2496        rc = hgcmMsgSend(pMsg);
    25462497    }
    25472498
     
    25642515        return VERR_INVALID_PARAMETER;
    25652516    }
    2566 
    2567     HGCMMSGHANDLE hMsg = 0;
    25682517
    25692518    /* Host calls go to main HGCM thread that resolves the service name to the
     
    25732522     * other non-time-critical functions.
    25742523     */
    2575     int rc = hgcmMsgAlloc(g_pHgcmThread, &hMsg, HGCM_MSG_SVCAQUIRE, hgcmMainMessageAlloc);
     2524    HGCMMsgCore *pCoreMsg;
     2525    int rc = hgcmMsgAlloc(g_pHgcmThread, &pCoreMsg, HGCM_MSG_SVCAQUIRE, hgcmMainMessageAlloc);
    25762526
    25772527    if (RT_SUCCESS(rc))
    25782528    {
    2579         HGCMMsgMainSvcAcquire *pMsg = (HGCMMsgMainSvcAcquire *)hgcmObjReference(hMsg, HGCMOBJ_MSG);
    2580         AssertRelease(pMsg);
     2529        HGCMMsgMainSvcAcquire *pMsg = (HGCMMsgMainSvcAcquire *)pCoreMsg;
    25812530
    25822531        pMsg->pszServiceName = (char *)pszServiceName;
    25832532        pMsg->pService = NULL;
    25842533
    2585         rc = hgcmMsgSend(hMsg);
     2534        pMsg->Reference();
     2535
     2536        rc = hgcmMsgSend(pMsg);
    25862537        if (RT_SUCCESS(rc))
    25872538        {
     
    25892540            *phSvc = (HGCMCVSHANDLE)pMsg->pService;
    25902541        }
    2591 
    2592         hgcmObjDereference(pMsg);
     2542        pMsg->Dereference();
    25932543    }
    25942544
     
    26052555        return VERR_INVALID_PARAMETER;
    26062556    }
    2607 
    2608     HGCMMSGHANDLE hMsg = 0;
    26092557
    26102558    /* Host calls go to main HGCM thread that resolves the service name to the
     
    26142562     * other non-time-critical functions.
    26152563     */
    2616     int rc = hgcmMsgAlloc(g_pHgcmThread, &hMsg, HGCM_MSG_SVCRELEASE, hgcmMainMessageAlloc);
     2564    HGCMMsgCore *pCoreMsg;
     2565    int rc = hgcmMsgAlloc(g_pHgcmThread, &pCoreMsg, HGCM_MSG_SVCRELEASE, hgcmMainMessageAlloc);
    26172566
    26182567    if (RT_SUCCESS(rc))
    26192568    {
    2620         HGCMMsgMainSvcRelease *pMsg = (HGCMMsgMainSvcRelease *)hgcmObjReference(hMsg, HGCMOBJ_MSG);
    2621         AssertRelease(pMsg);
     2569        HGCMMsgMainSvcRelease *pMsg = (HGCMMsgMainSvcRelease *)pCoreMsg;
    26222570
    26232571        pMsg->pService = (HGCMService *)hSvc;
    26242572
    2625         hgcmObjDereference(pMsg);
    2626 
    2627         rc = hgcmMsgSend(hMsg);
     2573        rc = hgcmMsgSend(pMsg);
    26282574    }
    26292575
     
    26582604     */
    26592605
    2660     HGCMMSGHANDLE hMsg = 0;
    2661 
    2662     int rc = hgcmMsgAlloc(g_pHgcmThread, &hMsg, HGCM_MSG_RESET, hgcmMainMessageAlloc);
     2606    HGCMMsgCore *pMsg;
     2607    int rc = hgcmMsgAlloc(g_pHgcmThread, &pMsg, HGCM_MSG_RESET, hgcmMainMessageAlloc);
    26632608
    26642609    if (RT_SUCCESS(rc))
    2665     {
    2666         rc = hgcmMsgSend(hMsg);
    2667     }
     2610        rc = hgcmMsgSend(pMsg);
    26682611
    26692612    LogFlowFunc(("rc = %Rrc\n", rc));
     
    26862629
    26872630        if (RT_FAILURE(rc))
    2688         {
    26892631            LogRel(("Failed to start HGCM thread. HGCM services will be unavailable!!! rc = %Rrc\n", rc));
    2690         }
    26912632    }
    26922633
     
    27082649    {
    27092650        /* Send the quit message to the main hgcmThread. */
    2710         HGCMMSGHANDLE hMsg = 0;
    2711 
    2712         rc = hgcmMsgAlloc(g_pHgcmThread, &hMsg, HGCM_MSG_QUIT, hgcmMainMessageAlloc);
     2651        HGCMMsgCore *pMsg;
     2652        rc = hgcmMsgAlloc(g_pHgcmThread, &pMsg, HGCM_MSG_QUIT, hgcmMainMessageAlloc);
    27132653
    27142654        if (RT_SUCCESS(rc))
    27152655        {
    2716             rc = hgcmMsgSend(hMsg);
     2656            rc = hgcmMsgSend(pMsg);
    27172657
    27182658            if (RT_SUCCESS(rc))
     
    27202660                /* Wait for the thread termination. */
    27212661                hgcmThreadWait(g_pHgcmThread);
    2722                 g_pHgcmThread = 0;
     2662                g_pHgcmThread = NULL;
    27232663
    27242664                hgcmThreadUninit();
     
    27302670    return rc;
    27312671}
     2672
  • trunk/src/VBox/Main/src-client/HGCMObjects.cpp

    r75539 r75541  
    246246}
    247247
    248 void hgcmObjDereference(HGCMReferencedObject *pObject)
     248void hgcmObjDereference(HGCMObject *pObject)
    249249{
    250250    LogFlow(("MAIN::hgcmObjDereference: pObject %p\n", pObject));
  • trunk/src/VBox/Main/src-client/HGCMThread.cpp

    r75540 r75541  
    145145        int Initialize(const char *pszThreadName, PFNHGCMTHREAD pfnThread, void *pvUser, const char *pszStatsSubDir, PUVM pUVM);
    146146
    147         int MsgAlloc(HGCMMSGHANDLE *pHandle, uint32_t u32MsgId, PFNHGCMNEWMSGALLOC pfnNewMessage);
     147        int MsgAlloc(HGCMMsgCore **pMsg, uint32_t u32MsgId, PFNHGCMNEWMSGALLOC pfnNewMessage);
    148148        int MsgGet(HGCMMsgCore **ppMsg);
    149149        int MsgPost(HGCMMsgCore *pMsg, PHGCMMSGCALLBACK pfnCallback, bool bWait);
     
    364364
    365365
    366 int HGCMThread::MsgAlloc(HGCMMSGHANDLE *pHandle, uint32_t u32MsgId, PFNHGCMNEWMSGALLOC pfnNewMessage)
     366int HGCMThread::MsgAlloc(HGCMMsgCore **ppMsg, uint32_t u32MsgId, PFNHGCMNEWMSGALLOC pfnNewMessage)
    367367{
    368368    /** @todo  Implement this free list / cache thingy.   */
     
    375375        /* We have to allocate a new memory block. */
    376376        pmsg = pfnNewMessage(u32MsgId);
    377 
    378         if (pmsg == NULL)
     377        if (pmsg != NULL)
     378            pmsg->Reference(); /* (it's created with zero references) */
     379        else
    379380            return VERR_NO_MEMORY;
    380381    }
     
    388389    LogFlow(("MAIN::hgcmMsgAlloc: allocated message %p\n", pmsg));
    389390
    390     /** Get handle of the message. The message will be also referenced
    391      *  until the handle is deleted.
    392      */
    393     *pHandle = hgcmObjGenerateHandle(pmsg);
     391    *ppMsg = pmsg;
    394392
    395393    if (fFromFreeList)
     
    558556}
    559557
    560 void HGCMThread::MsgComplete (HGCMMsgCore *pMsg, int32_t result)
     558void HGCMThread::MsgComplete(HGCMMsgCore *pMsg, int32_t result)
    561559{
    562560    LogFlow(("HGCMThread::MsgComplete: thread = %p, pMsg = %p\n", this, pMsg));
     
    610608        pMsg->m_fu32Flags |= HGCM_MSG_F_PROCESSED;
    611609
    612         hgcmObjDeleteHandle(pMsg->Handle());
     610        pMsg->Dereference();
    613611
    614612        Leave();
     
    681679}
    682680
    683 int hgcmMsgAlloc(HGCMThread *pThread, HGCMMSGHANDLE *pHandle, uint32_t u32MsgId, PFNHGCMNEWMSGALLOC pfnNewMessage)
    684 {
    685     LogFlow(("hgcmMsgAlloc: pThread = %p, pHandle = %p, sizeof (HGCMMsgCore) = %d\n",
    686              pThread, pHandle, sizeof (HGCMMsgCore)));
     681int hgcmMsgAlloc(HGCMThread *pThread, HGCMMsgCore **ppMsg, uint32_t u32MsgId, PFNHGCMNEWMSGALLOC pfnNewMessage)
     682{
     683    LogFlow(("hgcmMsgAlloc: pThread = %p, ppMsg = %p, sizeof (HGCMMsgCore) = %d\n", pThread, ppMsg, sizeof(HGCMMsgCore)));
    687684
    688685    AssertReturn(pThread, VERR_INVALID_HANDLE);
    689     AssertReturn(pHandle, VERR_INVALID_PARAMETER);
    690 
    691     int rc = pThread->MsgAlloc(pHandle, u32MsgId, pfnNewMessage);
    692 
    693     LogFlow(("MAIN::hgcmMsgAlloc: handle 0x%08X, rc = %Rrc\n", *pHandle, rc));
    694     return rc;
    695 }
    696 
    697 static int hgcmMsgPostInternal(HGCMMSGHANDLE hMsg, PHGCMMSGCALLBACK pfnCallback, bool fWait)
    698 {
    699     LogFlow(("MAIN::hgcmMsgPostInternal: hMsg = 0x%08X, pfnCallback = %p, fWait = %d\n", hMsg, pfnCallback, fWait));
    700 
    701     int rc = VINF_SUCCESS;
    702 
    703     HGCMMsgCore *pMsg = (HGCMMsgCore *)hgcmObjReference(hMsg, HGCMOBJ_MSG);
    704 
    705     if (!pMsg)
    706     {
    707         rc = VERR_INVALID_HANDLE;
    708     }
    709     else
    710     {
    711         rc = pMsg->Thread()->MsgPost(pMsg, pfnCallback, fWait);
    712 
    713         hgcmObjDereference(pMsg);
    714     }
    715 
    716     LogFlow(("MAIN::hgcmMsgPostInternal: hMsg 0x%08X, rc = %Rrc\n", hMsg, rc));
    717     return rc;
    718 }
    719 
    720 
    721 /** Post message to worker thread with a flag indication if this is a Send or Post.
    722  *
    723  * @returns VINF_HGCM_ASYNC_EXECUTE
    724  * @thread any
    725  */
    726 int hgcmMsgPost(HGCMMSGHANDLE hMsg, PHGCMMSGCALLBACK pfnCallback)
    727 {
    728     int rc = hgcmMsgPostInternal(hMsg, pfnCallback, false);
     686    AssertReturn(ppMsg, VERR_INVALID_PARAMETER);
     687
     688    int rc = pThread->MsgAlloc(ppMsg, u32MsgId, pfnNewMessage);
     689
     690    LogFlow(("MAIN::hgcmMsgAlloc: *ppMsg = %p, rc = %Rrc\n", *ppMsg, rc));
     691    return rc;
     692}
     693
     694DECLINLINE(int) hgcmMsgPostInternal(HGCMMsgCore *pMsg, PHGCMMSGCALLBACK pfnCallback, bool fWait)
     695{
     696    LogFlow(("MAIN::hgcmMsgPostInternal: pMsg = %p, pfnCallback = %p, fWait = %d\n", pMsg, pfnCallback, fWait));
     697    Assert(pMsg);
     698
     699    pMsg->Reference(); /* paranoia? */
     700
     701    int rc = pMsg->Thread()->MsgPost(pMsg, pfnCallback, fWait);
     702
     703    pMsg->Dereference();
     704
     705    LogFlow(("MAIN::hgcmMsgPostInternal: pMsg %p, rc = %Rrc\n", pMsg, rc));
     706    return rc;
     707}
     708
     709int hgcmMsgPost(HGCMMsgCore *pMsg, PHGCMMSGCALLBACK pfnCallback)
     710{
     711    int rc = hgcmMsgPostInternal(pMsg, pfnCallback, false);
    729712
    730713    if (RT_SUCCESS(rc))
     
    734717}
    735718
    736 /** Send message to worker thread. Sending thread will block until message is processed.
    737  *
    738  * @thread any
    739  */
    740 int hgcmMsgSend (HGCMMSGHANDLE hMsg)
    741 {
    742     return hgcmMsgPostInternal (hMsg, NULL, true);
    743 }
    744 
     719int hgcmMsgSend(HGCMMsgCore *pMsg)
     720{
     721    return hgcmMsgPostInternal(pMsg, NULL, true);
     722}
    745723
    746724int hgcmMsgGet(HGCMThread *pThread, HGCMMsgCore **ppMsg)
     
    761739}
    762740
    763 
    764741void hgcmMsgComplete(HGCMMsgCore *pMsg, int32_t u32Result)
    765742{
     
    773750}
    774751
    775 
    776752int hgcmThreadInit(void)
    777753{
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