VirtualBox

Changeset 4993 in vbox for trunk/src


Ignore:
Timestamp:
Sep 24, 2007 9:02:26 AM (17 years ago)
Author:
vboxsync
Message:

HostSerial: Use pipe for the receive thread to wake it up on shutdown on linux hosts

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Devices/Serial/DrvHostSerial.cpp

    r4928 r4993  
    8181    RTSEMEVENT                  SendSem;
    8282
     83#ifdef RT_OS_LINUX
     84    /** The receive thread wakeup pipe. */
     85    RTFILE                      WakeupPipeR;
     86    RTFILE                      WakeupPipeW;
     87#endif
     88
    8389    /** the device path */
    8490    char                        *pszDevicePath;
     
    100106#define PDMICHAR_2_DRVHOSTSERIAL(pInterface) ( (PDRVHOSTSERIAL)((uintptr_t)pInterface - RT_OFFSETOF(DRVHOSTSERIAL, IChar)) )
    101107
    102 
     108#ifdef RT_OS_LINUX
     109/** String written to the wakeup pipe. */
     110#define WAKE_UP_STRING      "WakeUp!"
     111/** Length of the string written. */
     112#define WAKE_UP_STRING_LEN  ( sizeof (WAKE_UP_STRING) - 1 )
     113#endif
    103114/* -=-=-=-=- IBase -=-=-=-=- */
    104115
     
    445456
    446457#ifdef RT_OS_LINUX
    447             struct pollfd pfd;
    448 
    449             pfd.fd = pData->DeviceFile;
    450             pfd.events = POLLIN;
    451 
    452             rc = poll(&pfd, 1, -1);
     458            struct pollfd pfd[2];
     459
     460            pfd[0].fd = pData->DeviceFile;
     461            pfd[0].events = POLLIN;
     462            pfd[1].fd = pData->WakeupPipeR;
     463            pfd[1].events = POLLIN | POLLERR | POLLHUP;
     464
     465            rc = poll(&pfd[0], 2, -1);
     466
    453467            if (rc < 0)
    454468                break;
     469
     470            if (rc > 0)
     471            {
     472                if (pfd[1].revents & POLLIN)
     473                {
     474                    /* Empty the pipe. */
     475                    char szBuf[WAKE_UP_STRING_LEN];
     476                    rc = RTFileRead (pData->WakeupPipeR, szBuf, sizeof (szBuf), NULL);
     477                    AssertRC (rc);
     478                    break;
     479                }
     480            }
    455481#elif defined(RT_OS_WINDOWS)
    456482            BOOL retval;
     
    523549{
    524550    PDRVHOSTSERIAL pData = PDMINS2DATA(pDrvIns, PDRVHOSTSERIAL);
     551#ifdef RT_OS_LINUX
     552    int filedes[2];
     553#endif
     554
    525555    LogFlow(("%s: iInstance=%d\n", __FUNCTION__, pDrvIns->iInstance));
    526556
     
    579609#ifdef RT_OS_LINUX
    580610    fcntl(pData->DeviceFile, F_SETFL, O_NONBLOCK);
     611    /* Create the wakeup pipe. */
     612    if (!pipe(filedes))
     613    {
     614        pData->WakeupPipeR = filedes[0];
     615        pData->WakeupPipeW = filedes[1];
     616    }
    581617#elif defined(RT_OS_WINDOWS)
    582618    /* Set the COMMTIMEOUTS to get non blocking I/O */
     
    629665{
    630666    PDRVHOSTSERIAL     pData = PDMINS2DATA(pDrvIns, PDRVHOSTSERIAL);
     667    int rc;
    631668
    632669    LogFlow(("%s: iInstance=%d\n", __FUNCTION__, pDrvIns->iInstance));
    633670
    634671    ASMAtomicXchgBool(&pData->fShutdown, true);
     672
     673#ifdef RT_OS_LINUX
     674    /* Notify the receive thread that we want to shutdown. */
     675    rc = RTFileWrite (pData->WakeupPipeW, WAKE_UP_STRING, WAKE_UP_STRING_LEN, NULL);
     676    if (VBOX_SUCCESS (rc))
     677        RTFileFlush (pData->WakeupPipeW);
     678#endif
    635679    if (pData->ReceiveThread != NIL_RTTHREAD)
    636680    {
    637         int rc = RTThreadWait(pData->ReceiveThread, 15000, NULL);
     681        rc = RTThreadWait(pData->ReceiveThread, 15000, NULL);
    638682        if (RT_FAILURE(rc))
    639683            LogRel(("HostSerial%d: receive thread did not terminate (rc=%Rrc)\n", pDrvIns->iInstance, rc));
     
    655699        pData->SendThread = NIL_RTTHREAD;
    656700    }
     701
     702#ifdef RT_OS_LINUX
     703    RTFileClose(pData->WakeupPipeR);
     704    RTFileClose(pData->WakeupPipeW);
     705#endif
     706
     707    RTFileClose(pData->DeviceFile);
    657708}
    658709
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