The open source OpenXR runtime
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

xrt: Introduce a new xrt_ipc_handle_t for IPC connections

authored by

Julian Petrov and committed by
Ryan Pavlik
5f4f7530 6bb976e4

+117 -1
+117 -1
src/xrt/include/xrt/xrt_handles.h
··· 15 15 16 16 #ifdef XRT_OS_WINDOWS 17 17 #include "xrt_windows.h" 18 - #endif // XRT_OS_WINDOWS 18 + #else // !XRT_OS_WINDOWS 19 + #include "unistd.h" 20 + #endif // !XRT_OS_WINDOWS 19 21 20 22 21 23 #ifdef __cplusplus 22 24 extern "C" { 23 25 #endif 24 26 27 + #if defined(XRT_OS_WINDOWS) 28 + /*! 29 + * The type for an IPC handle. 30 + * 31 + * On Windows, this is HANDLE. 32 + */ 33 + typedef HANDLE xrt_ipc_handle_t; 34 + 35 + /*! 36 + * An invalid value for an IPC handle. 37 + * 38 + * Note that there may be more than one value that's invalid - use 39 + * @ref xrt_ipc_handle_is_valid instead of comparing against this! 40 + * 41 + * @relates xrt_ipc_handle_t 42 + */ 43 + #define XRT_IPC_HANDLE_INVALID INVALID_HANDLE_VALUE 44 + 45 + /*! 46 + * Check whether an IPC handle is valid. 47 + * 48 + * @public @memberof xrt_ipc_handle_t 49 + */ 50 + static inline bool 51 + xrt_ipc_handle_is_valid(xrt_ipc_handle_t handle) 52 + { 53 + return handle != INVALID_HANDLE_VALUE; 54 + } 55 + 56 + /*! 57 + * Close an IPC handle. 58 + * 59 + * @public @memberof xrt_ipc_handle_t 60 + */ 61 + static inline void 62 + xrt_ipc_handle_close(xrt_ipc_handle_t handle) 63 + { 64 + CloseHandle(handle); 65 + } 66 + 67 + #else // !XRT_OS_WINDOWS 68 + 69 + /*! 70 + * The type for an IPC handle. 71 + * 72 + * On non-Windows, this is a file descriptor. 73 + */ 74 + typedef int xrt_ipc_handle_t; 75 + 76 + /*! 77 + * An invalid value for an IPC handle. 78 + * 79 + * Note that there may be more than one value that's invalid - use 80 + * @ref xrt_ipc_handle_is_valid instead of comparing against this! 81 + * 82 + * @relates xrt_ipc_handle_t 83 + */ 84 + #define XRT_IPC_HANDLE_INVALID (-1) 85 + 86 + /*! 87 + * Check whether an IPC handle is valid. 88 + * 89 + * @public @memberof xrt_ipc_handle_t 90 + */ 91 + static inline bool 92 + xrt_ipc_handle_is_valid(xrt_ipc_handle_t handle) 93 + { 94 + return handle >= 0; 95 + } 96 + 97 + /*! 98 + * Close an IPC handle. 99 + * 100 + * @public @memberof xrt_ipc_handle_t 101 + */ 102 + static inline void 103 + xrt_ipc_handle_close(xrt_ipc_handle_t handle) 104 + { 105 + close(handle); 106 + } 107 + 108 + #endif // !XRT_OS_WINDOWS 25 109 26 110 /* 27 111 * ··· 29 113 * 30 114 */ 31 115 116 + #if defined(XRT_OS_WINDOWS) 117 + /*! 118 + * The type for shared memory blocks shared over IPC. 119 + * 120 + * On Windows, this is a HANDLE. 121 + */ 122 + typedef HANDLE xrt_shmem_handle_t; 123 + 124 + /*! 125 + * Check whether a shared memory handle is valid. 126 + * 127 + * @public @memberof xrt_shmem_handle_t 128 + */ 129 + static inline bool 130 + xrt_shmem_is_valid(xrt_shmem_handle_t handle) 131 + { 132 + return handle != NULL; 133 + } 134 + 135 + /*! 136 + * An invalid value for a shared memory block. 137 + * 138 + * Note that there may be more than one value that's invalid - use 139 + * @ref xrt_shmem_is_valid instead of comparing against this! 140 + * 141 + * @relates xrt_shmem_handle_t 142 + */ 143 + #define XRT_SHMEM_HANDLE_INVALID (NULL) 144 + 145 + #else // !XRT_OS_WINDOWS 146 + 32 147 /*! 33 148 * The type for shared memory blocks shared over IPC. 34 149 * ··· 64 179 */ 65 180 #define XRT_SHMEM_HANDLE_INVALID (-1) 66 181 182 + #endif // !XRT_OS_WINDOWS 67 183 68 184 /* 69 185 *