Пример #1
0
XN_C_API XnStatus xnOSCloseMutex(XN_MUTEX_HANDLE* pMutexHandle)
{
	// Local function variables
	XnStatus nRetVal = XN_STATUS_OK;

	// Validate the input/output pointers (to make sure none of them is NULL)
	XN_VALIDATE_INPUT_PTR(pMutexHandle);

	// Make sure the actual mutex handle isn't NULL
	XN_RET_IF_NULL(*pMutexHandle, XN_STATUS_OS_INVALID_MUTEX);
	
	XnMutex* pMutex = *pMutexHandle;

	// check the kind of mutex
	if (pMutex->bIsNamed)
	{
#ifndef XN_PLATFORM_LINUX_NO_SYSV

		// decrement second sem
		struct sembuf op;
		op.sem_num = 1;
		op.sem_op = -1;
		op.sem_flg = SEM_UNDO;
		
		if (0 != semop(pMutex->NamedSem, &op, 1))
		{
			return (XN_STATUS_OS_MUTEX_CLOSE_FAILED);
		}
		
		// check if sem reached 0 (if so, it can be deleted)
		int val = semctl(pMutex->NamedSem, 1, GETVAL);
		if (val == 0)
		{
			// destroy the semaphore
			semctl(pMutex->NamedSem, 0, IPC_RMID);
			// and remove file
			xnOSDeleteFile(pMutex->csSemFileName);
		}
		
		// in any case, close the file
		close(pMutex->hSemFile);
#endif
	}
	else
	{
		// destroy the mutex via the OS
		if (0 != pthread_mutex_destroy(&pMutex->ThreadMutex))
		{
			return (XN_STATUS_OS_MUTEX_CLOSE_FAILED);
		}
	}
	
	// free the handle
	XN_FREE_AND_NULL(*pMutexHandle);
	
	// All is good...
	return (XN_STATUS_OK);
}
Пример #2
0
XN_DDK_API XnStatus XnStreamDataDestroy(XnStreamData** ppStreamOutput)
{
	XN_VALIDATE_INPUT_PTR(ppStreamOutput);
	XnStreamData* pStreamOutput = *ppStreamOutput;

	if (pStreamOutput != NULL)
	{
		// only free buffer if allocated
		if (pStreamOutput->pInternal->nAllocSize != 0)
		{
			xnOSFreeAligned(pStreamOutput->pData);
		}

		pStreamOutput->pData = NULL;

		XN_FREE_AND_NULL(pStreamOutput->pInternal);

		XN_FREE_AND_NULL(*ppStreamOutput);
	}

	return (XN_STATUS_OK);
}
Пример #3
0
XN_C_API XnStatus xnOSCloseThread(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);

	// free handle
	XN_FREE_AND_NULL(*pThreadHandle);

	// All is good...
	return (XN_STATUS_OK);
}
Пример #4
0
XN_DDK_API XnStatus XN_DEVICE_PROXY_PROTO(Destroy)(XnDeviceHandle* pDeviceHandle)
{
	XN_VALIDATE_INPUT_PTR(pDeviceHandle);
	XN_VALIDATE_INPUT_PTR(*pDeviceHandle);

	XnDeviceProxyDeviceHandle* pHandle = (XnDeviceProxyDeviceHandle*)*pDeviceHandle;

	// first destroy actual device
	XnStatus nRetVal = pHandle->pDesc->Interface.Destroy(&pHandle->ActualDevice);
	XN_IS_STATUS_OK(nRetVal);

	// now destroy our handle
	XN_FREE_AND_NULL(*pDeviceHandle);

	return XN_STATUS_OK;
}
XN_C_API XnStatus xnOSCloseCriticalSection(XN_CRITICAL_SECTION_HANDLE* pCriticalSectionHandle)
{
	// Validate the input/output pointers (to make sure none of them is NULL)
	XN_VALIDATE_INPUT_PTR(pCriticalSectionHandle);

	// Make sure the actual critical section handle isn't NULL
	XN_RET_IF_NULL(*pCriticalSectionHandle, XN_STATUS_OS_INVALID_CRITICAL_SECTION);

	// Close the critical section via the OS
	DeleteCriticalSection(*pCriticalSectionHandle);

	// release allocated memory
	XN_FREE_AND_NULL(*pCriticalSectionHandle);

	// All is good...
	return (XN_STATUS_OK);
}
Пример #6
0
XN_C_API XnStatus xnUSBCloseDevice(XN_USB_DEV_HANDLE pDevHandle)
{
	// validate parameters
	XN_VALIDATE_USB_INIT();
	XN_VALIDATE_DEVICE_HANDLE(pDevHandle);

	int rc = libusb_release_interface(pDevHandle->hDevice, pDevHandle->nInterface);
	if (0 != rc)
	{
		return (XN_STATUS_USB_DEVICE_CLOSE_FAILED);
	}

	libusb_close(pDevHandle->hDevice);

	XN_FREE_AND_NULL(pDevHandle);

	return (XN_STATUS_OK);
}
Пример #7
0
XnStatus xnFPSFree(XnFPSData* pFPS)
{
	XN_VALIDATE_INPUT_PTR(pFPS);
	XnFPSDataImpl* pData = *pFPS;

	if (pData != NULL)
	{
		if (pData->anTimes != NULL)
		{
			XN_ALIGNED_FREE_AND_NULL(pData->anTimes);
		}

		if (*pFPS != NULL)
		{
			XN_FREE_AND_NULL(*pFPS);
		}
	}

	return XN_STATUS_OK;
}
Пример #8
0
//---------------------------------------------------------------------------
// Code
//---------------------------------------------------------------------------
XN_C_API XnStatus xnOSCreateThread(XN_THREAD_PROC_PROTO pThreadProc, const XN_THREAD_PARAM pThreadParam, XN_THREAD_HANDLE* pThreadHandle)
{
	// Validate the input/output pointers (to make sure none of them is NULL)
	XN_VALIDATE_INPUT_PTR(pThreadProc);
	XN_VALIDATE_OUTPUT_PTR(pThreadHandle);

	// allocate thread handle
	XN_VALIDATE_ALLOC(*pThreadHandle, pthread_t);

	// Create a thread via the OS
	int rc = pthread_create(*pThreadHandle, NULL, pThreadProc, pThreadParam);
	if (rc != 0)
	{
		XN_FREE_AND_NULL(*pThreadHandle);
		return (XN_STATUS_OS_THREAD_CREATION_FAILED);
	}

	// All is good...
	return (XN_STATUS_OK);
}
Пример #9
0
XnStatus XnDeviceManagerShutdown()
{
#ifdef XN_PLATFORM_SUPPORTS_DYNAMIC_LIBS
	// unload all libraries
	for (XnUInt32 i = 0; i < g_pDeviceManager->nDevicesCount; ++i)
	{
		xnOSFreeLibrary(g_pDeviceManager->aDevices[i].hLib);
	}
#endif

	// check if device manager is initialized
	if (g_pDeviceManager == NULL)
	{
		return XN_STATUS_NOT_INIT;
	}

	// free data
	XN_FREE_AND_NULL(g_pDeviceManager);

	return (XN_STATUS_OK);
}
Пример #10
0
XN_DDK_API XnStatus XnStreamDataSetDestroy(XnStreamDataSet** ppStreamOutputSet)
{
	XN_VALIDATE_INPUT_PTR(ppStreamOutputSet);

	XnStreamDataSet* pSet = (*ppStreamOutputSet);
	if (pSet != NULL)
	{
		for (XnStreamDataHash::Iterator it = pSet->pHash->begin(); it != pSet->pHash->end(); ++it)
		{
			XnStreamData* pStreamData = it.Value();
			XnStreamDataDestroy(&pStreamData);
		}

		// free hash table
		XN_DELETE(pSet->pHash);

		// free struct
		XN_FREE_AND_NULL(*ppStreamOutputSet);
	}

	return XN_STATUS_OK;
}
Пример #11
0
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;
}