void XnServerSensorInvoker::Free() { m_bShouldRun = FALSE; if (m_hReaderThread != NULL) { xnOSWaitAndTerminateThread(&m_hReaderThread, XN_SENSOR_TERMINATE_READER_THREAD_TIMEOUT); m_hReaderThread = NULL; } XnStatus nRetVal = m_sensor.Destroy(); if (nRetVal != XN_STATUS_OK) { xnLogWarning(XN_MASK_SENSOR_SERVER, "Failed to destroy sensor: %s", xnGetStatusString(nRetVal)); XN_ASSERT(FALSE); } if (m_hNewDataEvent != NULL) { xnOSCloseEvent(&m_hNewDataEvent); m_hNewDataEvent = NULL; } if (m_hSensorLock != NULL) { xnOSCloseCriticalSection(&m_hSensorLock); m_hSensorLock = NULL; } }
void XnServerSession::Free() { if (m_hThread != NULL) { xnOSWaitAndTerminateThread(&m_hThread, 2000); m_hThread = NULL; } if (m_hStreamsLock != NULL) { xnOSCloseCriticalSection(&m_hStreamsLock); m_hStreamsLock = NULL; } if (m_hCommLock != NULL) { xnOSCloseCriticalSection(&m_hCommLock); m_hCommLock = NULL; } if (m_pStreamDataSet != NULL) { XnStreamDataSetDestroy(&m_pStreamDataSet); m_pStreamDataSet = NULL; } if (m_hSocket != NULL) { xnOSCloseSocket(m_hSocket); m_hSocket = NULL; } m_privateIncomingPacker.Free(); m_privateOutgoingPacker.Free(); }
XnStatus xnUSBPlatformSpecificShutdown() { g_bUsbDevDetectShoudRun = FALSE; xnOSWaitAndTerminateThread(&g_xnUsbhPnThread, 5000); UnregisterClass((LPCSTR)g_xnClass, (HINSTANCE)g_xnUsbhModule); return (XN_STATUS_OK); }
void SocketInConnection::Disconnect() { XnStatus nRetVal = XN_STATUS_OK; if (m_hReadThread != NULL) { m_bStopReadThread = TRUE; //Signal read thread to stop running nRetVal = xnOSWaitAndTerminateThread(&m_hReadThread, READ_THREAD_TERMINATE_TIMEOUT); if (nRetVal != XN_STATUS_OK) { xnLogWarning("Failed to terminate input socket read thread: %s", xnGetStatusString(nRetVal)); XN_ASSERT(FALSE); } m_bStopReadThread = FALSE; } }
XnStatus XnSensorClient::Destroy() { XnStatus nRetVal = XN_STATUS_OK; if (m_hSocket != NULL) { nRetVal = SendBye(); if (nRetVal != XN_STATUS_OK) { xnLogWarning(XN_MASK_SENSOR_CLIENT, "Failed to send BYE to the server - %s", xnGetStatusString(nRetVal)); //But we keep going - we must destroy our object. } //Signal to the listener thread that it should stop running m_bShouldRun = FALSE; m_bConnected = FALSE; } if (m_hListenThread != NULL) { xnOSWaitAndTerminateThread(&m_hListenThread, XN_SENSOR_CLIENT_TERMINATE_THREAD_TIMEOUT); m_hListenThread = NULL; } // now destroy it all XnStreamReaderDevice::Destroy(); if (m_hReplyEvent != NULL) { xnOSCloseEvent(&m_hReplyEvent); m_hReplyEvent = NULL; } XN_DELETE(m_pOutgoingPacker); if (m_hLock != NULL) { xnOSCloseCriticalSection(&m_hLock); m_hLock = NULL; } return XN_STATUS_OK; }
XN_C_API XnStatus xnProfilingShutdown() { if (g_ProfilingData.hThread != NULL) { g_ProfilingData.bKillThread = TRUE; xnLogVerbose(XN_MASK_PROFILING, "Shutting down Profiling thread..."); xnOSWaitAndTerminateThread(&g_ProfilingData.hThread, g_ProfilingData.nProfilingInterval * 2); g_ProfilingData.hThread = NULL; } if (g_ProfilingData.hCriticalSection != NULL) { xnOSCloseCriticalSection(&g_ProfilingData.hCriticalSection); g_ProfilingData.hCriticalSection = NULL; } XN_FREE_AND_NULL(g_ProfilingData.aSections); g_ProfilingData.bInitialized = FALSE; return XN_STATUS_OK; }
void FreeScheduler(XnScheduler* pScheduler) { // stop thread if (pScheduler->hThread) { // mark for thread to stop pScheduler->bStopThread = TRUE; if (pScheduler->hWakeThreadEvent) { xnOSSetEvent(pScheduler->hWakeThreadEvent); } // now wait for it to exit xnLogVerbose(XN_MASK_SCHEDULER, "Shutting down Scheduler thread..."); xnOSWaitAndTerminateThread(&pScheduler->hThread, XN_SCHEDULER_WAIT_THREAD_EXIT_TIMEOUT); } if (pScheduler->hWakeThreadEvent) { xnOSCloseEvent(&pScheduler->hWakeThreadEvent); } if (pScheduler->hCriticalSection) { xnOSCloseCriticalSection(&pScheduler->hCriticalSection); } while (pScheduler->pFirst != NULL) { XnScheduledTask* pTask = pScheduler->pFirst; pScheduler->pFirst = pTask->pNextTask; xnOSFree(pTask); } xnOSFree(pScheduler); }
XnStatus xnUSBPlatformSpecificShutdown() { xnUSBAsynchThreadStop(); #ifdef XN_USE_UDEV g_bShouldRunUDEVThread = false; xnOSWaitAndTerminateThread(&g_hUDEVThread, 2 * 1000); g_hUDEVThread = NULL; #endif if (g_InitData.hLock != NULL) { xnOSCloseCriticalSection(&g_InitData.hLock); g_InitData.hLock = NULL; } if (g_InitData.pContext != NULL) { // close the library libusb_exit(g_InitData.pContext); g_InitData.pContext = NULL; } return (XN_STATUS_OK); }