Skip to content

Make umfPoolCreateEx public #97

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions include/umf/memory_pool.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,23 @@ UMF_EXPORT umf_result_t umfPoolCreate(const umf_memory_pool_ops_t *ops,
void *params,
umf_memory_pool_handle_t *hPool);

///
/// @brief Creates new memory pool with new memory provider.
/// Memory provider is created from specified provider_ops and provider_params
/// and passed to pool_ops::initialize. The provider is owned by the pool and
/// destroyed in umfPoolDestroy.
/// @param pool_ops instance of umf_memory_pool_ops_t
/// @param pool_params pointer to pool-specific parameters
/// @param provider_ops instance of umf_memory_provider_ops_t
/// @param provider_params pointer to provider-specific parameters
/// @param hPool [out] handle to the newly created memory pool
/// @return UMF_RESULT_SUCCESS on success or appropriate error code on failure.
///
UMF_EXPORT umf_result_t
umfPoolCreateEx(const umf_memory_pool_ops_t *pool_ops, void *pool_params,
const umf_memory_provider_ops_t *provider_ops,
void *provider_params, umf_memory_pool_handle_t *hPool);

///
/// @brief Destroys memory pool.
/// @param hPool handle to the pool
Expand Down
5 changes: 0 additions & 5 deletions src/memory_pool_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,6 @@ typedef struct umf_memory_pool_t {
bool own_provider;
} umf_memory_pool_t;

UMF_EXPORT umf_result_t
umfPoolCreateEx(const umf_memory_pool_ops_t *pool_ops, void *pool_params,
const umf_memory_provider_ops_t *provider_ops,
void *provider_params, umf_memory_pool_handle_t *hPool);

#ifdef __cplusplus
}
#endif
Expand Down
24 changes: 7 additions & 17 deletions test/memoryPool.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,32 +20,22 @@
using poolCreateExtParams = std::tuple<umf_memory_pool_ops_t *, void *,
umf_memory_provider_ops_t *, void *>;

umf::pool_unique_handle_t poolCreateExt(poolCreateExtParams params) {
umf_memory_provider_handle_t hProvider;
umf::pool_unique_handle_t poolCreateExtUnique(poolCreateExtParams params) {
umf_memory_pool_handle_t hPool;
auto [pool_ops, pool_params, provider_ops, provider_params] = params;

auto ret =
umfMemoryProviderCreate(provider_ops, provider_params, &hProvider);
auto ret = umfPoolCreateEx(pool_ops, pool_params, provider_ops,
provider_params, &hPool);
EXPECT_EQ(ret, UMF_RESULT_SUCCESS);

ret = umfPoolCreate(pool_ops, hProvider, pool_params, &hPool);
EXPECT_EQ(ret, UMF_RESULT_SUCCESS);

// capture provider and destroy it after the pool is destroyed
auto poolDestructor = [hProvider](umf_memory_pool_handle_t pool) {
umfPoolDestroy(pool);
umfMemoryProviderDestroy(hProvider);
};

return umf::pool_unique_handle_t(hPool, std::move(poolDestructor));
return umf::pool_unique_handle_t(hPool, &umfPoolDestroy);
}

struct umfPoolTest : umf_test::test,
::testing::WithParamInterface<poolCreateExtParams> {
void SetUp() override {
test::SetUp();
pool = poolCreateExt(this->GetParam());
pool = poolCreateExtUnique(this->GetParam());
}

void TearDown() override { test::TearDown(); }
Expand All @@ -64,7 +54,7 @@ struct umfMultiPoolTest : umf_test::test,
void SetUp() override {
test::SetUp();
for (size_t i = 0; i < numPools; i++) {
pools.emplace_back(poolCreateExt(this->GetParam()));
pools.emplace_back(poolCreateExtUnique(this->GetParam()));
}
}

Expand All @@ -81,7 +71,7 @@ struct umfMemTest
test::SetUp();

auto [params, expectedRecycledPoolAllocs] = this->GetParam();
pool = poolCreateExt(params);
pool = poolCreateExtUnique(params);
this->expectedRecycledPoolAllocs = expectedRecycledPoolAllocs;
}

Expand Down