Mercurial > cpython-lru_cache-weakref
annotate Include/pystate.h @ 80661:94de77bd0b4b 2.7
Issue #16194: document imp.load_dynamic problems
when read several extension modules from the same binary object file.
| author | Andrew Svetlov <andrew.svetlov@gmail.com> |
|---|---|
| date | Thu, 29 Nov 2012 19:51:28 +0200 |
| parents | 5a2ef447b80d |
| children |
| rev | line source |
|---|---|
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1 |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
2 /* Thread and interpreter state structures and their interfaces */ |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
3 |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
4 |
|
13443
7e58c060d534
ANSI-fication and Py_PROTO extermination.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
5 #ifndef Py_PYSTATE_H |
|
7e58c060d534
ANSI-fication and Py_PROTO extermination.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
6 #define Py_PYSTATE_H |
|
7e58c060d534
ANSI-fication and Py_PROTO extermination.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
7 #ifdef __cplusplus |
|
7e58c060d534
ANSI-fication and Py_PROTO extermination.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
8 extern "C" { |
|
7e58c060d534
ANSI-fication and Py_PROTO extermination.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
9 #endif |
|
7e58c060d534
ANSI-fication and Py_PROTO extermination.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
10 |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
11 /* State shared between threads */ |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
12 |
|
5919
5da18e002b1a
Mass checkin (more to follow for other directories).
Guido van Rossum <guido@python.org>
parents:
5564
diff
changeset
|
13 struct _ts; /* Forward */ |
|
5da18e002b1a
Mass checkin (more to follow for other directories).
Guido van Rossum <guido@python.org>
parents:
5564
diff
changeset
|
14 struct _is; /* Forward */ |
|
5da18e002b1a
Mass checkin (more to follow for other directories).
Guido van Rossum <guido@python.org>
parents:
5564
diff
changeset
|
15 |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
16 typedef struct _is { |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
17 |
|
13443
7e58c060d534
ANSI-fication and Py_PROTO extermination.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
18 struct _is *next; |
|
7e58c060d534
ANSI-fication and Py_PROTO extermination.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
19 struct _ts *tstate_head; |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
20 |
|
13443
7e58c060d534
ANSI-fication and Py_PROTO extermination.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
21 PyObject *modules; |
|
7e58c060d534
ANSI-fication and Py_PROTO extermination.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
22 PyObject *sysdict; |
|
7e58c060d534
ANSI-fication and Py_PROTO extermination.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
23 PyObject *builtins; |
|
41128
45ce388ec59a
Bug #742342: make Python stop segfaulting on infinitely-recursive reload()s. Fixed by patch #922167.
Collin Winter <collinw@gmail.com>
parents:
39056
diff
changeset
|
24 PyObject *modules_reloading; |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
25 |
|
28325
850626d47574
Fixed SF bug #663074. The codec system was using global static
Gustavo Niemeyer <gustavo@niemeyer.net>
parents:
27978
diff
changeset
|
26 PyObject *codec_search_path; |
|
850626d47574
Fixed SF bug #663074. The codec system was using global static
Gustavo Niemeyer <gustavo@niemeyer.net>
parents:
27978
diff
changeset
|
27 PyObject *codec_search_cache; |
|
850626d47574
Fixed SF bug #663074. The codec system was using global static
Gustavo Niemeyer <gustavo@niemeyer.net>
parents:
27978
diff
changeset
|
28 PyObject *codec_error_registry; |
|
850626d47574
Fixed SF bug #663074. The codec system was using global static
Gustavo Niemeyer <gustavo@niemeyer.net>
parents:
27978
diff
changeset
|
29 |
|
18689
064de84385ca
Patch #412229: Add functions sys.getdlopenflags and sys.setdlopenflags.
Martin v. Löwis <martin@v.loewis.de>
parents:
18374
diff
changeset
|
30 #ifdef HAVE_DLOPEN |
|
064de84385ca
Patch #412229: Add functions sys.getdlopenflags and sys.setdlopenflags.
Martin v. Löwis <martin@v.loewis.de>
parents:
18374
diff
changeset
|
31 int dlopenflags; |
|
064de84385ca
Patch #412229: Add functions sys.getdlopenflags and sys.setdlopenflags.
Martin v. Löwis <martin@v.loewis.de>
parents:
18374
diff
changeset
|
32 #endif |
|
32301
41c59d80bbc5
Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents:
31836
diff
changeset
|
33 #ifdef WITH_TSC |
|
41c59d80bbc5
Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents:
31836
diff
changeset
|
34 int tscdump; |
|
41c59d80bbc5
Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents:
31836
diff
changeset
|
35 #endif |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
36 |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
37 } PyInterpreterState; |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
38 |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
39 |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
40 /* State unique per thread */ |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
41 |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
42 struct _frame; /* Avoid including frameobject.h */ |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
43 |
|
18325
fb35b3a22604
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
16139
diff
changeset
|
44 /* Py_tracefunc return -1 when raising an exception, or 0 for success. */ |
|
fb35b3a22604
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
16139
diff
changeset
|
45 typedef int (*Py_tracefunc)(PyObject *, struct _frame *, int, PyObject *); |
|
fb35b3a22604
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
16139
diff
changeset
|
46 |
|
fb35b3a22604
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
16139
diff
changeset
|
47 /* The following values are used for 'what' for tracefunc functions: */ |
|
fb35b3a22604
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
16139
diff
changeset
|
48 #define PyTrace_CALL 0 |
|
fb35b3a22604
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
16139
diff
changeset
|
49 #define PyTrace_EXCEPTION 1 |
|
fb35b3a22604
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
16139
diff
changeset
|
50 #define PyTrace_LINE 2 |
|
fb35b3a22604
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
16139
diff
changeset
|
51 #define PyTrace_RETURN 3 |
|
31796
1c117dbb2def
Enable the profiling of C functions (builtins and extensions)
Nicholas Bastin <nick.bastin@gmail.com>
parents:
31654
diff
changeset
|
52 #define PyTrace_C_CALL 4 |
|
1c117dbb2def
Enable the profiling of C functions (builtins and extensions)
Nicholas Bastin <nick.bastin@gmail.com>
parents:
31654
diff
changeset
|
53 #define PyTrace_C_EXCEPTION 5 |
|
1c117dbb2def
Enable the profiling of C functions (builtins and extensions)
Nicholas Bastin <nick.bastin@gmail.com>
parents:
31654
diff
changeset
|
54 #define PyTrace_C_RETURN 6 |
|
18325
fb35b3a22604
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
16139
diff
changeset
|
55 |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
56 typedef struct _ts { |
|
35125
cdec978b916c
Add comments about PyThreadState and the usage of its fields.
Brett Cannon <bcannon@gmail.com>
parents:
32301
diff
changeset
|
57 /* See Python/ceval.c for comments explaining most fields */ |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
58 |
|
13443
7e58c060d534
ANSI-fication and Py_PROTO extermination.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
59 struct _ts *next; |
|
7e58c060d534
ANSI-fication and Py_PROTO extermination.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
60 PyInterpreterState *interp; |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
61 |
|
13443
7e58c060d534
ANSI-fication and Py_PROTO extermination.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
62 struct _frame *frame; |
|
7e58c060d534
ANSI-fication and Py_PROTO extermination.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
63 int recursion_depth; |
|
35125
cdec978b916c
Add comments about PyThreadState and the usage of its fields.
Brett Cannon <bcannon@gmail.com>
parents:
32301
diff
changeset
|
64 /* 'tracing' keeps track of the execution depth when tracing/profiling. |
|
cdec978b916c
Add comments about PyThreadState and the usage of its fields.
Brett Cannon <bcannon@gmail.com>
parents:
32301
diff
changeset
|
65 This is to prevent the actual trace/profile code from being recorded in |
|
cdec978b916c
Add comments about PyThreadState and the usage of its fields.
Brett Cannon <bcannon@gmail.com>
parents:
32301
diff
changeset
|
66 the trace/profile. */ |
|
13443
7e58c060d534
ANSI-fication and Py_PROTO extermination.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
67 int tracing; |
|
18374
3b295ce2705f
This change adjusts the profiling/tracing support so that the common
Fred Drake <fdrake@acm.org>
parents:
18325
diff
changeset
|
68 int use_tracing; |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
69 |
|
18325
fb35b3a22604
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
16139
diff
changeset
|
70 Py_tracefunc c_profilefunc; |
|
fb35b3a22604
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
16139
diff
changeset
|
71 Py_tracefunc c_tracefunc; |
|
fb35b3a22604
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
16139
diff
changeset
|
72 PyObject *c_profileobj; |
|
fb35b3a22604
Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents:
16139
diff
changeset
|
73 PyObject *c_traceobj; |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
74 |
|
13443
7e58c060d534
ANSI-fication and Py_PROTO extermination.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
75 PyObject *curexc_type; |
|
7e58c060d534
ANSI-fication and Py_PROTO extermination.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
76 PyObject *curexc_value; |
|
7e58c060d534
ANSI-fication and Py_PROTO extermination.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
77 PyObject *curexc_traceback; |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
78 |
|
13443
7e58c060d534
ANSI-fication and Py_PROTO extermination.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
79 PyObject *exc_type; |
|
7e58c060d534
ANSI-fication and Py_PROTO extermination.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
80 PyObject *exc_value; |
|
7e58c060d534
ANSI-fication and Py_PROTO extermination.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
81 PyObject *exc_traceback; |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
82 |
|
35125
cdec978b916c
Add comments about PyThreadState and the usage of its fields.
Brett Cannon <bcannon@gmail.com>
parents:
32301
diff
changeset
|
83 PyObject *dict; /* Stores per-thread state */ |
|
8043
b8e8ace79cf0
Move 'dict' struct member to end of struct. This ensures binary
Guido van Rossum <guido@python.org>
parents:
7971
diff
changeset
|
84 |
|
31836
e42cbaff8027
Added a comment about the unreferenced PyThreadState.tick_counter
Tim Peters <tim.peters@gmail.com>
parents:
31796
diff
changeset
|
85 /* tick_counter is incremented whenever the check_interval ticker |
|
e42cbaff8027
Added a comment about the unreferenced PyThreadState.tick_counter
Tim Peters <tim.peters@gmail.com>
parents:
31796
diff
changeset
|
86 * reaches zero. The purpose is to give a useful measure of the number |
|
e42cbaff8027
Added a comment about the unreferenced PyThreadState.tick_counter
Tim Peters <tim.peters@gmail.com>
parents:
31796
diff
changeset
|
87 * of interpreted bytecode instructions in a given thread. This |
|
e42cbaff8027
Added a comment about the unreferenced PyThreadState.tick_counter
Tim Peters <tim.peters@gmail.com>
parents:
31796
diff
changeset
|
88 * extremely lightweight statistic collector may be of interest to |
|
e42cbaff8027
Added a comment about the unreferenced PyThreadState.tick_counter
Tim Peters <tim.peters@gmail.com>
parents:
31796
diff
changeset
|
89 * profilers (like psyco.jit()), although nothing in the core uses it. |
|
e42cbaff8027
Added a comment about the unreferenced PyThreadState.tick_counter
Tim Peters <tim.peters@gmail.com>
parents:
31796
diff
changeset
|
90 */ |
|
26109
e61b946474df
Assorted patches from Armin Rigo:
Michael W. Hudson <mwh@python.net>
parents:
25108
diff
changeset
|
91 int tick_counter; |
|
31836
e42cbaff8027
Added a comment about the unreferenced PyThreadState.tick_counter
Tim Peters <tim.peters@gmail.com>
parents:
31796
diff
changeset
|
92 |
|
28694
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
28325
diff
changeset
|
93 int gilstate_counter; |
|
26109
e61b946474df
Assorted patches from Armin Rigo:
Michael W. Hudson <mwh@python.net>
parents:
25108
diff
changeset
|
94 |
|
29643
fa97293533a9
Add PyThreadState_SetAsyncExc(long, PyObject *).
Guido van Rossum <guido@python.org>
parents:
28694
diff
changeset
|
95 PyObject *async_exc; /* Asynchronous exception to raise */ |
|
fa97293533a9
Add PyThreadState_SetAsyncExc(long, PyObject *).
Guido van Rossum <guido@python.org>
parents:
28694
diff
changeset
|
96 long thread_id; /* Thread id where this tstate was created */ |
|
fa97293533a9
Add PyThreadState_SetAsyncExc(long, PyObject *).
Guido van Rossum <guido@python.org>
parents:
28694
diff
changeset
|
97 |
|
78855
5a2ef447b80d
Issue #13992: The trashcan mechanism is now thread-safe. This eliminates
Antoine Pitrou <solipsis@pitrou.net>
parents:
72898
diff
changeset
|
98 int trash_delete_nesting; |
|
5a2ef447b80d
Issue #13992: The trashcan mechanism is now thread-safe. This eliminates
Antoine Pitrou <solipsis@pitrou.net>
parents:
72898
diff
changeset
|
99 PyObject *trash_delete_later; |
|
5a2ef447b80d
Issue #13992: The trashcan mechanism is now thread-safe. This eliminates
Antoine Pitrou <solipsis@pitrou.net>
parents:
72898
diff
changeset
|
100 |
|
13443
7e58c060d534
ANSI-fication and Py_PROTO extermination.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
101 /* XXX signal handlers should also be here */ |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
102 |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
103 } PyThreadState; |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
104 |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
105 |
|
24752
c1eb668525e1
Excise DL_EXPORT from Include.
Mark Hammond <mhammond@skippinet.com.au>
parents:
18733
diff
changeset
|
106 PyAPI_FUNC(PyInterpreterState *) PyInterpreterState_New(void); |
|
c1eb668525e1
Excise DL_EXPORT from Include.
Mark Hammond <mhammond@skippinet.com.au>
parents:
18733
diff
changeset
|
107 PyAPI_FUNC(void) PyInterpreterState_Clear(PyInterpreterState *); |
|
c1eb668525e1
Excise DL_EXPORT from Include.
Mark Hammond <mhammond@skippinet.com.au>
parents:
18733
diff
changeset
|
108 PyAPI_FUNC(void) PyInterpreterState_Delete(PyInterpreterState *); |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
109 |
|
24752
c1eb668525e1
Excise DL_EXPORT from Include.
Mark Hammond <mhammond@skippinet.com.au>
parents:
18733
diff
changeset
|
110 PyAPI_FUNC(PyThreadState *) PyThreadState_New(PyInterpreterState *); |
|
59315
7f500641c06a
Issue #7544: Preallocate thread memory before creating the thread to avoid a
Victor Stinner <victor.stinner@haypocalc.com>
parents:
41128
diff
changeset
|
111 PyAPI_FUNC(PyThreadState *) _PyThreadState_Prealloc(PyInterpreterState *); |
|
7f500641c06a
Issue #7544: Preallocate thread memory before creating the thread to avoid a
Victor Stinner <victor.stinner@haypocalc.com>
parents:
41128
diff
changeset
|
112 PyAPI_FUNC(void) _PyThreadState_Init(PyThreadState *); |
|
24752
c1eb668525e1
Excise DL_EXPORT from Include.
Mark Hammond <mhammond@skippinet.com.au>
parents:
18733
diff
changeset
|
113 PyAPI_FUNC(void) PyThreadState_Clear(PyThreadState *); |
|
c1eb668525e1
Excise DL_EXPORT from Include.
Mark Hammond <mhammond@skippinet.com.au>
parents:
18733
diff
changeset
|
114 PyAPI_FUNC(void) PyThreadState_Delete(PyThreadState *); |
|
16139
d96ce9708c00
Add a new API, PyThreadState_DeleteCurrent() that combines
Guido van Rossum <guido@python.org>
parents:
14375
diff
changeset
|
115 #ifdef WITH_THREAD |
|
24752
c1eb668525e1
Excise DL_EXPORT from Include.
Mark Hammond <mhammond@skippinet.com.au>
parents:
18733
diff
changeset
|
116 PyAPI_FUNC(void) PyThreadState_DeleteCurrent(void); |
|
16139
d96ce9708c00
Add a new API, PyThreadState_DeleteCurrent() that combines
Guido van Rossum <guido@python.org>
parents:
14375
diff
changeset
|
117 #endif |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
118 |
|
24752
c1eb668525e1
Excise DL_EXPORT from Include.
Mark Hammond <mhammond@skippinet.com.au>
parents:
18733
diff
changeset
|
119 PyAPI_FUNC(PyThreadState *) PyThreadState_Get(void); |
|
c1eb668525e1
Excise DL_EXPORT from Include.
Mark Hammond <mhammond@skippinet.com.au>
parents:
18733
diff
changeset
|
120 PyAPI_FUNC(PyThreadState *) PyThreadState_Swap(PyThreadState *); |
|
c1eb668525e1
Excise DL_EXPORT from Include.
Mark Hammond <mhammond@skippinet.com.au>
parents:
18733
diff
changeset
|
121 PyAPI_FUNC(PyObject *) PyThreadState_GetDict(void); |
|
29643
fa97293533a9
Add PyThreadState_SetAsyncExc(long, PyObject *).
Guido van Rossum <guido@python.org>
parents:
28694
diff
changeset
|
122 PyAPI_FUNC(int) PyThreadState_SetAsyncExc(long, PyObject *); |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
123 |
|
9668
40858ab23568
Add macro version of PyThreadState_GET(). This uses
Guido van Rossum <guido@python.org>
parents:
9586
diff
changeset
|
124 |
|
40858ab23568
Add macro version of PyThreadState_GET(). This uses
Guido van Rossum <guido@python.org>
parents:
9586
diff
changeset
|
125 /* Variable and macro for in-line access to current thread state */ |
|
40858ab23568
Add macro version of PyThreadState_GET(). This uses
Guido van Rossum <guido@python.org>
parents:
9586
diff
changeset
|
126 |
|
24752
c1eb668525e1
Excise DL_EXPORT from Include.
Mark Hammond <mhammond@skippinet.com.au>
parents:
18733
diff
changeset
|
127 PyAPI_DATA(PyThreadState *) _PyThreadState_Current; |
|
9668
40858ab23568
Add macro version of PyThreadState_GET(). This uses
Guido van Rossum <guido@python.org>
parents:
9586
diff
changeset
|
128 |
|
40858ab23568
Add macro version of PyThreadState_GET(). This uses
Guido van Rossum <guido@python.org>
parents:
9586
diff
changeset
|
129 #ifdef Py_DEBUG |
|
40858ab23568
Add macro version of PyThreadState_GET(). This uses
Guido van Rossum <guido@python.org>
parents:
9586
diff
changeset
|
130 #define PyThreadState_GET() PyThreadState_Get() |
|
40858ab23568
Add macro version of PyThreadState_GET(). This uses
Guido van Rossum <guido@python.org>
parents:
9586
diff
changeset
|
131 #else |
|
40858ab23568
Add macro version of PyThreadState_GET(). This uses
Guido van Rossum <guido@python.org>
parents:
9586
diff
changeset
|
132 #define PyThreadState_GET() (_PyThreadState_Current) |
|
40858ab23568
Add macro version of PyThreadState_GET(). This uses
Guido van Rossum <guido@python.org>
parents:
9586
diff
changeset
|
133 #endif |
|
40858ab23568
Add macro version of PyThreadState_GET(). This uses
Guido van Rossum <guido@python.org>
parents:
9586
diff
changeset
|
134 |
|
31836
e42cbaff8027
Added a comment about the unreferenced PyThreadState.tick_counter
Tim Peters <tim.peters@gmail.com>
parents:
31796
diff
changeset
|
135 typedef |
|
28694
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
28325
diff
changeset
|
136 enum {PyGILState_LOCKED, PyGILState_UNLOCKED} |
|
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
28325
diff
changeset
|
137 PyGILState_STATE; |
|
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
28325
diff
changeset
|
138 |
|
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
28325
diff
changeset
|
139 /* Ensure that the current thread is ready to call the Python |
|
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
28325
diff
changeset
|
140 C API, regardless of the current state of Python, or of its |
|
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
28325
diff
changeset
|
141 thread lock. This may be called as many times as desired |
|
31836
e42cbaff8027
Added a comment about the unreferenced PyThreadState.tick_counter
Tim Peters <tim.peters@gmail.com>
parents:
31796
diff
changeset
|
142 by a thread so long as each call is matched with a call to |
|
e42cbaff8027
Added a comment about the unreferenced PyThreadState.tick_counter
Tim Peters <tim.peters@gmail.com>
parents:
31796
diff
changeset
|
143 PyGILState_Release(). In general, other thread-state APIs may |
|
e42cbaff8027
Added a comment about the unreferenced PyThreadState.tick_counter
Tim Peters <tim.peters@gmail.com>
parents:
31796
diff
changeset
|
144 be used between _Ensure() and _Release() calls, so long as the |
|
28694
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
28325
diff
changeset
|
145 thread-state is restored to its previous state before the Release(). |
|
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
28325
diff
changeset
|
146 For example, normal use of the Py_BEGIN_ALLOW_THREADS/ |
|
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
28325
diff
changeset
|
147 Py_END_ALLOW_THREADS macros are acceptable. |
|
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
28325
diff
changeset
|
148 |
|
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
28325
diff
changeset
|
149 The return value is an opaque "handle" to the thread state when |
|
31654
7fffdb94a172
SF patch #906501: Fix typos in pystate.h comments
Raymond Hettinger <python@rcn.com>
parents:
29643
diff
changeset
|
150 PyGILState_Ensure() was called, and must be passed to |
|
28694
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
28325
diff
changeset
|
151 PyGILState_Release() to ensure Python is left in the same state. Even |
|
31836
e42cbaff8027
Added a comment about the unreferenced PyThreadState.tick_counter
Tim Peters <tim.peters@gmail.com>
parents:
31796
diff
changeset
|
152 though recursive calls are allowed, these handles can *not* be shared - |
|
e42cbaff8027
Added a comment about the unreferenced PyThreadState.tick_counter
Tim Peters <tim.peters@gmail.com>
parents:
31796
diff
changeset
|
153 each unique call to PyGILState_Ensure must save the handle for its |
|
28694
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
28325
diff
changeset
|
154 call to PyGILState_Release. |
|
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
28325
diff
changeset
|
155 |
|
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
28325
diff
changeset
|
156 When the function returns, the current thread will hold the GIL. |
|
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
28325
diff
changeset
|
157 |
|
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
28325
diff
changeset
|
158 Failure is a fatal error. |
|
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
28325
diff
changeset
|
159 */ |
|
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
28325
diff
changeset
|
160 PyAPI_FUNC(PyGILState_STATE) PyGILState_Ensure(void); |
|
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
28325
diff
changeset
|
161 |
|
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
28325
diff
changeset
|
162 /* Release any resources previously acquired. After this call, Python's |
|
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
28325
diff
changeset
|
163 state will be the same as it was prior to the corresponding |
|
31836
e42cbaff8027
Added a comment about the unreferenced PyThreadState.tick_counter
Tim Peters <tim.peters@gmail.com>
parents:
31796
diff
changeset
|
164 PyGILState_Ensure() call (but generally this state will be unknown to |
|
28694
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
28325
diff
changeset
|
165 the caller, hence the use of the GILState API.) |
|
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
28325
diff
changeset
|
166 |
|
31836
e42cbaff8027
Added a comment about the unreferenced PyThreadState.tick_counter
Tim Peters <tim.peters@gmail.com>
parents:
31796
diff
changeset
|
167 Every call to PyGILState_Ensure must be matched by a call to |
|
28694
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
28325
diff
changeset
|
168 PyGILState_Release on the same thread. |
|
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
28325
diff
changeset
|
169 */ |
|
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
28325
diff
changeset
|
170 PyAPI_FUNC(void) PyGILState_Release(PyGILState_STATE); |
|
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
28325
diff
changeset
|
171 |
|
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
28325
diff
changeset
|
172 /* Helper/diagnostic function - get the current thread state for |
|
31836
e42cbaff8027
Added a comment about the unreferenced PyThreadState.tick_counter
Tim Peters <tim.peters@gmail.com>
parents:
31796
diff
changeset
|
173 this thread. May return NULL if no GILState API has been used |
|
71768
8852e4a9aa1e
#10741: add documentation for PyGILState_GetThisThreadState()
Sandro Tosi <sandro.tosi@gmail.com>
parents:
69635
diff
changeset
|
174 on the current thread. Note that the main thread always has such a |
|
31836
e42cbaff8027
Added a comment about the unreferenced PyThreadState.tick_counter
Tim Peters <tim.peters@gmail.com>
parents:
31796
diff
changeset
|
175 thread-state, even if no auto-thread-state call has been made |
|
28694
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
28325
diff
changeset
|
176 on the main thread. |
|
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
28325
diff
changeset
|
177 */ |
|
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
28325
diff
changeset
|
178 PyAPI_FUNC(PyThreadState *) PyGILState_GetThisThreadState(void); |
|
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
28325
diff
changeset
|
179 |
|
39056
b6fd499e4343
After approval from Anthony, merge the tim-current_frames
Tim Peters <tim.peters@gmail.com>
parents:
35125
diff
changeset
|
180 /* The implementation of sys._current_frames() Returns a dict mapping |
|
b6fd499e4343
After approval from Anthony, merge the tim-current_frames
Tim Peters <tim.peters@gmail.com>
parents:
35125
diff
changeset
|
181 thread id to that thread's current frame. |
|
b6fd499e4343
After approval from Anthony, merge the tim-current_frames
Tim Peters <tim.peters@gmail.com>
parents:
35125
diff
changeset
|
182 */ |
|
b6fd499e4343
After approval from Anthony, merge the tim-current_frames
Tim Peters <tim.peters@gmail.com>
parents:
35125
diff
changeset
|
183 PyAPI_FUNC(PyObject *) _PyThread_CurrentFrames(void); |
|
b6fd499e4343
After approval from Anthony, merge the tim-current_frames
Tim Peters <tim.peters@gmail.com>
parents:
35125
diff
changeset
|
184 |
|
18733
b0329649b8cf
Add a low-level API to access interpreters, for David Beazley.
Guido van Rossum <guido@python.org>
parents:
18689
diff
changeset
|
185 /* Routines for advanced debuggers, requested by David Beazley. |
|
b0329649b8cf
Add a low-level API to access interpreters, for David Beazley.
Guido van Rossum <guido@python.org>
parents:
18689
diff
changeset
|
186 Don't use unless you know what you are doing! */ |
|
24752
c1eb668525e1
Excise DL_EXPORT from Include.
Mark Hammond <mhammond@skippinet.com.au>
parents:
18733
diff
changeset
|
187 PyAPI_FUNC(PyInterpreterState *) PyInterpreterState_Head(void); |
|
c1eb668525e1
Excise DL_EXPORT from Include.
Mark Hammond <mhammond@skippinet.com.au>
parents:
18733
diff
changeset
|
188 PyAPI_FUNC(PyInterpreterState *) PyInterpreterState_Next(PyInterpreterState *); |
|
c1eb668525e1
Excise DL_EXPORT from Include.
Mark Hammond <mhammond@skippinet.com.au>
parents:
18733
diff
changeset
|
189 PyAPI_FUNC(PyThreadState *) PyInterpreterState_ThreadHead(PyInterpreterState *); |
|
c1eb668525e1
Excise DL_EXPORT from Include.
Mark Hammond <mhammond@skippinet.com.au>
parents:
18733
diff
changeset
|
190 PyAPI_FUNC(PyThreadState *) PyThreadState_Next(PyThreadState *); |
|
18733
b0329649b8cf
Add a low-level API to access interpreters, for David Beazley.
Guido van Rossum <guido@python.org>
parents:
18689
diff
changeset
|
191 |
|
27978
4b99a701defe
- PyEval_GetFrame() is now declared to return a PyFrameObject *
Guido van Rossum <guido@python.org>
parents:
26109
diff
changeset
|
192 typedef struct _frame *(*PyThreadFrameGetter)(PyThreadState *self_); |
|
4b99a701defe
- PyEval_GetFrame() is now declared to return a PyFrameObject *
Guido van Rossum <guido@python.org>
parents:
26109
diff
changeset
|
193 |
|
26109
e61b946474df
Assorted patches from Armin Rigo:
Michael W. Hudson <mwh@python.net>
parents:
25108
diff
changeset
|
194 /* hook for PyEval_GetFrame(), requested for Psyco */ |
|
27978
4b99a701defe
- PyEval_GetFrame() is now declared to return a PyFrameObject *
Guido van Rossum <guido@python.org>
parents:
26109
diff
changeset
|
195 PyAPI_DATA(PyThreadFrameGetter) _PyThreadState_GetFrame; |
|
26109
e61b946474df
Assorted patches from Armin Rigo:
Michael W. Hudson <mwh@python.net>
parents:
25108
diff
changeset
|
196 |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
197 #ifdef __cplusplus |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
198 } |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
199 #endif |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
200 #endif /* !Py_PYSTATE_H */ |
