| 39 | } |
| 40 | |
| 41 | XN_C_API XnStatus XN_C_DECL xnOSCreateNamedMutexEx(XN_MUTEX_HANDLE* pMutexHandle, const XnChar* cpMutexName, XnBool bAllowOtherUsers) |
| 42 | { |
| 43 | // Local function variables |
| 44 | XnStatus nRetVal = XN_STATUS_OK; |
| 45 | |
| 46 | // Validate the input/output pointers (to make sure none of them is NULL) |
| 47 | XN_VALIDATE_INPUT_PTR(pMutexHandle); |
| 48 | |
| 49 | XnChar strMutexOSName[MAX_PATH]; |
| 50 | XnChar* pMutexOSName = NULL; |
| 51 | SECURITY_ATTRIBUTES* pSecurityAttributes = NULL; |
| 52 | |
| 53 | if (cpMutexName != NULL) |
| 54 | { |
| 55 | nRetVal = XnWin32CreateKernelObjectName(strMutexOSName, MAX_PATH, cpMutexName, bAllowOtherUsers); |
| 56 | if (nRetVal != XN_STATUS_OK) |
| 57 | { |
| 58 | return XN_STATUS_OS_MUTEX_CREATION_FAILED; |
| 59 | } |
| 60 | |
| 61 | pMutexOSName = strMutexOSName; |
| 62 | |
| 63 | nRetVal = XnWin32GetSecurityAttributes(bAllowOtherUsers, &pSecurityAttributes); |
| 64 | if (nRetVal != XN_STATUS_OK) |
| 65 | { |
| 66 | return XN_STATUS_OS_MUTEX_CREATION_FAILED; |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | // Create a named mutex via the OS |
| 71 | *pMutexHandle = CreateMutex(pSecurityAttributes, FALSE, pMutexOSName); |
| 72 | |
| 73 | // Make sure it succeeded (return value is not null) |
| 74 | if (*pMutexHandle == NULL) |
| 75 | { |
| 76 | XN_LOG_WARNING_RETURN(XN_STATUS_OS_MUTEX_CREATION_FAILED, XN_MASK_OS, "Failed to create mutex (%d).", GetLastError()); |
| 77 | } |
| 78 | |
| 79 | // All is good... |
| 80 | return (XN_STATUS_OK); |
| 81 | } |
| 82 | |
| 83 | XN_C_API XnStatus xnOSCloseMutex(XN_MUTEX_HANDLE* pMutexHandle) |
| 84 | { |
no test coverage detected