VirtualBox

Changeset 1778 in vbox


Ignore:
Timestamp:
Mar 28, 2007 3:17:57 PM (18 years ago)
Author:
vboxsync
Message:

Clean up listen thread properly.

File:
1 edited

Legend:

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

    r1777 r1778  
    3737#include <iprt/alloc.h>
    3838#include <iprt/string.h>
     39#include <iprt/semaphore.h>
    3940
    4041#include "Builtins.h"
     
    8384    /* Overlapped structure for reads. */
    8485    OVERLAPPED          OverlappedRead;
     86    /* Listen thread wakeup semaphore */
     87    RTSEMEVENT          ListenSem;
    8588#else /* !__WIN__ */
    8689    /** Socket handle of the local socket for server. */
     
    356359            if (hrc == ERROR_PIPE_CONNECTED)
    357360            {
    358                 RTThreadSleep(250);
     361                RTSemEventWait(pData->ListenSem, 250);
    359362            }
    360363            else
     
    396399    CloseHandle(hEvent);
    397400#endif
     401    pData->ListenThread = NIL_RTTHREAD;
    398402    return VINF_SUCCESS;
    399403}
     
    474478        if VBOX_FAILURE(rc)
    475479            return PDMDrvHlpVMSetError(pDrvIns, rc,  RT_SRC_POS, N_("NamedPipe#%d failed to create listening thread\n"), pDrvIns->iInstance);
     480
     481        rc = RTSemEventCreate(&pData->ListenSem);
     482        AssertRC(rc);
    476483    }
    477484    else
     
    487494    pData->OverlappedWrite.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
    488495    pData->OverlappedRead.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
    489 
    490496#else /* !__WIN__ */
    491497    int s;
     
    561567        CloseHandle(pData->OverlappedWrite.hEvent);
    562568    }
     569    /* Wake up listen thread */
     570    RTSemEventSignal(pData->ListenSem);
     571    RTSemEventDestroy(pData->ListenSem);
    563572#else /* !__WIN__ */
    564573    if (pData->fIsServer)
     
    575584    }
    576585#endif /* !__WIN__ */
     586
     587    if (pData->ListenThread)
     588    {
     589        RTThreadWait(pData->ListenThread, 250, NULL);
     590        if (pData->ListenThread != NIL_RTTHREAD)
     591            LogRel(("NamedPipe%d: listen thread did not terminate\n", pDrvIns->iInstance));
     592    }
     593
    577594    if (pData->pszLocation)
    578595        MMR3HeapFree(pData->pszLocation);
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