Skip to content

Commit 9ce6514

Browse files
committed
error handling
1 parent 7e9f4d8 commit 9ce6514

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

src/pool/pool_disjoint.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,14 @@
2727

2828
#include "pool_disjoint_temp.h"
2929

30+
// TODO remove
3031
#ifdef __cplusplus
3132
extern "C" {
3233
#endif
3334

35+
//static <- make static rename to TLS_last_allocation_error
36+
__TLS umf_result_t TLS_last_allocation_error_dp;
37+
3438
static size_t CutOff = (size_t)1 << 31; // 2GB
3539

3640
// Temporary solution for disabling memory poisoning. This is needed because
@@ -768,6 +772,7 @@ void AllocImpl_printStats(AllocImpl *ai, bool *TitlePrinted,
768772
}
769773
}
770774

775+
// TODO remove
771776
#ifdef __cplusplus
772777
}
773778
#endif

src/pool/pool_disjoint.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ extern "C" {
4545

4646
#include "pool_disjoint_temp.h"
4747

48+
extern __TLS umf_result_t TLS_last_allocation_error_dp;
49+
4850
#ifdef __cplusplus
4951
}
5052
#endif
@@ -110,7 +112,7 @@ static void *memoryProviderAlloc(umf_memory_provider_handle_t hProvider,
110112
void *ptr;
111113
auto ret = umfMemoryProviderAlloc(hProvider, size, alignment, &ptr);
112114
if (ret != UMF_RESULT_SUCCESS) {
113-
umf::getPoolLastStatusRef<DisjointPool>() = ret;
115+
TLS_last_allocation_error_dp = ret;
114116
return NULL;
115117
}
116118
annotate_memory_inaccessible(ptr, size);
@@ -132,7 +134,7 @@ static umf_result_t memoryProviderFree(umf_memory_provider_handle_t hProvider,
132134
auto ret = umfMemoryProviderFree(hProvider, ptr, size);
133135
if (ret != UMF_RESULT_SUCCESS) {
134136

135-
umf::getPoolLastStatusRef<DisjointPool>() = ret;
137+
TLS_last_allocation_error_dp = ret;
136138
// throw MemoryProviderError{ret};
137139
return ret;
138140
}
@@ -184,8 +186,7 @@ void *AllocImpl_allocate(AllocImpl *ai, size_t Size, bool *FromPool) {
184186

185187
if (Ptr == NULL) {
186188
// TODO get code from func
187-
umf::getPoolLastStatusRef<DisjointPool>() =
188-
UMF_RESULT_ERROR_OUT_OF_HOST_MEMORY;
189+
TLS_last_allocation_error_dp = UMF_RESULT_ERROR_OUT_OF_HOST_MEMORY;
189190
return nullptr;
190191
}
191192

@@ -203,8 +204,7 @@ void *AllocImpl_allocate(AllocImpl *ai, size_t Size, bool *FromPool) {
203204

204205
if (Ptr == NULL) {
205206
// TODO get code from func
206-
umf::getPoolLastStatusRef<DisjointPool>() =
207-
UMF_RESULT_ERROR_OUT_OF_HOST_MEMORY;
207+
TLS_last_allocation_error_dp = UMF_RESULT_ERROR_OUT_OF_HOST_MEMORY;
208208
return nullptr;
209209
}
210210

@@ -358,13 +358,13 @@ void *DisjointPool::malloc(size_t size) { // For full-slab allocations indicates
358358

359359
void *DisjointPool::calloc(size_t, size_t) {
360360
// Not supported
361-
umf::getPoolLastStatusRef<DisjointPool>() = UMF_RESULT_ERROR_NOT_SUPPORTED;
361+
TLS_last_allocation_error_dp = UMF_RESULT_ERROR_NOT_SUPPORTED;
362362
return NULL;
363363
}
364364

365365
void *DisjointPool::realloc(void *, size_t) {
366366
// Not supported
367-
umf::getPoolLastStatusRef<DisjointPool>() = UMF_RESULT_ERROR_NOT_SUPPORTED;
367+
TLS_last_allocation_error_dp = UMF_RESULT_ERROR_NOT_SUPPORTED;
368368
return NULL;
369369
}
370370

@@ -407,7 +407,7 @@ umf_result_t DisjointPool::free(void *ptr) {
407407
}
408408

409409
umf_result_t DisjointPool::get_last_allocation_error() {
410-
return umf::getPoolLastStatusRef<DisjointPool>();
410+
return TLS_last_allocation_error_dp;
411411
}
412412

413413
DisjointPool::DisjointPool() {}

0 commit comments

Comments
 (0)