VirtualBox

Changeset 4455 in vbox for trunk


Ignore:
Timestamp:
Aug 30, 2007 9:57:57 PM (17 years ago)
Author:
vboxsync
Message:

Fixed PDMTHREAD::Thread initialiation race, the new thread might finish before it was set by EMT.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/VMM/PDMThread.cpp

    r4421 r4455  
    6464            rc = pThread->u.Dev.pfnWakeUp(pThread->u.Dev.pDevIns, pThread);
    6565            break;
    66            
     66
    6767        case PDMTHREADTYPE_USB:
    6868            rc = pThread->u.Usb.pfnWakeUp(pThread->u.Usb.pUsbIns, pThread);
     
    140140        /*
    141141         * Create the thread and wait for it to initialize.
     142         * The newly created thread will set the PDMTHREAD::Thread member.
    142143         */
    143         rc = RTThreadCreate(&pThread->Thread, pdmR3ThreadMain, pThread, cbStack, enmType, RTTHREADFLAGS_WAITABLE, pszName);
     144        RTTHREAD Thread;
     145        rc = RTThreadCreate(&Thread, pdmR3ThreadMain, pThread, cbStack, enmType, RTTHREADFLAGS_WAITABLE, pszName);
    144146        if (RT_SUCCESS(rc))
    145147        {
    146             rc = RTThreadUserWait(pThread->Thread, 60*1000);
     148            rc = RTThreadUserWait(Thread, 60*1000);
    147149            if (    RT_SUCCESS(rc)
    148150                &&  pThread->enmState != PDMTHREADSTATE_SUSPENDED)
     
    160162                pVM->pdm.s.pThreadsTail = pThread;
    161163
    162                 rc = RTThreadUserReset(pThread->Thread);
     164                rc = RTThreadUserReset(Thread);
    163165                AssertRC(rc);
    164166                return rc;
     
    166168
    167169            /* bailout */
    168             RTThreadWait(pThread->Thread, 60*1000, NULL);
     170            RTThreadWait(Thread, 60*1000, NULL);
    169171        }
    170172        RTSemEventMultiDestroy(pThread->Internal.s.BlockEvent);
     
    180182/**
    181183 * Device Helper for creating a thread associated with a device.
    182  * 
    183  * @returns VBox status code.
    184  * @param   pVM         The VM handle. 
     184 *
     185 * @returns VBox status code.
     186 * @param   pVM         The VM handle.
    185187 * @param   pDevIns     The device instance.
    186188 * @param   ppThread    Where to store the thread 'handle'.
     
    212214/**
    213215 * USB Device Helper for creating a thread associated with an USB device.
    214  * 
    215  * @returns VBox status code.
    216  * @param   pVM         The VM handle. 
     216 *
     217 * @returns VBox status code.
     218 * @param   pVM         The VM handle.
    217219 * @param   pUsbIns     The USB device instance.
    218220 * @param   ppThread    Where to store the thread 'handle'.
     
    244246/**
    245247 * Driver Helper for creating a thread associated with a driver.
    246  * 
    247  * @returns VBox status code.
    248  * @param   pVM         The VM handle. 
     248 *
     249 * @returns VBox status code.
     250 * @param   pVM         The VM handle.
    249251 * @param   pDrvIns     The driver instance.
    250252 * @param   ppThread    Where to store the thread 'handle'.
     
    276278/**
    277279 * Creates a PDM thread for internal use in the VM.
    278  * 
    279  * @returns VBox status code.
    280  * @param   pVM         The VM handle. 
     280 *
     281 * @returns VBox status code.
     282 * @param   pVM         The VM handle.
    281283 * @param   ppThread    Where to store the thread 'handle'.
    282284 * @param   pvUser      The user argument to the thread function.
     
    306308/**
    307309 * Creates a PDM thread for VM use by some external party.
    308  * 
    309  * @returns VBox status code.
    310  * @param   pVM         The VM handle. 
     310 *
     311 * @returns VBox status code.
     312 * @param   pVM         The VM handle.
    311313 * @param   ppThread    Where to store the thread 'handle'.
    312314 * @param   pvUser      The user argument to the thread function.
     
    442444 * Destroys all threads associated with a device.
    443445 *
    444  * This function is called by PDMDevice when a device is 
     446 * This function is called by PDMDevice when a device is
    445447 * destroyed (not currently implemented).
    446  * 
     448 *
    447449 * @returns VBox status code of the first failure.
    448450 * @param   pVM         The VM handle.
     
    476478 *
    477479 * This function is called by PDMUsb when a device is destroyed.
    478  * 
     480 *
    479481 * @returns VBox status code of the first failure.
    480482 * @param   pVM         The VM handle.
     
    508510 *
    509511 * This function is called by PDMDriver when a driver is destroyed.
    510  * 
     512 *
    511513 * @returns VBox status code of the first failure.
    512514 * @param   pVM         The VM handle.
     
    686688    PPDMTHREAD pThread = (PPDMTHREAD)pvUser;
    687689    Log(("PDMThread: Initializing thread %RTthrd / %p / '%s'...\n", Thread, pThread, RTThreadGetName(Thread)));
     690    pThread->Thread = Thread;
    688691
    689692    /*
     
    820823 * PDM thread a bit early. The thread will be automatically suspend upon
    821824 * completion of the device/driver notification cycle.
    822  * 
     825 *
    823826 * The caller is responsible for serializing the control operations on the
    824827 * thread. That basically means, always do these calls from the EMT.
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