Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
allendowney
GitHub Repository: allendowney/cpython
Path: blob/main/Include/internal/pycore_ceval_state.h
12 views
1
#ifndef Py_INTERNAL_CEVAL_STATE_H
2
#define Py_INTERNAL_CEVAL_STATE_H
3
#ifdef __cplusplus
4
extern "C" {
5
#endif
6
7
#ifndef Py_BUILD_CORE
8
# error "this header requires Py_BUILD_CORE define"
9
#endif
10
11
12
#include "pycore_atomic.h" /* _Py_atomic_address */
13
#include "pycore_gil.h" // struct _gil_runtime_state
14
15
16
struct _pending_calls {
17
int busy;
18
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 _pending_call {
27
int (*func)(void *);
28
void *arg;
29
} calls[NPENDINGCALLS];
30
int first;
31
int last;
32
};
33
34
typedef enum {
35
PERF_STATUS_FAILED = -1, // Perf trampoline is in an invalid state
36
PERF_STATUS_NO_INIT = 0, // Perf trampoline is not initialized
37
PERF_STATUS_OK = 1, // Perf trampoline is ready to be executed
38
} perf_status_t;
39
40
41
#ifdef PY_HAVE_PERF_TRAMPOLINE
42
struct code_arena_st;
43
44
struct trampoline_api_st {
45
void* (*init_state)(void);
46
void (*write_state)(void* state, const void *code_addr,
47
unsigned int code_size, PyCodeObject* code);
48
int (*free_state)(void* state);
49
void *state;
50
};
51
#endif
52
53
struct _ceval_runtime_state {
54
struct {
55
#ifdef PY_HAVE_PERF_TRAMPOLINE
56
perf_status_t status;
57
Py_ssize_t extra_code_index;
58
struct code_arena_st *code_arena;
59
struct trampoline_api_st trampoline_api;
60
FILE *map_file;
61
#else
62
int _not_used;
63
#endif
64
} perf;
65
/* Request for checking signals. It is shared by all interpreters (see
66
bpo-40513). Any thread of any interpreter can receive a signal, but only
67
the main thread of the main interpreter can handle signals: see
68
_Py_ThreadCanHandleSignals(). */
69
_Py_atomic_int signals_pending;
70
/* Pending calls to be made only on the main thread. */
71
struct _pending_calls pending_mainthread;
72
};
73
74
#ifdef PY_HAVE_PERF_TRAMPOLINE
75
# define _PyEval_RUNTIME_PERF_INIT \
76
{ \
77
.status = PERF_STATUS_NO_INIT, \
78
.extra_code_index = -1, \
79
}
80
#else
81
# define _PyEval_RUNTIME_PERF_INIT {0}
82
#endif
83
84
85
struct _ceval_state {
86
/* This single variable consolidates all requests to break out of
87
the fast path in the eval loop. */
88
_Py_atomic_int eval_breaker;
89
/* Request for dropping the GIL */
90
_Py_atomic_int gil_drop_request;
91
int recursion_limit;
92
struct _gil_runtime_state *gil;
93
int own_gil;
94
/* The GC is ready to be executed */
95
_Py_atomic_int gc_scheduled;
96
struct _pending_calls pending;
97
};
98
99
100
#ifdef __cplusplus
101
}
102
#endif
103
#endif /* !Py_INTERNAL_CEVAL_STATE_H */
104
105