VirtualBox

Changeset 82209 in vbox


Ignore:
Timestamp:
Nov 25, 2019 11:50:16 PM (5 years ago)
Author:
vboxsync
Message:

GIMDev: Corrected method order (dtor before ctor), eliminated unnecessary pDevInsR? members. bugref:9218

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Devices/GIMDev/GIMDev.cpp

    r81591 r82209  
    2929#include <iprt/uuid.h>
    3030
     31
     32/*********************************************************************************************************************************
     33*   Defined Constants And Macros                                                                                                 *
     34*********************************************************************************************************************************/
    3135#define GIMDEV_DEBUG_LUN                998
    3236
     37
     38/*********************************************************************************************************************************
     39*   Structures and Typedefs                                                                                                      *
     40*********************************************************************************************************************************/
    3341/**
    3442 * GIM device.
     
    3644typedef struct GIMDEV
    3745{
    38     /** Pointer to the device instance - R3 Ptr. */
    39     PPDMDEVINSR3                    pDevInsR3;
    40     /** Pointer to the device instance - R0 Ptr. */
    41     PPDMDEVINSR0                    pDevInsR0;
    42     /** Pointer to the device instance - RC Ptr. */
    43     PPDMDEVINSRC                    pDevInsRC;
    44     /** Alignment. */
    45     RTRCPTR                         Alignment0;
     46    /** Pointer to the device instance.
     47     * @note Only for getting our bearings when arriving in an interface method. */
     48    PPDMDEVINSR3                    pDevIns;
    4649
    4750    /** LUN\#998: The debug interface. */
     
    5558    /** Flag to indicate shutdown of the debug receive thread. */
    5659    bool volatile                   fDbgRecvThreadShutdown;
     60    bool                            afAlignment1[ARCH_BITS / 8 - 1];
    5761    /** The debug setup parameters. */
    5862    GIMDEBUGSETUP                   DbgSetup;
     
    196200
    197201/**
     202 * @interface_method_impl{PDMDEVREG,pfnDestruct}
     203 */
     204static DECLCALLBACK(int) gimdevR3Destruct(PPDMDEVINS pDevIns)
     205{
     206    PDMDEV_CHECK_VERSIONS_RETURN_QUIET(pDevIns);
     207    PGIMDEV  pThis    = PDMDEVINS_2_DATA(pDevIns, PGIMDEV);
     208    PVM      pVM      = PDMDevHlpGetVM(pDevIns);
     209
     210    uint32_t cRegions = 0;
     211    PGIMMMIO2REGION pCur = GIMR3GetMmio2Regions(pVM, &cRegions);
     212    for (uint32_t i = 0; i < cRegions; i++, pCur++)
     213    {
     214        int rc = PDMDevHlpMMIOExDeregister(pDevIns, NULL, pCur->iRegion);
     215        if (RT_FAILURE(rc))
     216            return rc;
     217    }
     218
     219    /*
     220     * Signal and wait for the debug thread to terminate.
     221     */
     222    if (pThis->hDbgRecvThread != NIL_RTTHREAD)
     223    {
     224        pThis->fDbgRecvThreadShutdown = true;
     225        if (pThis->Dbg.hDbgRecvThreadSem != NIL_RTSEMEVENT)
     226            RTSemEventMultiSignal(pThis->Dbg.hDbgRecvThreadSem);
     227
     228        int rc = RTThreadWait(pThis->hDbgRecvThread, 20000, NULL /*prc*/);
     229        if (RT_SUCCESS(rc))
     230            pThis->hDbgRecvThread = NIL_RTTHREAD;
     231        else
     232        {
     233            LogRel(("GIMDev: Debug thread did not terminate, rc=%Rrc!\n", rc));
     234            return VERR_RESOURCE_BUSY;
     235        }
     236    }
     237
     238    /*
     239     * Now clean up the semaphore & buffer now that the thread is gone.
     240     */
     241    if (pThis->Dbg.hDbgRecvThreadSem != NIL_RTSEMEVENT)
     242    {
     243        RTSemEventMultiDestroy(pThis->Dbg.hDbgRecvThreadSem);
     244        pThis->Dbg.hDbgRecvThreadSem = NIL_RTSEMEVENTMULTI;
     245    }
     246    if (pThis->Dbg.pvDbgRecvBuf)
     247    {
     248        RTMemFree(pThis->Dbg.pvDbgRecvBuf);
     249        pThis->Dbg.pvDbgRecvBuf = NULL;
     250    }
     251
     252    return VINF_SUCCESS;
     253}
     254
     255
     256/**
    198257 * @interface_method_impl{PDMDEVREG,pfnConstruct}
    199258 */
     
    208267     * Initialize relevant state bits.
    209268     */
    210     pThis->pDevInsR3  = pDevIns;
    211     pThis->pDevInsR0  = PDMDEVINS_2_R0PTR(pDevIns);
    212     pThis->pDevInsRC  = PDMDEVINS_2_RCPTR(pDevIns);
     269    pThis->pDevIns                  = pDevIns;
     270    pThis->hDbgRecvThread           = NIL_RTTHREAD;
     271    pThis->Dbg.hDbgRecvThreadSem    = NIL_RTSEMEVENT;
    213272
    214273    /*
     
    266325
    267326        /*
    268          * Create the sempahore and the debug receive thread itself.
     327         * Create the semaphore and the debug receive thread itself.
    269328         */
    270329        rc = RTSemEventMultiCreate(&pThis->Dbg.hDbgRecvThreadSem);
    271         if (RT_SUCCESS(rc))
    272         {
    273             rc = RTThreadCreate(&pThis->hDbgRecvThread, gimDevR3DbgRecvThread, pDevIns, 0 /*cbStack*/, RTTHREADTYPE_IO,
    274                                 RTTHREADFLAGS_WAITABLE, "GIMDebugRecv");
    275             if (RT_FAILURE(rc))
    276             {
    277                 RTSemEventMultiDestroy(pThis->Dbg.hDbgRecvThreadSem);
    278                 pThis->Dbg.hDbgRecvThreadSem = NIL_RTSEMEVENTMULTI;
    279 
    280                 RTMemFree(pThis->Dbg.pvDbgRecvBuf);
    281                 pThis->Dbg.pvDbgRecvBuf = NULL;
    282                 return rc;
    283             }
    284         }
    285         else
     330        AssertRCReturn(rc, rc);
     331        rc = RTThreadCreate(&pThis->hDbgRecvThread, gimDevR3DbgRecvThread, pDevIns, 0 /*cbStack*/, RTTHREADTYPE_IO,
     332                            RTTHREADFLAGS_WAITABLE, "GIMDebugRecv");
     333        if (RT_FAILURE(rc))
     334        {
     335            RTSemEventMultiDestroy(pThis->Dbg.hDbgRecvThreadSem);
     336            pThis->Dbg.hDbgRecvThreadSem = NIL_RTSEMEVENTMULTI;
     337
     338            RTMemFree(pThis->Dbg.pvDbgRecvBuf);
     339            pThis->Dbg.pvDbgRecvBuf = NULL;
    286340            return rc;
     341        }
    287342    }
    288343
     
    351406}
    352407
    353 
    354 /**
    355  * @interface_method_impl{PDMDEVREG,pfnDestruct}
    356  */
    357 static DECLCALLBACK(int) gimdevR3Destruct(PPDMDEVINS pDevIns)
    358 {
    359     PGIMDEV  pThis    = PDMDEVINS_2_DATA(pDevIns, PGIMDEV);
    360     PVM      pVM      = PDMDevHlpGetVM(pDevIns);
    361     uint32_t cRegions = 0;
    362 
    363     PGIMMMIO2REGION pCur = GIMR3GetMmio2Regions(pVM, &cRegions);
    364     for (uint32_t i = 0; i < cRegions; i++, pCur++)
    365     {
    366         int rc = PDMDevHlpMMIOExDeregister(pDevIns, NULL, pCur->iRegion);
    367         if (RT_FAILURE(rc))
    368             return rc;
    369     }
    370 
    371     /*
    372      * Signal and wait for the debug thread to terminate.
    373      */
    374     if (pThis->hDbgRecvThread != NIL_RTTHREAD)
    375     {
    376         pThis->fDbgRecvThreadShutdown = true;
    377         if (pThis->Dbg.hDbgRecvThreadSem != NIL_RTSEMEVENT)
    378             RTSemEventMultiSignal(pThis->Dbg.hDbgRecvThreadSem);
    379 
    380         int rc = RTThreadWait(pThis->hDbgRecvThread, 20000, NULL /*prc*/);
    381         if (RT_SUCCESS(rc))
    382             pThis->hDbgRecvThread = NIL_RTTHREAD;
    383         else
    384         {
    385             LogRel(("GIMDev: Debug thread did not terminate, rc=%Rrc!\n", rc));
    386             return VERR_RESOURCE_BUSY;
    387         }
    388     }
    389 
    390     /*
    391      * Now clean up the semaphore & buffer now that the thread is gone.
    392      */
    393     if (pThis->Dbg.hDbgRecvThreadSem != NIL_RTSEMEVENT)
    394     {
    395         RTSemEventMultiDestroy(pThis->Dbg.hDbgRecvThreadSem);
    396         pThis->Dbg.hDbgRecvThreadSem = NIL_RTSEMEVENTMULTI;
    397     }
    398     if (pThis->Dbg.pvDbgRecvBuf)
    399     {
    400         RTMemFree(pThis->Dbg.pvDbgRecvBuf);
    401         pThis->Dbg.pvDbgRecvBuf = NULL;
    402     }
    403 
    404     return VINF_SUCCESS;
    405 }
    406408
    407409#endif /* IN_RING3 */
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