diff options
| author | Jeff Epler <jepler@gmail.com> | 2020-04-07 11:19:24 -0500 |
|---|---|---|
| committer | Jeff Epler <jepler@gmail.com> | 2020-04-14 18:24:58 -0500 |
| commit | 0ca270172f36817c14790eb87053e3c326001822 (patch) | |
| tree | ee45064eb050b687b32db159b15aa38253126e9a /shared-module | |
| parent | 23bced26da40d5d87b0aac18e6aac525d4d27bac (diff) | |
protomatter: allocator: Never supervisor-alloc while gc available
This may have been contributing to fragmentation of the supervisor
heap
Diffstat (limited to 'shared-module')
| -rw-r--r-- | shared-module/_protomatter/allocator.h | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/shared-module/_protomatter/allocator.h b/shared-module/_protomatter/allocator.h index 9b7590df3..501a26098 100644 --- a/shared-module/_protomatter/allocator.h +++ b/shared-module/_protomatter/allocator.h @@ -2,6 +2,7 @@ #define MICROPY_INCLUDED_SHARED_MODULE_PROTOMATTER_ALLOCATOR_H #include <stdbool.h> +#include "py/gc.h" #include "py/misc.h" #include "supervisor/memory.h" @@ -9,11 +10,11 @@ #define _PM_FREE(x) (_PM_free_impl((x)), (x)=NULL, (void)0) static inline void *_PM_allocator_impl(size_t sz) { - supervisor_allocation *allocation = allocate_memory(align32_size(sz), true); - if (allocation) { - return allocation->ptr; - } else { + if (gc_alloc_possible()) { return m_malloc(sz + sizeof(void*), true); + } else { + supervisor_allocation *allocation = allocate_memory(align32_size(sz), true); + return allocation ? allocation->ptr : NULL; } } |
