MCPcopy Create free account
hub / github.com/OpenNI/OpenNI / xnUSBShutdownReadThread

Function xnUSBShutdownReadThread

Source/OpenNI/Win32/XnUSBWin32.cpp:1555–1618  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1553}
1554
1555XN_C_API XnStatus xnUSBShutdownReadThread(XN_USB_EP_HANDLE pEPHandle)
1556{
1557 // Local variables
1558 XnStatus nRetVal = XN_STATUS_OK;
1559 xnUSBReadThreadData* pThreadData = NULL;
1560
1561 // Validate xnUSB
1562 XN_VALIDATE_USB_INIT();
1563 XN_VALIDATE_USB_PEP_HANDLE(pEPHandle);
1564
1565 // Dereference the ThreadData
1566 pThreadData = &pEPHandle->ThreadData;
1567
1568 // Make sure that this EP has a read thread active
1569 if (pThreadData->bInUse == FALSE)
1570 {
1571 return (XN_STATUS_USB_READTHREAD_NOT_INIT);
1572 }
1573
1574 // Make sure that the read thread is alive
1575 if (pThreadData->hReadThread != NULL)
1576 {
1577 // Request for the read thread to die
1578 pThreadData->bKillReadThread = TRUE;
1579
1580 // close thread
1581 xnOSWaitAndTerminateThread(&pThreadData->hReadThread, XN_USB_READ_THREAD_KILL_TIMEOUT);
1582
1583 pThreadData->hReadThread = NULL;
1584 }
1585
1586 // Free any buffers and events if necessary...
1587 if (pThreadData->pBuffersInfo != NULL)
1588 {
1589 for (XnUInt32 nBufIdx = 0; nBufIdx < pThreadData->nNumBuffers; nBufIdx++)
1590 {
1591 if (pThreadData->pOvlpIO[nBufIdx].hEvent != NULL)
1592 {
1593 xnOSCloseEvent(&pThreadData->pOvlpIO[nBufIdx].hEvent);
1594 }
1595
1596 if (pThreadData->pBuffersInfo[nBufIdx].pBuffer != NULL)
1597 {
1598 XN_ALIGNED_FREE_AND_NULL(pThreadData->pBuffersInfo[nBufIdx].pBuffer);
1599 }
1600 }
1601
1602 XN_ALIGNED_FREE_AND_NULL(pThreadData->pBuffersInfo);
1603 XN_ALIGNED_FREE_AND_NULL(pThreadData->pOvlpIO);
1604 }
1605
1606 // Re-init the overlapped I/O structs (they cannot be reused because of completion I/O port)
1607 nRetVal = xnUSBInitOvlp(pEPHandle);
1608 if (nRetVal != XN_STATUS_OK)
1609 {
1610 return (XN_STATUS_USB_READTHREAD_SHUTDOWN_FAILED);
1611 }
1612

Callers

nothing calls this directly

Calls 3

xnUSBInitOvlpFunction · 0.85
xnOSCloseEventFunction · 0.70

Tested by

no test coverage detected