Skip to content

Commit 13db60c

Browse files
committed
Make umfPoolCreateEx public
This function is useful in tests in in UR. Without it, the logic for provider lifetime management is duplicated in several places.
1 parent d425888 commit 13db60c

File tree

3 files changed

+25
-23
lines changed

3 files changed

+25
-23
lines changed

include/umf/memory_pool.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,24 @@ umf_result_t umfPoolCreate(const umf_memory_pool_ops_t *ops,
4242
umf_memory_provider_handle_t provider, void *params,
4343
umf_memory_pool_handle_t *hPool);
4444

45+
///
46+
/// @brief Creates new memory pool with new memory provider.
47+
/// Memory provider is created from specified provider_ops and provider_params
48+
/// and passed to pool_ops::initialize. The provider is owned by the pool and
49+
/// destroyed in umfPoolDestroy.
50+
/// @param pool_ops instance of umf_memory_pool_ops_t
51+
/// @param pool_params pointer to pool-specific parameters
52+
/// @param provider_ops instance of umf_memory_pool_ops_t
53+
/// @param provider_params pointer to provider-specific parameters
54+
/// @param hPool [out] handle to the newly created memory pool
55+
/// @return UMF_RESULT_SUCCESS on success or appropriate error code on failure.
56+
///
57+
umf_result_t umfPoolCreateEx(const umf_memory_pool_ops_t *pool_ops,
58+
void *pool_params,
59+
const umf_memory_provider_ops_t *provider_ops,
60+
void *provider_params,
61+
umf_memory_pool_handle_t *hPool);
62+
4563
///
4664
/// @brief Destroys memory pool.
4765
/// @param hPool handle to the pool

src/memory_pool_internal.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,6 @@ typedef struct umf_memory_pool_t {
3131
bool own_provider;
3232
} umf_memory_pool_t;
3333

34-
umf_result_t umfPoolCreateEx(const umf_memory_pool_ops_t *pool_ops,
35-
void *pool_params,
36-
const umf_memory_provider_ops_t *provider_ops,
37-
void *provider_params,
38-
umf_memory_pool_handle_t *hPool);
39-
4034
#ifdef __cplusplus
4135
}
4236
#endif

test/memoryPool.hpp

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,32 +20,22 @@
2020
using poolCreateExtParams = std::tuple<umf_memory_pool_ops_t *, void *,
2121
umf_memory_provider_ops_t *, void *>;
2222

23-
umf::pool_unique_handle_t poolCreateExt(poolCreateExtParams params) {
24-
umf_memory_provider_handle_t hProvider;
23+
umf::pool_unique_handle_t poolCreateExtUnique(poolCreateExtParams params) {
2524
umf_memory_pool_handle_t hPool;
2625
auto [pool_ops, pool_params, provider_ops, provider_params] = params;
2726

28-
auto ret =
29-
umfMemoryProviderCreate(provider_ops, provider_params, &hProvider);
27+
auto ret = umfPoolCreateEx(pool_ops, pool_params, provider_ops,
28+
provider_params, &hPool);
3029
EXPECT_EQ(ret, UMF_RESULT_SUCCESS);
3130

32-
ret = umfPoolCreate(pool_ops, hProvider, pool_params, &hPool);
33-
EXPECT_EQ(ret, UMF_RESULT_SUCCESS);
34-
35-
// capture provider and destroy it after the pool is destroyed
36-
auto poolDestructor = [hProvider](umf_memory_pool_handle_t pool) {
37-
umfPoolDestroy(pool);
38-
umfMemoryProviderDestroy(hProvider);
39-
};
40-
41-
return umf::pool_unique_handle_t(hPool, std::move(poolDestructor));
31+
return umf::pool_unique_handle_t(hPool, &umfPoolDestroy);
4232
}
4333

4434
struct umfPoolTest : umf_test::test,
4535
::testing::WithParamInterface<poolCreateExtParams> {
4636
void SetUp() override {
4737
test::SetUp();
48-
pool = poolCreateExt(this->GetParam());
38+
pool = poolCreateExtUnique(this->GetParam());
4939
}
5040

5141
void TearDown() override { test::TearDown(); }
@@ -64,7 +54,7 @@ struct umfMultiPoolTest : umf_test::test,
6454
void SetUp() override {
6555
test::SetUp();
6656
for (size_t i = 0; i < numPools; i++) {
67-
pools.emplace_back(poolCreateExt(this->GetParam()));
57+
pools.emplace_back(poolCreateExtUnique(this->GetParam()));
6858
}
6959
}
7060

@@ -81,7 +71,7 @@ struct umfMemTest
8171
test::SetUp();
8272

8373
auto [params, expectedRecycledPoolAllocs] = this->GetParam();
84-
pool = poolCreateExt(params);
74+
pool = poolCreateExtUnique(params);
8575
this->expectedRecycledPoolAllocs = expectedRecycledPoolAllocs;
8676
}
8777

0 commit comments

Comments
 (0)