Skip to content

Commit 68b2edc

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 b5a0ed9 commit 68b2edc

File tree

3 files changed

+24
-22
lines changed

3 files changed

+24
-22
lines changed

include/umf/memory_pool.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,23 @@ UMF_EXPORT umf_result_t umfPoolCreate(const umf_memory_pool_ops_t *ops,
4343
void *params,
4444
umf_memory_pool_handle_t *hPool);
4545

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

src/memory_pool_internal.h

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

34-
UMF_EXPORT umf_result_t
35-
umfPoolCreateEx(const umf_memory_pool_ops_t *pool_ops, void *pool_params,
36-
const umf_memory_provider_ops_t *provider_ops,
37-
void *provider_params, umf_memory_pool_handle_t *hPool);
38-
3934
#ifdef __cplusplus
4035
}
4136
#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)