blob: c8c63b1c7fdafe7969a140650a1390ab2be5ce7f [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 Stinner130893d2018-11-09 13:03:37 +01007#if !defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_BUILTIN)
8# error "this header requires Py_BUILD_CORE or Py_BUILD_CORE_BUILTIN define"
9#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
14struct _pending_calls {
15 unsigned long main_thread;
16 PyThread_type_lock lock;
17 /* Request for running pending calls. */
18 _Py_atomic_int calls_to_do;
19 /* Request for looking at the `async_exc` field of the current
20 thread state.
21 Guarded by the GIL. */
22 int async_exc;
23#define NPENDINGCALLS 32
24 struct {
25 int (*func)(void *);
26 void *arg;
27 } calls[NPENDINGCALLS];
28 int first;
29 int last;
30};
31
Victor Stinner27e2d1f2018-11-01 00:52:28 +010032#include "pycore_gil.h"
Eric Snow2ebc5ce2017-09-07 23:51:28 -060033
34struct _ceval_runtime_state {
35 int recursion_limit;
Eric Snow2ebc5ce2017-09-07 23:51:28 -060036 /* Records whether tracing is on for any thread. Counts the number
37 of threads for which tstate->c_tracefunc is non-NULL, so if the
38 value is 0, we know we don't have to check this thread's
39 c_tracefunc. This speeds up the if statement in
40 PyEval_EvalFrameEx() after fast_next_opcode. */
41 int tracing_possible;
42 /* This single variable consolidates all requests to break out of
43 the fast path in the eval loop. */
44 _Py_atomic_int eval_breaker;
45 /* Request for dropping the GIL */
46 _Py_atomic_int gil_drop_request;
47 struct _pending_calls pending;
48 struct _gil_runtime_state gil;
49};
50
51PyAPI_FUNC(void) _PyEval_Initialize(struct _ceval_runtime_state *);
52
53#ifdef __cplusplus
54}
55#endif
56#endif /* !Py_INTERNAL_CEVAL_H */