Skip to content

Commit f764b67

Browse files
committed
Add umf_ba_linear_pool_contains_pointer
Signed-off-by: Lukasz Dorau <[email protected]>
1 parent eedb2ae commit f764b67

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

src/base_alloc/base_alloc_linear.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,3 +174,26 @@ void umf_ba_linear_destroy(umf_ba_linear_pool_t *pool) {
174174
util_mutex_destroy_not_free(&pool->metadata.lock);
175175
ba_os_free(pool, pool->metadata.pool_size);
176176
}
177+
178+
int umf_ba_linear_pool_contains_pointer(umf_ba_linear_pool_t *pool, void *ptr) {
179+
util_mutex_lock(&pool->metadata.lock);
180+
char *cptr = (char *)ptr;
181+
if (cptr >= pool->data &&
182+
cptr < ((char *)(pool)) + pool->metadata.pool_size) {
183+
util_mutex_unlock(&pool->metadata.lock);
184+
return 1;
185+
}
186+
187+
umf_ba_next_linear_pool_t *next_pool = pool->next_pool;
188+
while (next_pool) {
189+
if (cptr >= next_pool->data &&
190+
cptr < ((char *)(next_pool)) + next_pool->pool_size) {
191+
util_mutex_unlock(&pool->metadata.lock);
192+
return 1;
193+
}
194+
next_pool = next_pool->next_pool;
195+
}
196+
197+
util_mutex_unlock(&pool->metadata.lock);
198+
return 0;
199+
}

src/base_alloc/base_alloc_linear.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ typedef struct umf_ba_linear_pool umf_ba_linear_pool_t;
2626
umf_ba_linear_pool_t *umf_ba_linear_create(size_t pool_size);
2727
void *umf_ba_linear_alloc(umf_ba_linear_pool_t *pool, size_t size);
2828
void umf_ba_linear_destroy(umf_ba_linear_pool_t *pool);
29+
int umf_ba_linear_pool_contains_pointer(umf_ba_linear_pool_t *pool, void *ptr);
2930

3031
#ifdef __cplusplus
3132
}

0 commit comments

Comments
 (0)