@@ -42,7 +42,7 @@ PyAPI_FUNC(int) _PyEval_MakePendingCalls(PyThreadState *);
4242
4343extern void _Py_FinishPendingCalls (PyThreadState * tstate );
4444extern void _PyEval_InitState (PyInterpreterState * );
45- extern void _PyEval_SignalReceived (PyInterpreterState * interp );
45+ extern void _PyEval_SignalReceived (void );
4646
4747// bitwise flags:
4848#define _Py_PENDING_MAINTHREADONLY 1
@@ -55,7 +55,6 @@ PyAPI_FUNC(int) _PyEval_AddPendingCall(
5555 void * arg ,
5656 int flags );
5757
58- extern void _PyEval_SignalAsyncExc (PyInterpreterState * interp );
5958#ifdef HAVE_FORK
6059extern PyStatus _PyEval_ReInitThreads (PyThreadState * tstate );
6160#endif
@@ -200,40 +199,43 @@ int _PyEval_UnpackIterable(PyThreadState *tstate, PyObject *v, int argcnt, int a
200199void _PyEval_FrameClearAndPop (PyThreadState * tstate , _PyInterpreterFrame * frame );
201200
202201
203- #define _PY_GIL_DROP_REQUEST_BIT 0
204- #define _PY_SIGNALS_PENDING_BIT 1
205- #define _PY_CALLS_TO_DO_BIT 2
206- #define _PY_ASYNC_EXCEPTION_BIT 3
207- #define _PY_GC_SCHEDULED_BIT 4
208- #define _PY_EVAL_PLEASE_STOP_BIT 5
209- #define _PY_EVAL_EXPLICIT_MERGE_BIT 6
202+ /* Bits that can be set in PyThreadState.eval_breaker */
203+ #define _PY_GIL_DROP_REQUEST_BIT (1U << 0)
204+ #define _PY_SIGNALS_PENDING_BIT (1U << 1)
205+ #define _PY_CALLS_TO_DO_BIT (1U << 2)
206+ #define _PY_ASYNC_EXCEPTION_BIT (1U << 3)
207+ #define _PY_GC_SCHEDULED_BIT (1U << 4)
208+ #define _PY_EVAL_PLEASE_STOP_BIT (1U << 5)
209+ #define _PY_EVAL_EXPLICIT_MERGE_BIT (1U << 6)
210210
211211/* Reserve a few bits for future use */
212212#define _PY_EVAL_EVENTS_BITS 8
213213#define _PY_EVAL_EVENTS_MASK ((1 << _PY_EVAL_EVENTS_BITS)-1)
214214
215215static inline void
216- _Py_set_eval_breaker_bit (PyInterpreterState * interp , uint32_t bit , uint32_t set )
216+ _Py_set_eval_breaker_bit (PyThreadState * tstate , uintptr_t bit )
217217{
218- assert (set == 0 || set == 1 );
219- uintptr_t to_set = set << bit ;
220- uintptr_t mask = ((uintptr_t )1 ) << bit ;
221- uintptr_t old = _Py_atomic_load_uintptr (& interp -> ceval .eval_breaker );
222- if ((old & mask ) == to_set ) {
223- return ;
224- }
225- uintptr_t new ;
226- do {
227- new = (old & ~mask ) | to_set ;
228- } while (!_Py_atomic_compare_exchange_uintptr (& interp -> ceval .eval_breaker , & old , new ));
218+ _Py_atomic_or_uintptr (& tstate -> eval_breaker , bit );
219+ }
220+
221+ static inline void
222+ _Py_unset_eval_breaker_bit (PyThreadState * tstate , uintptr_t bit )
223+ {
224+ _Py_atomic_and_uintptr (& tstate -> eval_breaker , ~bit );
229225}
230226
231- static inline bool
232- _Py_eval_breaker_bit_is_set (PyInterpreterState * interp , int32_t bit )
227+ static inline int
228+ _Py_eval_breaker_bit_is_set (PyThreadState * tstate , uintptr_t bit )
233229{
234- return _Py_atomic_load_uintptr_relaxed (& interp -> ceval .eval_breaker ) & (((uintptr_t )1 ) << bit );
230+ uintptr_t b = _Py_atomic_load_uintptr_relaxed (& tstate -> eval_breaker );
231+ return (b & bit ) != 0 ;
235232}
236233
234+ // Free-threaded builds use these functions to set or unset a bit on all
235+ // threads in the given interpreter.
236+ void _Py_set_eval_breaker_bit_all (PyInterpreterState * interp , uintptr_t bit );
237+ void _Py_unset_eval_breaker_bit_all (PyInterpreterState * interp , uintptr_t bit );
238+
237239
238240#ifdef __cplusplus
239241}
0 commit comments