@@ -30,11 +30,10 @@ _Py_freelists_GET(void)
3030
3131// Pushes `op` to the freelist, calls `freefunc` if the freelist is full
3232#define _Py_FREELIST_FREE (NAME , op , freefunc ) \
33- _PyFreeList_Free(&_Py_freelists_GET()->NAME, _PyObject_CAST(op), \
34- Py_ ## NAME ## _MAXFREELIST, freefunc)
33+ _PyFreeList_Free(&_Py_freelists_GET()->NAME, _PyObject_CAST(op), freefunc)
3534// Pushes `op` to the freelist, returns 1 if successful, 0 if the freelist is full
36- #define _Py_FREELIST_PUSH (NAME , op , limit ) \
37- _PyFreeList_Push(&_Py_freelists_GET()->NAME, _PyObject_CAST(op), limit )
35+ #define _Py_FREELIST_PUSH (NAME , op ) \
36+ _PyFreeList_Push(&_Py_freelists_GET()->NAME, _PyObject_CAST(op))
3837
3938// Pops a PyObject from the freelist, returns NULL if the freelist is empty.
4039#define _Py_FREELIST_POP (TYPE , NAME ) \
@@ -45,26 +44,36 @@ _Py_freelists_GET(void)
4544#define _Py_FREELIST_POP_MEM (NAME ) \
4645 _PyFreeList_PopMem(&_Py_freelists_GET()->NAME)
4746
48- #define _Py_FREELIST_SIZE (NAME ) (int)((_Py_freelists_GET()->NAME).size)
47+ static inline uint32_t
48+ _PyFreeList_Size (struct _Py_freelist * fl )
49+ {
50+ return fl -> capacity - fl -> available ;
51+ }
52+
53+ static inline void
54+ _PyFreeList_Init (struct _Py_freelist * fl , uint32_t capacity )
55+ {
56+ fl -> freelist = NULL ;
57+ fl -> capacity = fl -> available = 0 ; // capacity;
58+ }
4959
5060static inline int
51- _PyFreeList_Push (struct _Py_freelist * fl , void * obj , Py_ssize_t maxsize )
61+ _PyFreeList_Push (struct _Py_freelist * fl , void * obj )
5262{
53- if (fl -> size < maxsize && fl -> size > = 0 ) {
63+ if (fl -> available ! = 0 ) {
5464 FT_ATOMIC_STORE_PTR_RELAXED (* (void * * )obj , fl -> freelist );
5565 fl -> freelist = obj ;
56- fl -> size ++ ;
66+ fl -> available -- ;
5767 OBJECT_STAT_INC (to_freelist );
5868 return 1 ;
5969 }
6070 return 0 ;
6171}
6272
6373static inline void
64- _PyFreeList_Free (struct _Py_freelist * fl , void * obj , Py_ssize_t maxsize ,
65- freefunc dofree )
74+ _PyFreeList_Free (struct _Py_freelist * fl , void * obj , freefunc dofree )
6675{
67- if (!_PyFreeList_Push (fl , obj , maxsize )) {
76+ if (!_PyFreeList_Push (fl , obj )) {
6877 dofree (obj );
6978 }
7079}
@@ -74,9 +83,9 @@ _PyFreeList_PopNoStats(struct _Py_freelist *fl)
7483{
7584 void * obj = fl -> freelist ;
7685 if (obj != NULL ) {
77- assert (fl -> size > 0 );
86+ assert (fl -> capacity > 0 );
7887 fl -> freelist = * (void * * )obj ;
79- fl -> size -- ;
88+ fl -> available ++ ;
8089 }
8190 return obj ;
8291}
0 commit comments