XN_C_API XnStatus xnOSTerminateThread(XN_THREAD_HANDLE* pThreadHandle) { // Local function variables XnBool bRetVal = FALSE; XnStatus nRetVal = XN_STATUS_OK; // Validate the input/output pointers (to make sure none of them is NULL) XN_VALIDATE_INPUT_PTR(pThreadHandle); // Make sure the actual thread handle isn't NULL XN_RET_IF_NULL(*pThreadHandle, XN_STATUS_OS_INVALID_THREAD); // Close the thread via the OS bRetVal = TerminateThread(*pThreadHandle, 0); // Make sure it succeeded (return value is true) if (bRetVal != TRUE) { return (XN_STATUS_OS_THREAD_TERMINATION_FAILED); } // Close the handle nRetVal = xnOSCloseThread(pThreadHandle); XN_IS_STATUS_OK(nRetVal); // All is good... return (XN_STATUS_OK); }
XnVMessageListener::~XnVMessageListener() { if (m_bInternalThreadAlive) { XnAutoCSLocker local(m_hListenerCS); m_bInternalThreadKill = true; XnStatus rc = xnOSWaitForThreadExit(m_hActivityThread, 1000); if (rc != XN_STATUS_OK) { xnOSTerminateThread(&m_hActivityThread); } else { xnOSCloseThread(&m_hActivityThread); } } xnLogVerbose(XNV_NITE_MASK_CREATE, "Listener %s [0x%08x]: Destroy", m_strListenerName, this); XnVMessageListener::ClearQueue(); if (m_strListenerName != NULL) { xnOSFree(m_strListenerName); } XN_DELETE(m_pMessageQueue); XN_DELETE(m_pUpdateCBs); XN_DELETE(m_pActivateCBs); XN_DELETE(m_pDeactivateCBs); xnOSCloseCriticalSection(&m_hListenerCS); } // XnVMessageListener::~XnVMessageListener
XN_C_API XnStatus xnOSTerminateThread(XN_THREAD_HANDLE* pThreadHandle) { // Validate the input/output pointers (to make sure none of them is NULL) XN_VALIDATE_INPUT_PTR(pThreadHandle); // Make sure the actual thread handle isn't NULL XN_RET_IF_NULL(*pThreadHandle, XN_STATUS_OS_INVALID_THREAD); XN_THREAD_HANDLE handle = *pThreadHandle; #ifndef XN_PLATFORM_LINUX_NO_PTHREAD_CANCEL if (0 != pthread_cancel(*handle)) #else // send the KILL signal to the thread if (0 != pthread_kill(*handle, SIGUSR1)) #endif { return (XN_STATUS_OS_THREAD_TERMINATION_FAILED); } // Close the handle XnStatus nRetVal = xnOSCloseThread(pThreadHandle); XN_IS_STATUS_OK(nRetVal); // All is good... return (XN_STATUS_OK); }
XnStatus xnUSBPlatformSpecificShutdown() { XnStatus nRetVal = XN_STATUS_OK; if (g_InitData.hThread != NULL) { // mark for thread to exit g_InitData.bShouldThreadRun = FALSE; // wait for it to exit nRetVal = xnOSWaitForThreadExit(g_InitData.hThread, XN_USB_HANDLE_EVENTS_TIMEOUT); if (nRetVal != XN_STATUS_OK) { xnOSTerminateThread(&g_InitData.hThread); } else { xnOSCloseThread(&g_InitData.hThread); } g_InitData.hThread = NULL; } if (g_InitData.pContext != NULL) { // close the library libusb_exit(g_InitData.pContext); g_InitData.pContext = NULL; } return (XN_STATUS_OK); }
void kinectWeb::exit() { // 終了処理 clients.close(); xnOSCloseThread(&threadHandle); context.shutdown(); ofLog(OF_LOG_NOTICE, "End Application"); }
void PlayerDevice::close() { // Destroy the thread. m_running = false; m_readyForDataInternalEvent.Set(); m_manualTriggerInternalEvent.Set(); XnStatus rc = xnOSWaitForThreadExit(m_threadHandle, DEVICE_DESTROY_THREAD_TIMEOUT); if (rc != XN_STATUS_OK) { xnOSTerminateThread(&m_threadHandle); } else { xnOSCloseThread(&m_threadHandle); } // Destroy the player. m_player.Destroy(); // Delete all the sources and streams. Lock(); while (m_streams.Begin() != m_streams.End()) { PlayerStream* pStream = *m_streams.Begin(); m_streams.Remove(pStream); } while (m_sources.Begin() != m_sources.End()) { PlayerSource* pSource = *m_sources.Begin(); m_sources.Remove(pSource); XN_DELETE(pSource); } Unlock(); }
Recorder::~Recorder() { stop(); detachAllStreams(); send(Message::MESSAGE_TERMINATE); xnOSWaitForThreadExit(m_thread, XN_WAIT_INFINITE); xnOSCloseThread(&m_thread); if (NULL != m_handle) { m_handle->pRecorder = NULL; } }
void xnUSBAsynchThreadStop() { if (g_InitData.hThread != NULL) { // mark for thread to exit g_InitData.bShouldThreadRun = FALSE; // wait for it to exit XnStatus nRetVal = xnOSWaitForThreadExit(g_InitData.hThread, XN_USB_HANDLE_EVENTS_TIMEOUT); if (nRetVal != XN_STATUS_OK) { xnOSTerminateThread(&g_InitData.hThread); } else { xnOSCloseThread(&g_InitData.hThread); } g_InitData.hThread = NULL; } }
XN_C_API XnStatus xnOSWaitAndTerminateThread(XN_THREAD_HANDLE* pThreadHandle, XnUInt32 nMilliseconds) { XnStatus nRetVal = XN_STATUS_OK; XN_VALIDATE_INPUT_PTR(pThreadHandle); // first, wait for thread to exit on its own nRetVal = xnOSWaitForThreadExit(*pThreadHandle, nMilliseconds); if (nRetVal != XN_STATUS_OK) { // thread did not exit on its own. Kill it. xnLogWarning(XN_MASK_OS, "Thread did not shutdown in %u ms. Thread will be killed...", nMilliseconds); xnOSTerminateThread(pThreadHandle); } else { // thread exited. Just close the handle. xnOSCloseThread(pThreadHandle); } return (XN_STATUS_OK); }
// Stream VideoStream::~VideoStream() { // Make sure stream is stopped. stop(); m_device.clearStream(this); // Detach all recorders from this stream. xnl::LockGuard< Recorders > guard(m_recorders); while (m_recorders.Begin() != m_recorders.End()) { // NOTE: DetachStream has a side effect of modifying m_recorders. m_recorders.Begin()->Value()->detachStream(*this); } // Try to close the thread properly, and forcibly terminate it if failed/timedout. m_running = false; xnOSSetEvent(m_newFrameInternalEvent); xnOSSetEvent(m_newFrameInternalEventForFrameHolder); XnStatus rc = xnOSWaitForThreadExit(m_newFrameThread, STREAM_DESTROY_THREAD_TIMEOUT); if (rc != XN_STATUS_OK) { xnOSTerminateThread(&m_newFrameThread); } else { xnOSCloseThread(&m_newFrameThread); } m_pFrameHolder->setStreamEnabled(this, FALSE); m_driverHandler.deviceDestroyStream(m_device.getHandle(), m_streamHandle); xnOSCloseEvent(&m_newFrameInternalEvent); xnOSCloseEvent(&m_newFrameInternalEventForFrameHolder); XN_DELETE_ARR(m_pSensorInfo->pSupportedVideoModes); XN_DELETE(m_pSensorInfo); }
void xnUSBAsynchThreadStop() { if (g_InitData.hThread != NULL) { // mark for thread to exit g_InitData.bShouldThreadRun = FALSE; // wait for it to exit xnLogVerbose(XN_MASK_USB, "Shutting down USB events thread..."); XnStatus nRetVal = xnOSWaitForThreadExit(g_InitData.hThread, XN_USB_HANDLE_EVENTS_TIMEOUT * 2); if (nRetVal != XN_STATUS_OK) { xnLogWarning(XN_MASK_USB, "USB events thread didn't shutdown. Terminating it..."); xnOSTerminateThread(&g_InitData.hThread); } else { xnOSCloseThread(&g_InitData.hThread); } g_InitData.hThread = NULL; } }