Skip to content

Commit 7caa6d4

Browse files
committed
ipc redesing proposal
1 parent e9b0630 commit 7caa6d4

File tree

4 files changed

+72
-13
lines changed

4 files changed

+72
-13
lines changed

include/umf/ipc.h

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ extern "C" {
1818
#endif
1919

2020
typedef struct umf_ipc_data_t *umf_ipc_handle_t;
21-
21+
typedef struct umf_ipc_handler *umf_ipc_handler_t;
22+
typedef const struct umf_ipc_handler *umf_ipc_handler_t;
2223
///
2324
/// @brief Returns the size of IPC handles for the specified pool.
2425
/// @param hPool [in] Pool handle
@@ -42,13 +43,31 @@ umf_result_t umfGetIPCHandle(const void *ptr, umf_ipc_handle_t *ipcHandle,
4243
/// @return UMF_RESULT_SUCCESS on success or appropriate error code on failure.
4344
umf_result_t umfPutIPCHandle(umf_ipc_handle_t ipcHandle);
4445

46+
///
47+
/// @bries Retrivies an IPC handler which is used to open IPC handles.
48+
/// @param hpool [in] Pool handle.
49+
/// @param ipcHandler [out] IPC handler.
50+
/// @return UMF_RESULT_SUCCESS on success or appropriate error code on failure.
51+
umf_result_t umfGetIPCHandler(umf_memory_pool_handle_t hpool,
52+
umf_const_ipc_handler_t *ipcHandler);
53+
54+
///
55+
/// @brief Creates an IPC handler, which is used to open IPC handles.
56+
/// @param ops [in] instance of umf_memory_provider_ops_t.
57+
/// @param params [in] pointer to provider specific parameters. This is the same stucture that is used to create a memory provider. But some fileds may be ignored. See your memory provider documentation for details.
58+
/// @param ipcHandler [out] handle to the newly created IPC handler.
59+
/// @return UMF_RESULT_SUCCESS on success or appropriate error code on failure.
60+
/// @details this function is should be used if user only want to open IPC handles,
61+
/// and do not need a memory pool, to allocate memory on client side.
62+
umf_result_t umfCreateIPCHandler(const umf_memory_provider_ops_t *ops,
63+
void *params, umf_ipc_handler_t *ipcHandler);
4564
///
4665
/// @brief Open IPC handle retrieved by umfGetIPCHandle.
47-
/// @param hPool [in] Pool handle where to open the the IPC handle.
66+
/// @param handler [in] IPC handler.
4867
/// @param ipcHandle [in] IPC handle.
4968
/// @param ptr [out] pointer to the memory in the current process.
5069
/// @return UMF_RESULT_SUCCESS on success or appropriate error code on failure.
51-
umf_result_t umfOpenIPCHandle(umf_memory_pool_handle_t hPool,
70+
umf_result_t umfOpenIPCHandle(umf_const_ipc_handler_t handler,
5271
umf_ipc_handle_t ipcHandle, void **ptr);
5372

5473
///
@@ -57,6 +76,12 @@ umf_result_t umfOpenIPCHandle(umf_memory_pool_handle_t hPool,
5776
/// @return UMF_RESULT_SUCCESS on success or appropriate error code on failure.
5877
umf_result_t umfCloseIPCHandle(void *ptr);
5978

79+
///
80+
/// @brief Destroys IPC handler, created by umfCreateIPCHandler.
81+
/// @param handler [in] IPC handler.
82+
/// @return UMF_RESULT_SUCCESS on success or appropriate error code on failure.
83+
umf_result_t umfDestroyIPCHandler(umf_ipc_handler_t handler);
84+
6085
#ifdef __cplusplus
6186
}
6287
#endif

include/umf/memory_pool.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ umf_result_t umfPoolGetLastAllocationError(umf_memory_pool_handle_t hPool);
157157
/// with the usage of a memory provider is being tracked.
158158
/// @param ptr pointer to memory belonging to a memory pool
159159
/// @return Handle to a memory pool that contains ptr or NULL if pointer does not belong to any UMF pool.
160-
///
160+
/// @details returns NULL for ptrs that were open through IPC open function, as this ptr do not belong to any pool.
161161
umf_memory_pool_handle_t umfPoolByPtr(const void *ptr);
162162

163163
///

include/umf/memory_provider.h

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ extern "C" {
1919

2020
/// @brief A struct containing memory provider specific set of functions
2121
typedef struct umf_memory_provider_t *umf_memory_provider_handle_t;
22-
22+
typedef struct umf_ipc_handler *umf_ipc_handler_t;
23+
typedef const struct umf_ipc_handler *umf_ipc_handler_t;
2324
///
2425
/// @brief Creates new memory provider.
2526
/// @param ops instance of umf_memory_provider_ops_t
@@ -172,21 +173,35 @@ umf_result_t
172173
umfMemoryProviderPutIPCHandle(umf_memory_provider_handle_t hProvider,
173174
void *providerIpcData);
174175

176+
/// check memory_provider_ops.h for more details
177+
umf_result_t
178+
umfMemoryProviderGetIpcHandler(umf_memory_provider_handle_t hProvider,
179+
umf_const_ipc_handler_t *handler);
180+
/// check memory_provider_ops.h for more details
181+
umf_result_t
182+
umfMemoryProviderCreateIpcHandler(const umf_memory_provider_ops_t *ops,
183+
void *params, umf_ipc_handler_t *handler);
184+
/// check memory_provider_ops.h for more details
185+
umf_result_t
186+
umfMemoryProviderDestroyIpcHandler(umf_memory_provider_handle_t *hProvider);
187+
175188
///
176189
/// @brief Open IPC handle.
177-
/// @param hProvider [in] handle to the memory provider.
190+
/// @param hIpcHandler [in] handle to the ipcHandler
178191
/// @param providerIpcData [in] pointer to the IPC opaque data structure.
179192
/// @param ptr [out] pointer to the memory to be used in the current process.
193+
/// @param size [out][optional] size of the memory address range.
180194
/// @return UMF_RESULT_SUCCESS on success or appropriate error code on failure.
181195
/// UMF_RESULT_ERROR_INVALID_ARGUMENT if providerIpcData cannot be handled by the provider.
182196
/// UMF_RESULT_ERROR_NOT_SUPPORTED if IPC functionality is not supported by this provider.
183197
umf_result_t
184-
umfMemoryProviderOpenIPCHandle(umf_memory_provider_handle_t hProvider,
185-
void *providerIpcData, void **ptr);
198+
umfMemoryProviderOpenIPCHandle(umf_memory_provider_handleer_t hIpcHanler,
199+
void *providerIpcData, void **ptr,
200+
size_t **size);
186201

187202
///
188203
/// @brief Close an IPC memory handle.
189-
/// @param hProvider [in] handle to the memory provider.
204+
/// @param hIpcHanler [in] handle to the memory provider.
190205
/// @param ptr [in] pointer returned by umfMemoryProviderOpenIPCHandle function.
191206
/// @param size [in] size of the memory address range.
192207
/// @return UMF_RESULT_SUCCESS on success or appropriate error code on failure.

include/umf/memory_provider_ops.h

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,13 +116,13 @@ typedef struct umf_memory_provider_ipc_ops_t {
116116

117117
///
118118
/// @brief Open IPC handle.
119-
/// @param provider pointer to the memory provider.
120-
/// @param providerIpcData pointer to the IPC opaque data structure.
119+
/// @param ipcHandler pointer to the memory provider.
120+
/// @param providerIpc Data pointer to the IPC opaque data structure.
121121
/// @param ptr [out] pointer to the memory to be used in the current process.
122122
/// @return UMF_RESULT_SUCCESS on success or appropriate error code on failure.
123123
/// UMF_RESULT_ERROR_INVALID_ARGUMENT if providerIpcData cannot be handled by the provider.
124124
/// UMF_RESULT_ERROR_NOT_SUPPORTED if IPC functionality is not supported by this provider.
125-
umf_result_t (*open_ipc_handle)(void *provider, void *providerIpcData,
125+
umf_result_t (*open_ipc_handle)(void *ipcHandler, void *providerIpcData,
126126
void **ptr);
127127

128128
///
@@ -133,7 +133,26 @@ typedef struct umf_memory_provider_ipc_ops_t {
133133
/// @return UMF_RESULT_SUCCESS on success or appropriate error code on failure.
134134
/// UMF_RESULT_ERROR_INVALID_ARGUMENT if invalid \p ptr is passed.
135135
/// UMF_RESULT_ERROR_NOT_SUPPORTED if IPC functionality is not supported by this provider.
136-
umf_result_t (*close_ipc_handle)(void *provider, void *ptr, size_t size);
136+
umf_result_t (*close_ipc_handle)(void *ipcHandler, void *ptr, size_t size);
137+
138+
/// @brief Retrieve an IPC handler which is used to open IPC handles.
139+
/// @param provider pointer to the memory provider.
140+
/// @param ipcHandler [out] pointer to the IPC handler.
141+
/// @return UMF_RESULT_SUCCESS on success or appropriate error code on failure.
142+
umf_result_t (*get_ipc_handler)(void *provider, void **ipcHandler);
143+
144+
/// @brief Creates an IPC handler, which is used to open IPC handles.
145+
/// @param params provider-specific params. This argument must be the same structure then in the initialize function,
146+
/// but some fields might be ignored, if they are not needed for IPC handle.
147+
/// @param ipcHandler [out] pointer to the newly created IPC handler.
148+
/// @return UMF_RESULT_SUCCESS on success or appropriate error code on failure.
149+
/// @details This function create ipc handler, with is used to open IPC handles, without need to create provider, only to open handle.
150+
umf_result_t (*create_ipc_handler)(void *params, void **ipcHandler);
151+
152+
/// @brief Destroys an IPC handler, created by create_ipc_handler.
153+
/// @param ipcHandler pointer to the IPC handler.
154+
/// @return UMF_RESULT_SUCCESS on success or appropriate error code on failure.
155+
umf_result_t (*destory_ipc_handler)(void *ipcHandler);
137156
} umf_memory_provider_ipc_ops_t;
138157

139158
///

0 commit comments

Comments
 (0)