Skip to content

Commit 47f0445

Browse files
committed
error handling
1 parent 883042c commit 47f0445

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
@@ -46,6 +46,8 @@ extern "C" {
4646

4747
#include "pool_disjoint_temp.h"
4848

49+
extern __TLS umf_result_t TLS_last_allocation_error_dp;
50+
4951
#ifdef __cplusplus
5052
}
5153
#endif
@@ -221,7 +223,7 @@ static void *memoryProviderAlloc(umf_memory_provider_handle_t hProvider,
221223
void *ptr;
222224
auto ret = umfMemoryProviderAlloc(hProvider, size, alignment, &ptr);
223225
if (ret != UMF_RESULT_SUCCESS) {
224-
umf::getPoolLastStatusRef<DisjointPool>() = ret;
226+
TLS_last_allocation_error_dp = ret;
225227
return NULL;
226228
}
227229
annotate_memory_inaccessible(ptr, size);
@@ -243,7 +245,7 @@ static umf_result_t memoryProviderFree(umf_memory_provider_handle_t hProvider,
243245
auto ret = umfMemoryProviderFree(hProvider, ptr, size);
244246
if (ret != UMF_RESULT_SUCCESS) {
245247

246-
umf::getPoolLastStatusRef<DisjointPool>() = ret;
248+
TLS_last_allocation_error_dp = ret;
247249
// throw MemoryProviderError{ret};
248250
return ret;
249251
}
@@ -295,8 +297,7 @@ void *AllocImpl_allocate(AllocImpl *ai, size_t Size, bool *FromPool) {
295297

296298
if (Ptr == NULL) {
297299
// TODO get code from func
298-
umf::getPoolLastStatusRef<DisjointPool>() =
299-
UMF_RESULT_ERROR_OUT_OF_HOST_MEMORY;
300+
TLS_last_allocation_error_dp = UMF_RESULT_ERROR_OUT_OF_HOST_MEMORY;
300301
return nullptr;
301302
}
302303

@@ -314,8 +315,7 @@ void *AllocImpl_allocate(AllocImpl *ai, size_t Size, bool *FromPool) {
314315

315316
if (Ptr == NULL) {
316317
// TODO get code from func
317-
umf::getPoolLastStatusRef<DisjointPool>() =
318-
UMF_RESULT_ERROR_OUT_OF_HOST_MEMORY;
318+
TLS_last_allocation_error_dp = UMF_RESULT_ERROR_OUT_OF_HOST_MEMORY;
319319
return nullptr;
320320
}
321321

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

494494
void *DisjointPool::calloc(size_t, size_t) {
495495
// Not supported
496-
umf::getPoolLastStatusRef<DisjointPool>() = UMF_RESULT_ERROR_NOT_SUPPORTED;
496+
TLS_last_allocation_error_dp = UMF_RESULT_ERROR_NOT_SUPPORTED;
497497
return NULL;
498498
}
499499

500500
void *DisjointPool::realloc(void *, size_t) {
501501
// Not supported
502-
umf::getPoolLastStatusRef<DisjointPool>() = UMF_RESULT_ERROR_NOT_SUPPORTED;
502+
TLS_last_allocation_error_dp = UMF_RESULT_ERROR_NOT_SUPPORTED;
503503
return NULL;
504504
}
505505

@@ -542,7 +542,7 @@ umf_result_t DisjointPool::free(void *ptr) {
542542
}
543543

544544
umf_result_t DisjointPool::get_last_allocation_error() {
545-
return umf::getPoolLastStatusRef<DisjointPool>();
545+
return TLS_last_allocation_error_dp;
546546
}
547547

548548
DisjointPool::DisjointPool() {}

0 commit comments

Comments
 (0)