blob: 0bb19f1aa3b6423f69d47ea257d100077c58a6bb [file] [log] [blame]
Eric Snow2ebc5ce2017-09-07 23:51:28 -06001#ifndef Py_INTERNAL_CEVAL_H
2#define Py_INTERNAL_CEVAL_H
3#ifdef __cplusplus
4extern "C" {
5#endif
6
Victor Stinner5c75f372019-04-17 23:02:26 +02007#ifndef Py_BUILD_CORE
8# error "this header requires Py_BUILD_CORE define"
Victor Stinner130893d2018-11-09 13:03:37 +01009#endif
10
Victor Stinner27e2d1f2018-11-01 00:52:28 +010011#include "pycore_atomic.h"
Eric Snow2ebc5ce2017-09-07 23:51:28 -060012#include "pythread.h"
13
Eric Snowb75b1a352019-04-12 10:20:10 -060014PyAPI_FUNC(void) _Py_FinishPendingCalls(void);
Eric Snow842a2f02019-03-15 15:47:51 -060015
Eric Snow2ebc5ce2017-09-07 23:51:28 -060016struct _pending_calls {
Eric Snow842a2f02019-03-15 15:47:51 -060017 int finishing;
Eric Snow2ebc5ce2017-09-07 23:51:28 -060018 PyThread_type_lock lock;
19 /* Request for running pending calls. */
20 _Py_atomic_int calls_to_do;
21 /* Request for looking at the `async_exc` field of the current
22 thread state.
23 Guarded by the GIL. */
24 int async_exc;
25#define NPENDINGCALLS 32
26 struct {
27 int (*func)(void *);
28 void *arg;
29 } calls[NPENDINGCALLS];
30 int first;
31 int last;
32};
33
Victor Stinner27e2d1f2018-11-01 00:52:28 +010034#include "pycore_gil.h"
Eric Snow2ebc5ce2017-09-07 23:51:28 -060035
36struct _ceval_runtime_state {
37 int recursion_limit;
Eric Snow2ebc5ce2017-09-07 23:51:28 -060038 /* Records whether tracing is on for any thread. Counts the number
39 of threads for which tstate->c_tracefunc is non-NULL, so if the
40 value is 0, we know we don't have to check this thread's
41 c_tracefunc. This speeds up the if statement in
42 PyEval_EvalFrameEx() after fast_next_opcode. */
43 int tracing_possible;
Eric Snowb75b1a352019-04-12 10:20:10 -060044 /* This single variable consolidates all requests to break out of
45 the fast path in the eval loop. */
46 _Py_atomic_int eval_breaker;
Eric Snow2ebc5ce2017-09-07 23:51:28 -060047 /* Request for dropping the GIL */
48 _Py_atomic_int gil_drop_request;
Eric Snowb75b1a352019-04-12 10:20:10 -060049 struct _pending_calls pending;
Eric Snowfdf282d2019-01-11 14:26:55 -070050 /* Request for checking signals. */
51 _Py_atomic_int signals_pending;
Eric Snow2ebc5ce2017-09-07 23:51:28 -060052 struct _gil_runtime_state gil;
53};
54
55PyAPI_FUNC(void) _PyEval_Initialize(struct _ceval_runtime_state *);
56
57#ifdef __cplusplus
58}
59#endif
60#endif /* !Py_INTERNAL_CEVAL_H */