Skip to content

Get size of allocation from tracking provider in memoryProviderFree() #490

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

Merged
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
1 change: 1 addition & 0 deletions src/libumf.def
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ EXPORTS
umfFree
umfGetIPCHandle
umfGetLastFailedMemoryProvider
umfMemoryTrackerGetAllocInfo
umfMemoryProviderAlloc
umfMemoryProviderAllocationMerge
umfMemoryProviderAllocationSplit
Expand Down
1 change: 1 addition & 0 deletions src/libumf.map
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ UMF_1.0 {
umfGetIPCHandle;
umfGetLastFailedMemoryProvider;
umfLevelZeroMemoryProviderOps;
umfMemoryTrackerGetAllocInfo;
umfMemoryProviderAlloc;
umfMemoryProviderAllocationMerge;
umfMemoryProviderAllocationSplit;
Expand Down
6 changes: 6 additions & 0 deletions src/pool/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,15 @@ if(UMF_BUILD_LIBUMF_POOL_DISJOINT)
TYPE STATIC
SRCS pool_disjoint.cpp ${POOL_EXTRA_SRCS}
LIBS ${POOL_EXTRA_LIBS})

target_compile_definitions(disjoint_pool
PRIVATE ${POOL_COMPILE_DEFINITIONS})

if(WINDOWS)
target_compile_options(disjoint_pool PRIVATE /DWIN32_LEAN_AND_MEAN
/DNOMINMAX)
endif()

add_library(${PROJECT_NAME}::disjoint_pool ALIAS disjoint_pool)

add_dependencies(disjoint_pool umf)
Expand Down
14 changes: 13 additions & 1 deletion src/pool/pool_disjoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
// TODO: replace with logger?
#include <iostream>

#include "provider/provider_tracking.h"

#include "../cpp_helpers.hpp"
#include "pool_disjoint.h"
#include "umf.h"
Expand Down Expand Up @@ -404,7 +406,17 @@ static void *memoryProviderAlloc(umf_memory_provider_handle_t hProvider,

static void memoryProviderFree(umf_memory_provider_handle_t hProvider,
void *ptr) {
auto ret = umfMemoryProviderFree(hProvider, ptr, 0);
size_t size = 0;

if (ptr) {
umf_alloc_info_t allocInfo = {0};
umf_result_t umf_result = umfMemoryTrackerGetAllocInfo(ptr, &allocInfo);
if (umf_result == UMF_RESULT_SUCCESS) {
size = allocInfo.baseSize;
}
}

auto ret = umfMemoryProviderFree(hProvider, ptr, size);
if (ret != UMF_RESULT_SUCCESS) {
throw MemoryProviderError{ret};
}
Expand Down
12 changes: 10 additions & 2 deletions src/utils/utils_concurrency.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,20 @@
#define UMF_UTILS_CONCURRENCY_H 1

#include <stdio.h>
#if defined(_WIN32)

#ifdef _WIN32
#include <windows.h>
#else
#include <pthread.h>

#ifndef __cplusplus
#include <stdatomic.h>
#endif
#else /* __cplusplus */
#include <atomic>
#define _Atomic(X) std::atomic<X>
#endif /* __cplusplus */

#endif /* _WIN32 */

#include "utils_sanitizers.h"

Expand Down