-
Notifications
You must be signed in to change notification settings - Fork 39
Split initialize function and add post-initialize phase #1467
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,6 +36,9 @@ typedef struct umf_memory_pool_ops_t { | |
|
||
/// | ||
/// @brief Initializes memory pool. | ||
/// /details | ||
/// * The memory pool implementation *must* allocate the memory pool structure | ||
/// and return it by the \p pool parameter. | ||
/// @param provider memory provider that will be used for coarse-grain allocations. | ||
/// @param params pool-specific params, or NULL for defaults | ||
/// @param pool [out] returns pointer to the pool | ||
|
@@ -191,6 +194,25 @@ typedef struct umf_memory_pool_ops_t { | |
/// failure. | ||
/// | ||
umf_result_t (*ext_trim_memory)(void *pool, size_t minBytesToKeep); | ||
|
||
/// | ||
/// @brief Post-initializes and set up memory pool. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add "this function must be implemented if the pool/provider supports CTL that overrides defaults" There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Even with this clarification, for me it is not clear why we need a separate function. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've added a short description what is and what for. |
||
/// Post-construction hook for memory pools, enabling advanced or deferred setup that cannot | ||
/// be done in the initial allocation phase (e.g. setting defaults from CTL). | ||
/// | ||
/// \details | ||
/// * This function *must* be implemented if the pool/provider supports CTL that overrides defaults. | ||
/// * This function *must* free any resources allocated in the function. | ||
/// * This function *must* be called after the memory pool has been allocated in initialize function | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Must be called by whom? If UMF calls it, then the comment is missleading. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's about the function order. Generally, this function is the same case as |
||
/// and is used to perform any additional setup required by the memory pool. | ||
/// * This function *may* be used to set up any additional resources required by the memory pool. | ||
/// * This function *may* be used to set up default values for the memory pool parameters set up by CTL. | ||
/// | ||
/// @param pool pointer to the pool | ||
/// @return UMF_RESULT_SUCCESS on success or appropriate error code on failure | ||
/// | ||
umf_result_t (*ext_post_initialize)(void *pool); | ||
|
||
} umf_memory_pool_ops_t; | ||
|
||
#ifdef __cplusplus | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -758,6 +758,14 @@ umf_result_t disjoint_pool_initialize(umf_memory_provider_handle_t provider, | |
disjoint_pool->provider = provider; | ||
disjoint_pool->params = *dp_params; | ||
|
||
*ppPool = (void *)disjoint_pool; | ||
|
||
return UMF_RESULT_SUCCESS; | ||
} | ||
|
||
umf_result_t disjoint_pool_post_initialize(void *ppPool) { | ||
disjoint_pool_t *disjoint_pool = (disjoint_pool_t *)ppPool; | ||
|
||
disjoint_pool->known_slabs = critnib_new(free_slab, NULL); | ||
if (disjoint_pool->known_slabs == NULL) { | ||
goto err_free_disjoint_pool; | ||
|
@@ -816,13 +824,11 @@ umf_result_t disjoint_pool_initialize(umf_memory_provider_handle_t provider, | |
} | ||
|
||
umf_result_t ret = umfMemoryProviderGetMinPageSize( | ||
provider, NULL, &disjoint_pool->provider_min_page_size); | ||
disjoint_pool->provider, NULL, &disjoint_pool->provider_min_page_size); | ||
if (ret != UMF_RESULT_SUCCESS) { | ||
disjoint_pool->provider_min_page_size = 0; | ||
} | ||
|
||
*ppPool = (void *)disjoint_pool; | ||
|
||
return UMF_RESULT_SUCCESS; | ||
|
||
err_free_buckets: | ||
|
@@ -841,7 +847,6 @@ umf_result_t disjoint_pool_initialize(umf_memory_provider_handle_t provider, | |
|
||
err_free_disjoint_pool: | ||
umf_ba_global_free(disjoint_pool); | ||
|
||
return UMF_RESULT_ERROR_OUT_OF_HOST_MEMORY; | ||
} | ||
|
||
|
@@ -1199,7 +1204,7 @@ static umf_memory_pool_ops_t UMF_DISJOINT_POOL_OPS = { | |
.get_name = disjoint_pool_get_name, | ||
.ext_ctl = disjoint_pool_ctl, | ||
.ext_trim_memory = disjoint_pool_trim_memory, | ||
}; | ||
.ext_post_initialize = disjoint_pool_post_initialize}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: add ',' after the last member There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Initializer list doesn't require it; it's not a struct declaration. Sometimes ends with |
||
|
||
const umf_memory_pool_ops_t *umfDisjointPoolOps(void) { | ||
return &UMF_DISJOINT_POOL_OPS; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add a comment above "The following operations were added in ops version 1.1"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rebased.