-
-
Notifications
You must be signed in to change notification settings - Fork 34.4k
Expand file tree
/
Copy pathpycore_runtime.h
More file actions
86 lines (66 loc) · 2.5 KB
/
pycore_runtime.h
File metadata and controls
86 lines (66 loc) · 2.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#ifndef Py_INTERNAL_RUNTIME_H
#define Py_INTERNAL_RUNTIME_H
#ifdef __cplusplus
extern "C" {
#endif
#ifndef Py_BUILD_CORE
# error "this header requires Py_BUILD_CORE define"
#endif
#include "pycore_runtime_structs.h" // _PyRuntimeState
/* API */
// Export _PyRuntime for shared extensions which use it in static inline
// functions for best performance, like _Py_IsMainThread() or _Py_ID().
// It's also made accessible for debuggers and profilers.
PyAPI_DATA(_PyRuntimeState) _PyRuntime;
extern PyStatus _PyRuntimeState_Init(_PyRuntimeState *runtime);
extern void _PyRuntimeState_Fini(_PyRuntimeState *runtime);
#ifdef HAVE_FORK
extern PyStatus _PyRuntimeState_ReInitThreads(_PyRuntimeState *runtime);
#endif
/* Initialize _PyRuntimeState.
Return NULL on success, or return an error message on failure. */
extern PyStatus _PyRuntime_Initialize(void);
extern void _PyRuntime_Finalize(void);
static inline PyThreadState*
_PyRuntimeState_GetFinalizing(_PyRuntimeState *runtime) {
return (PyThreadState*)_Py_atomic_load_ptr_relaxed(&runtime->_finalizing);
}
static inline unsigned long
_PyRuntimeState_GetFinalizingID(_PyRuntimeState *runtime) {
return _Py_atomic_load_ulong_relaxed(&runtime->_finalizing_id);
}
static inline void
_PyRuntimeState_SetFinalizing(_PyRuntimeState *runtime, PyThreadState *tstate) {
_Py_atomic_store_ptr_relaxed(&runtime->_finalizing, tstate);
if (tstate == NULL) {
_Py_atomic_store_ulong_relaxed(&runtime->_finalizing_id, 0);
}
else {
// XXX Re-enable this assert once gh-109860 is fixed.
//assert(tstate->thread_id == PyThread_get_thread_ident());
_Py_atomic_store_ulong_relaxed(&runtime->_finalizing_id,
tstate->thread_id);
}
}
// Atomic so a thread that reads initialized=1 observes all writes
// from the initialization sequence (gh-146302).
static inline int
_PyRuntimeState_GetCoreInitialized(_PyRuntimeState *runtime) {
return _Py_atomic_load_int(&runtime->core_initialized);
}
static inline void
_PyRuntimeState_SetCoreInitialized(_PyRuntimeState *runtime, int initialized) {
_Py_atomic_store_int(&runtime->core_initialized, initialized);
}
static inline int
_PyRuntimeState_GetInitialized(_PyRuntimeState *runtime) {
return _Py_atomic_load_int(&runtime->initialized);
}
static inline void
_PyRuntimeState_SetInitialized(_PyRuntimeState *runtime, int initialized) {
_Py_atomic_store_int(&runtime->initialized, initialized);
}
#ifdef __cplusplus
}
#endif
#endif /* !Py_INTERNAL_RUNTIME_H */