2023-10-30 12:43:11 -03:00
|
|
|
#ifndef Py_INTERNAL_MIMALLOC_H
|
|
|
|
#define Py_INTERNAL_MIMALLOC_H
|
|
|
|
|
|
|
|
#ifndef Py_BUILD_CORE
|
|
|
|
# error "this header requires Py_BUILD_CORE define"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(MIMALLOC_H) || defined(MIMALLOC_TYPES_H)
|
|
|
|
# error "pycore_mimalloc.h must be included before mimalloc.h"
|
|
|
|
#endif
|
|
|
|
|
2023-12-26 12:53:20 -04:00
|
|
|
typedef enum {
|
|
|
|
_Py_MIMALLOC_HEAP_MEM = 0, // PyMem_Malloc() and friends
|
|
|
|
_Py_MIMALLOC_HEAP_OBJECT = 1, // non-GC objects
|
|
|
|
_Py_MIMALLOC_HEAP_GC = 2, // GC objects without pre-header
|
|
|
|
_Py_MIMALLOC_HEAP_GC_PRE = 3, // GC objects with pre-header
|
|
|
|
_Py_MIMALLOC_HEAP_COUNT
|
|
|
|
} _Py_mimalloc_heap_id;
|
|
|
|
|
2023-10-30 12:43:11 -03:00
|
|
|
#include "pycore_pymem.h"
|
2023-12-26 12:53:20 -04:00
|
|
|
|
|
|
|
#ifdef WITH_MIMALLOC
|
2024-02-14 17:41:29 -04:00
|
|
|
# ifdef Py_GIL_DISABLED
|
|
|
|
# define MI_PRIM_THREAD_ID _Py_ThreadId
|
|
|
|
# endif
|
|
|
|
# define MI_DEBUG_UNINIT PYMEM_CLEANBYTE
|
|
|
|
# define MI_DEBUG_FREED PYMEM_DEADBYTE
|
|
|
|
# define MI_DEBUG_PADDING PYMEM_FORBIDDENBYTE
|
2023-12-26 12:53:20 -04:00
|
|
|
#ifdef Py_DEBUG
|
2024-03-05 14:54:20 -04:00
|
|
|
# define MI_DEBUG 2
|
2023-12-26 12:53:20 -04:00
|
|
|
#else
|
|
|
|
# define MI_DEBUG 0
|
|
|
|
#endif
|
2023-10-30 12:43:11 -03:00
|
|
|
|
2024-03-11 10:25:55 -03:00
|
|
|
#ifdef _Py_THREAD_SANITIZER
|
|
|
|
# define MI_TSAN 1
|
|
|
|
#endif
|
|
|
|
|
2024-08-15 10:01:01 -03:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C++" {
|
|
|
|
#endif
|
|
|
|
|
2024-05-09 17:03:45 -03:00
|
|
|
#include "mimalloc/mimalloc.h"
|
|
|
|
#include "mimalloc/mimalloc/types.h"
|
|
|
|
#include "mimalloc/mimalloc/internal.h"
|
2024-08-15 10:01:01 -03:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2023-12-26 12:53:20 -04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef Py_GIL_DISABLED
|
2024-01-04 18:21:40 -04:00
|
|
|
struct _mimalloc_interp_state {
|
|
|
|
// When exiting, threads place any segments with live blocks in this
|
|
|
|
// shared pool for other threads to claim and reuse.
|
|
|
|
mi_abandoned_pool_t abandoned_pool;
|
|
|
|
};
|
|
|
|
|
2023-12-26 12:53:20 -04:00
|
|
|
struct _mimalloc_thread_state {
|
|
|
|
mi_heap_t *current_object_heap;
|
|
|
|
mi_heap_t heaps[_Py_MIMALLOC_HEAP_COUNT];
|
|
|
|
mi_tld_t tld;
|
2024-06-04 10:42:13 -03:00
|
|
|
int initialized;
|
2024-03-06 10:42:11 -04:00
|
|
|
struct llist_node page_list;
|
2023-12-26 12:53:20 -04:00
|
|
|
};
|
|
|
|
#endif
|
2023-10-30 12:43:11 -03:00
|
|
|
|
|
|
|
#endif // Py_INTERNAL_MIMALLOC_H
|