File tree Expand file tree Collapse file tree 1 file changed +19
-2
lines changed Expand file tree Collapse file tree 1 file changed +19
-2
lines changed Original file line number Diff line number Diff line change 2727
2828/******************************************************************/
2929
30+
31+ #ifdef Py_GIL_DISABLED
32+ static PyMutex malloc_closure_lock ;
33+ # define MALLOC_CLOSURE_LOCK () PyMutex_Lock(&malloc_closure_lock)
34+ # define MALLOC_CLOSURE_UNLOCK () PyMutex_Unlock(&malloc_closure_lock)
35+ #else
36+ # define MALLOC_CLOSURE_LOCK () ((void)0)
37+ # define MALLOC_CLOSURE_UNLOCK () ((void)0)
38+ #endif
39+
3040typedef union _tagITEM {
3141 ffi_closure closure ;
3242 union _tagITEM * next ;
@@ -110,9 +120,11 @@ void Py_ffi_closure_free(void *p)
110120 }
111121#endif
112122#endif
123+ MALLOC_CLOSURE_LOCK ();
113124 ITEM * item = (ITEM * )p ;
114125 item -> next = free_list ;
115126 free_list = item ;
127+ MALLOC_CLOSURE_UNLOCK ();
116128}
117129
118130/* return one item from the free list, allocating more if needed */
@@ -131,11 +143,15 @@ void *Py_ffi_closure_alloc(size_t size, void** codeloc)
131143 }
132144#endif
133145#endif
146+ MALLOC_CLOSURE_LOCK ();
134147 ITEM * item ;
135- if (!free_list )
148+ if (!free_list ) {
136149 more_core ();
137- if (!free_list )
150+ }
151+ if (!free_list ) {
152+ MALLOC_CLOSURE_UNLOCK ();
138153 return NULL ;
154+ }
139155 item = free_list ;
140156 free_list = item -> next ;
141157#ifdef _M_ARM
@@ -144,5 +160,6 @@ void *Py_ffi_closure_alloc(size_t size, void** codeloc)
144160#else
145161 * codeloc = (void * )item ;
146162#endif
163+ MALLOC_CLOSURE_UNLOCK ();
147164 return (void * )item ;
148165}
You can’t perform that action at this time.
0 commit comments