diff options
author | Donghee Na <donghee.na@python.org> | 2024-01-10 15:47:13 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-01-10 15:47:13 (GMT) |
commit | f728f7242c6008a16daaa5dde8e1db786857c50e (patch) | |
tree | 5e6dd8e921e432c9de0b0d8f60805ec03a8584eb /Include | |
parent | a0c9cf9456c2ee7a89d9bd859c07afac8cf5e893 (diff) | |
download | cpython-f728f7242c6008a16daaa5dde8e1db786857c50e.zip cpython-f728f7242c6008a16daaa5dde8e1db786857c50e.tar.gz cpython-f728f7242c6008a16daaa5dde8e1db786857c50e.tar.bz2 |
gh-111968: Use per-thread freelists for float in free-threading (gh-113886)
Diffstat (limited to 'Include')
-rw-r--r-- | Include/internal/pycore_floatobject.h | 21 | ||||
-rw-r--r-- | Include/internal/pycore_freelist.h | 26 | ||||
-rw-r--r-- | Include/internal/pycore_gc.h | 2 | ||||
-rw-r--r-- | Include/internal/pycore_interp.h | 1 |
4 files changed, 21 insertions, 29 deletions
diff --git a/Include/internal/pycore_floatobject.h b/Include/internal/pycore_floatobject.h index 4e54748..038578e 100644 --- a/Include/internal/pycore_floatobject.h +++ b/Include/internal/pycore_floatobject.h @@ -8,14 +8,14 @@ extern "C" { # error "this header requires Py_BUILD_CORE define" #endif - +#include "pycore_freelist.h" // _PyFreeListState #include "pycore_unicodeobject.h" // _PyUnicodeWriter /* runtime lifecycle */ extern void _PyFloat_InitState(PyInterpreterState *); extern PyStatus _PyFloat_InitTypes(PyInterpreterState *); -extern void _PyFloat_Fini(PyInterpreterState *); +extern void _PyFloat_Fini(_PyFreeListState *); extern void _PyFloat_FiniType(PyInterpreterState *); @@ -33,24 +33,7 @@ struct _Py_float_runtime_state { }; -#ifndef WITH_FREELISTS -// without freelists -# define PyFloat_MAXFREELIST 0 -#endif - -#ifndef PyFloat_MAXFREELIST -# define PyFloat_MAXFREELIST 100 -#endif -struct _Py_float_state { -#if PyFloat_MAXFREELIST > 0 - /* Special free list - free_list is a singly-linked list of available PyFloatObjects, - linked via abuse of their ob_type members. */ - int numfree; - PyFloatObject *free_list; -#endif -}; void _PyFloat_ExactDealloc(PyObject *op); diff --git a/Include/internal/pycore_freelist.h b/Include/internal/pycore_freelist.h index b725986..d961921 100644 --- a/Include/internal/pycore_freelist.h +++ b/Include/internal/pycore_freelist.h @@ -8,24 +8,34 @@ extern "C" { # error "this header requires Py_BUILD_CORE define" #endif -#ifndef WITH_FREELISTS -// without freelists -# define PyList_MAXFREELIST 0 -#endif - -/* Empty list reuse scheme to save calls to malloc and free */ -#ifndef PyList_MAXFREELIST +#ifdef WITH_FREELISTS +// with freelists # define PyList_MAXFREELIST 80 +# define PyFloat_MAXFREELIST 100 +#else +# define PyList_MAXFREELIST 0 +# define PyFloat_MAXFREELIST 0 #endif struct _Py_list_state { -#if PyList_MAXFREELIST > 0 +#ifdef WITH_FREELISTS PyListObject *free_list[PyList_MAXFREELIST]; int numfree; #endif }; +struct _Py_float_state { +#ifdef WITH_FREELISTS + /* Special free list + free_list is a singly-linked list of available PyFloatObjects, + linked via abuse of their ob_type members. */ + int numfree; + PyFloatObject *free_list; +#endif +}; + typedef struct _Py_freelist_state { + struct _Py_float_state float_state; struct _Py_list_state list; } _PyFreeListState; diff --git a/Include/internal/pycore_gc.h b/Include/internal/pycore_gc.h index 5d90d3a..2a0730e 100644 --- a/Include/internal/pycore_gc.h +++ b/Include/internal/pycore_gc.h @@ -243,7 +243,7 @@ extern PyObject *_PyGC_GetReferrers(PyInterpreterState *interp, PyObject *objs); extern void _PyGC_ClearAllFreeLists(PyInterpreterState *interp); extern void _Py_ClearFreeLists(_PyFreeListState *state, int is_finalization); extern void _PyTuple_ClearFreeList(PyInterpreterState *interp); -extern void _PyFloat_ClearFreeList(PyInterpreterState *interp); +extern void _PyFloat_ClearFreeList(_PyFreeListState *state, int is_finalization); extern void _PyList_ClearFreeList(_PyFreeListState *state, int is_finalization); extern void _PyDict_ClearFreeList(PyInterpreterState *interp); extern void _PyAsyncGen_ClearFreeLists(PyInterpreterState *interp); diff --git a/Include/internal/pycore_interp.h b/Include/internal/pycore_interp.h index 4d49fa2..dadc8e3 100644 --- a/Include/internal/pycore_interp.h +++ b/Include/internal/pycore_interp.h @@ -184,7 +184,6 @@ struct _is { #endif struct _py_object_state object_state; struct _Py_unicode_state unicode; - struct _Py_float_state float_state; struct _Py_long_state long_state; struct _dtoa_state dtoa; struct _py_func_state func_state; |