Skip to content

Commit c55e8b5

Browse files
authored
Merge pull request #490 from ldorau/Get_size_of_allocation_from_tracking_provider_in_memoryProviderFree
Get size of allocation from tracking provider in memoryProviderFree()
2 parents 83b2812 + a0195e8 commit c55e8b5

File tree

5 files changed

+31
-3
lines changed

5 files changed

+31
-3
lines changed

src/libumf.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ EXPORTS
1414
umfFree
1515
umfGetIPCHandle
1616
umfGetLastFailedMemoryProvider
17+
umfMemoryTrackerGetAllocInfo
1718
umfMemoryProviderAlloc
1819
umfMemoryProviderAllocationMerge
1920
umfMemoryProviderAllocationSplit

src/libumf.map

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ UMF_1.0 {
99
umfGetIPCHandle;
1010
umfGetLastFailedMemoryProvider;
1111
umfLevelZeroMemoryProviderOps;
12+
umfMemoryTrackerGetAllocInfo;
1213
umfMemoryProviderAlloc;
1314
umfMemoryProviderAllocationMerge;
1415
umfMemoryProviderAllocationSplit;

src/pool/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,15 @@ if(UMF_BUILD_LIBUMF_POOL_DISJOINT)
1515
TYPE STATIC
1616
SRCS pool_disjoint.cpp ${POOL_EXTRA_SRCS}
1717
LIBS ${POOL_EXTRA_LIBS})
18+
1819
target_compile_definitions(disjoint_pool
1920
PRIVATE ${POOL_COMPILE_DEFINITIONS})
2021

22+
if(WINDOWS)
23+
target_compile_options(disjoint_pool PRIVATE /DWIN32_LEAN_AND_MEAN
24+
/DNOMINMAX)
25+
endif()
26+
2127
add_library(${PROJECT_NAME}::disjoint_pool ALIAS disjoint_pool)
2228

2329
add_dependencies(disjoint_pool umf)

src/pool/pool_disjoint.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
// TODO: replace with logger?
2323
#include <iostream>
2424

25+
#include "provider/provider_tracking.h"
26+
2527
#include "../cpp_helpers.hpp"
2628
#include "pool_disjoint.h"
2729
#include "umf.h"
@@ -404,7 +406,17 @@ static void *memoryProviderAlloc(umf_memory_provider_handle_t hProvider,
404406

405407
static void memoryProviderFree(umf_memory_provider_handle_t hProvider,
406408
void *ptr) {
407-
auto ret = umfMemoryProviderFree(hProvider, ptr, 0);
409+
size_t size = 0;
410+
411+
if (ptr) {
412+
umf_alloc_info_t allocInfo = {0};
413+
umf_result_t umf_result = umfMemoryTrackerGetAllocInfo(ptr, &allocInfo);
414+
if (umf_result == UMF_RESULT_SUCCESS) {
415+
size = allocInfo.baseSize;
416+
}
417+
}
418+
419+
auto ret = umfMemoryProviderFree(hProvider, ptr, size);
408420
if (ret != UMF_RESULT_SUCCESS) {
409421
throw MemoryProviderError{ret};
410422
}

src/utils/utils_concurrency.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,20 @@
1111
#define UMF_UTILS_CONCURRENCY_H 1
1212

1313
#include <stdio.h>
14-
#if defined(_WIN32)
14+
15+
#ifdef _WIN32
1516
#include <windows.h>
1617
#else
1718
#include <pthread.h>
19+
20+
#ifndef __cplusplus
1821
#include <stdatomic.h>
19-
#endif
22+
#else /* __cplusplus */
23+
#include <atomic>
24+
#define _Atomic(X) std::atomic<X>
25+
#endif /* __cplusplus */
26+
27+
#endif /* _WIN32 */
2028

2129
#include "utils_sanitizers.h"
2230

0 commit comments

Comments
 (0)