Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 10:18:06

0001 #ifndef Py_INTERNAL_CEVAL_STATE_H
0002 #define Py_INTERNAL_CEVAL_STATE_H
0003 #ifdef __cplusplus
0004 extern "C" {
0005 #endif
0006 
0007 #ifndef Py_BUILD_CORE
0008 #  error "this header requires Py_BUILD_CORE define"
0009 #endif
0010 
0011 
0012 #include "pycore_atomic.h"          /* _Py_atomic_address */
0013 #include "pycore_gil.h"             // struct _gil_runtime_state
0014 
0015 
0016 struct _pending_calls {
0017     int busy;
0018     PyThread_type_lock lock;
0019     /* Request for running pending calls. */
0020     _Py_atomic_int calls_to_do;
0021     /* Request for looking at the `async_exc` field of the current
0022        thread state.
0023        Guarded by the GIL. */
0024     int async_exc;
0025 #define NPENDINGCALLS 32
0026     struct _pending_call {
0027         int (*func)(void *);
0028         void *arg;
0029     } calls[NPENDINGCALLS];
0030     int first;
0031     int last;
0032 };
0033 
0034 typedef enum {
0035     PERF_STATUS_FAILED = -1,  // Perf trampoline is in an invalid state
0036     PERF_STATUS_NO_INIT = 0,  // Perf trampoline is not initialized
0037     PERF_STATUS_OK = 1,       // Perf trampoline is ready to be executed
0038 } perf_status_t;
0039 
0040 
0041 #ifdef PY_HAVE_PERF_TRAMPOLINE
0042 struct code_arena_st;
0043 
0044 struct trampoline_api_st {
0045     void* (*init_state)(void);
0046     void (*write_state)(void* state, const void *code_addr,
0047                         unsigned int code_size, PyCodeObject* code);
0048     int (*free_state)(void* state);
0049     void *state;
0050 };
0051 #endif
0052 
0053 struct _ceval_runtime_state {
0054     struct {
0055 #ifdef PY_HAVE_PERF_TRAMPOLINE
0056         perf_status_t status;
0057         Py_ssize_t extra_code_index;
0058         struct code_arena_st *code_arena;
0059         struct trampoline_api_st trampoline_api;
0060         FILE *map_file;
0061 #else
0062         int _not_used;
0063 #endif
0064     } perf;
0065     /* Request for checking signals. It is shared by all interpreters (see
0066        bpo-40513). Any thread of any interpreter can receive a signal, but only
0067        the main thread of the main interpreter can handle signals: see
0068        _Py_ThreadCanHandleSignals(). */
0069     _Py_atomic_int signals_pending;
0070     /* Pending calls to be made only on the main thread. */
0071     struct _pending_calls pending_mainthread;
0072 };
0073 
0074 #ifdef PY_HAVE_PERF_TRAMPOLINE
0075 # define _PyEval_RUNTIME_PERF_INIT \
0076     { \
0077         .status = PERF_STATUS_NO_INIT, \
0078         .extra_code_index = -1, \
0079     }
0080 #else
0081 # define _PyEval_RUNTIME_PERF_INIT {0}
0082 #endif
0083 
0084 
0085 struct _ceval_state {
0086     /* This single variable consolidates all requests to break out of
0087        the fast path in the eval loop. */
0088     _Py_atomic_int eval_breaker;
0089     /* Request for dropping the GIL */
0090     _Py_atomic_int gil_drop_request;
0091     int recursion_limit;
0092     struct _gil_runtime_state *gil;
0093     int own_gil;
0094     /* The GC is ready to be executed */
0095     _Py_atomic_int gc_scheduled;
0096     struct _pending_calls pending;
0097 };
0098 
0099 
0100 #ifdef __cplusplus
0101 }
0102 #endif
0103 #endif /* !Py_INTERNAL_CEVAL_STATE_H */