Mercurial > cpython-lru_cache-weakref
annotate Python/pystate.c @ 13658:f79434ee41fa legacy-trunk
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
declarations yet, those come later.
| author | Thomas Wouters <thomas@python.org> |
|---|---|
| date | Sat, 22 Jul 2000 18:47:25 +0000 |
| parents | 87ee82e5c56d |
| children | dfdb601cee1c |
| rev | line source |
|---|---|
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1 /*********************************************************** |
|
13255
916fb024ce94
Change copyright notice.
Guido van Rossum <guido@python.org>
parents:
11011
diff
changeset
|
2 Copyright (c) 2000, BeOpen.com. |
|
916fb024ce94
Change copyright notice.
Guido van Rossum <guido@python.org>
parents:
11011
diff
changeset
|
3 Copyright (c) 1995-2000, Corporation for National Research Initiatives. |
|
916fb024ce94
Change copyright notice.
Guido van Rossum <guido@python.org>
parents:
11011
diff
changeset
|
4 Copyright (c) 1990-1995, Stichting Mathematisch Centrum. |
|
916fb024ce94
Change copyright notice.
Guido van Rossum <guido@python.org>
parents:
11011
diff
changeset
|
5 All rights reserved. |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
6 |
|
13255
916fb024ce94
Change copyright notice.
Guido van Rossum <guido@python.org>
parents:
11011
diff
changeset
|
7 See the file "Misc/COPYRIGHT" for information on usage and |
|
916fb024ce94
Change copyright notice.
Guido van Rossum <guido@python.org>
parents:
11011
diff
changeset
|
8 redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES. |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
9 ******************************************************************/ |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
10 |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
11 /* 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
|
12 |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
13 #include "Python.h" |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
14 |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5849
diff
changeset
|
15 #define ZAP(x) { \ |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5849
diff
changeset
|
16 PyObject *tmp = (PyObject *)(x); \ |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5849
diff
changeset
|
17 (x) = NULL; \ |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5849
diff
changeset
|
18 Py_XDECREF(tmp); \ |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5849
diff
changeset
|
19 } |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5849
diff
changeset
|
20 |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5849
diff
changeset
|
21 |
| 11011 | 22 #ifdef WITH_THREAD |
| 23 #include "pythread.h" | |
| 24 static PyThread_type_lock head_mutex = NULL; /* Protects interp->tstate_head */ | |
| 25 #define HEAD_INIT() (head_mutex || (head_mutex = PyThread_allocate_lock())) | |
| 26 #define HEAD_LOCK() PyThread_acquire_lock(head_mutex, WAIT_LOCK) | |
| 27 #define HEAD_UNLOCK() PyThread_release_lock(head_mutex) | |
| 28 #else | |
| 29 #define HEAD_INIT() /* Nothing */ | |
| 30 #define HEAD_LOCK() /* Nothing */ | |
| 31 #define HEAD_UNLOCK() /* Nothing */ | |
| 32 #endif | |
| 33 | |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5849
diff
changeset
|
34 static PyInterpreterState *interp_head = NULL; |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
35 |
|
9667
914f83e7fa0a
Make current_tstate a global, _PyThreadState_Current. This is to
Guido van Rossum <guido@python.org>
parents:
7970
diff
changeset
|
36 PyThreadState *_PyThreadState_Current = NULL; |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
37 |
|
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 PyInterpreterState * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13256
diff
changeset
|
40 PyInterpreterState_New(void) |
|
5405
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 PyInterpreterState *interp = PyMem_NEW(PyInterpreterState, 1); |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5849
diff
changeset
|
43 |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
44 if (interp != NULL) { |
| 11011 | 45 HEAD_INIT(); |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5849
diff
changeset
|
46 interp->modules = NULL; |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
47 interp->sysdict = NULL; |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5849
diff
changeset
|
48 interp->builtins = NULL; |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5849
diff
changeset
|
49 interp->checkinterval = 10; |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5849
diff
changeset
|
50 interp->tstate_head = NULL; |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5849
diff
changeset
|
51 |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5849
diff
changeset
|
52 interp->next = interp_head; |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5849
diff
changeset
|
53 interp_head = interp; |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
54 } |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5849
diff
changeset
|
55 |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
56 return interp; |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
57 } |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
58 |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
59 |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
60 void |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13256
diff
changeset
|
61 PyInterpreterState_Clear(PyInterpreterState *interp) |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5849
diff
changeset
|
62 { |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5849
diff
changeset
|
63 PyThreadState *p; |
| 11011 | 64 HEAD_LOCK(); |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5849
diff
changeset
|
65 for (p = interp->tstate_head; p != NULL; p = p->next) |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5849
diff
changeset
|
66 PyThreadState_Clear(p); |
| 11011 | 67 HEAD_UNLOCK(); |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5849
diff
changeset
|
68 ZAP(interp->modules); |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5849
diff
changeset
|
69 ZAP(interp->sysdict); |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5849
diff
changeset
|
70 ZAP(interp->builtins); |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5849
diff
changeset
|
71 } |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5849
diff
changeset
|
72 |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5849
diff
changeset
|
73 |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5849
diff
changeset
|
74 static void |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13256
diff
changeset
|
75 zapthreads(PyInterpreterState *interp) |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5849
diff
changeset
|
76 { |
| 11011 | 77 PyThreadState *p; |
| 78 /* No need to lock the mutex here because this should only happen | |
| 79 when the threads are all really dead (XXX famous last words). */ | |
| 80 while ((p = interp->tstate_head) != NULL) { | |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5849
diff
changeset
|
81 PyThreadState_Delete(p); |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5849
diff
changeset
|
82 } |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5849
diff
changeset
|
83 } |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5849
diff
changeset
|
84 |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5849
diff
changeset
|
85 |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5849
diff
changeset
|
86 void |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13256
diff
changeset
|
87 PyInterpreterState_Delete(PyInterpreterState *interp) |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
88 { |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5849
diff
changeset
|
89 PyInterpreterState **p; |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5849
diff
changeset
|
90 zapthreads(interp); |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5849
diff
changeset
|
91 for (p = &interp_head; ; p = &(*p)->next) { |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5849
diff
changeset
|
92 if (*p == NULL) |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5849
diff
changeset
|
93 Py_FatalError( |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5849
diff
changeset
|
94 "PyInterpreterState_Delete: invalid interp"); |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5849
diff
changeset
|
95 if (*p == interp) |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5849
diff
changeset
|
96 break; |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5849
diff
changeset
|
97 } |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5849
diff
changeset
|
98 if (interp->tstate_head != NULL) |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5849
diff
changeset
|
99 Py_FatalError("PyInterpreterState_Delete: remaining threads"); |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5849
diff
changeset
|
100 *p = interp->next; |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
101 PyMem_DEL(interp); |
|
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 |
|
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 PyThreadState * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13256
diff
changeset
|
106 PyThreadState_New(PyInterpreterState *interp) |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
107 { |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
108 PyThreadState *tstate = PyMem_NEW(PyThreadState, 1); |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5849
diff
changeset
|
109 |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
110 if (tstate != NULL) { |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5849
diff
changeset
|
111 tstate->interp = interp; |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
112 |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
113 tstate->frame = NULL; |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
114 tstate->recursion_depth = 0; |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
115 tstate->ticker = 0; |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
116 tstate->tracing = 0; |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
117 |
|
7970
4ceee1ef99b0
/* An extension mechanism to store arbitrary additional per-thread state.
Guido van Rossum <guido@python.org>
parents:
6549
diff
changeset
|
118 tstate->dict = NULL; |
|
4ceee1ef99b0
/* An extension mechanism to store arbitrary additional per-thread state.
Guido van Rossum <guido@python.org>
parents:
6549
diff
changeset
|
119 |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
120 tstate->curexc_type = NULL; |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
121 tstate->curexc_value = NULL; |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
122 tstate->curexc_traceback = NULL; |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
123 |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
124 tstate->exc_type = NULL; |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
125 tstate->exc_value = NULL; |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
126 tstate->exc_traceback = NULL; |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
127 |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
128 tstate->sys_profilefunc = NULL; |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
129 tstate->sys_tracefunc = NULL; |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5849
diff
changeset
|
130 |
| 11011 | 131 HEAD_LOCK(); |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5849
diff
changeset
|
132 tstate->next = interp->tstate_head; |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5849
diff
changeset
|
133 interp->tstate_head = tstate; |
| 11011 | 134 HEAD_UNLOCK(); |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5849
diff
changeset
|
135 } |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5849
diff
changeset
|
136 |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5849
diff
changeset
|
137 return tstate; |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5849
diff
changeset
|
138 } |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5849
diff
changeset
|
139 |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
140 |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5849
diff
changeset
|
141 void |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13256
diff
changeset
|
142 PyThreadState_Clear(PyThreadState *tstate) |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5849
diff
changeset
|
143 { |
|
6549
a8e3b2e9f5d2
The warning about thread still having a frame now only happens in
Guido van Rossum <guido@python.org>
parents:
6124
diff
changeset
|
144 if (Py_VerboseFlag && tstate->frame != NULL) |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5849
diff
changeset
|
145 fprintf(stderr, |
|
6124
cc2c84769636
Added missing newline to warning msg
Guido van Rossum <guido@python.org>
parents:
5926
diff
changeset
|
146 "PyThreadState_Clear: warning: thread still has a frame\n"); |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5849
diff
changeset
|
147 |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5849
diff
changeset
|
148 ZAP(tstate->frame); |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5849
diff
changeset
|
149 |
|
7970
4ceee1ef99b0
/* An extension mechanism to store arbitrary additional per-thread state.
Guido van Rossum <guido@python.org>
parents:
6549
diff
changeset
|
150 ZAP(tstate->dict); |
|
4ceee1ef99b0
/* An extension mechanism to store arbitrary additional per-thread state.
Guido van Rossum <guido@python.org>
parents:
6549
diff
changeset
|
151 |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5849
diff
changeset
|
152 ZAP(tstate->curexc_type); |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5849
diff
changeset
|
153 ZAP(tstate->curexc_value); |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5849
diff
changeset
|
154 ZAP(tstate->curexc_traceback); |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5849
diff
changeset
|
155 |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5849
diff
changeset
|
156 ZAP(tstate->exc_type); |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5849
diff
changeset
|
157 ZAP(tstate->exc_value); |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5849
diff
changeset
|
158 ZAP(tstate->exc_traceback); |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5849
diff
changeset
|
159 |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5849
diff
changeset
|
160 ZAP(tstate->sys_profilefunc); |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5849
diff
changeset
|
161 ZAP(tstate->sys_tracefunc); |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
162 } |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
163 |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
164 |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
165 void |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13256
diff
changeset
|
166 PyThreadState_Delete(PyThreadState *tstate) |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
167 { |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5849
diff
changeset
|
168 PyInterpreterState *interp; |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5849
diff
changeset
|
169 PyThreadState **p; |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5849
diff
changeset
|
170 if (tstate == NULL) |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5849
diff
changeset
|
171 Py_FatalError("PyThreadState_Delete: NULL tstate"); |
|
9667
914f83e7fa0a
Make current_tstate a global, _PyThreadState_Current. This is to
Guido van Rossum <guido@python.org>
parents:
7970
diff
changeset
|
172 if (tstate == _PyThreadState_Current) |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5849
diff
changeset
|
173 Py_FatalError("PyThreadState_Delete: tstate is still current"); |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5849
diff
changeset
|
174 interp = tstate->interp; |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5849
diff
changeset
|
175 if (interp == NULL) |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5849
diff
changeset
|
176 Py_FatalError("PyThreadState_Delete: NULL interp"); |
| 11011 | 177 HEAD_LOCK(); |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5849
diff
changeset
|
178 for (p = &interp->tstate_head; ; p = &(*p)->next) { |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5849
diff
changeset
|
179 if (*p == NULL) |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5849
diff
changeset
|
180 Py_FatalError( |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5849
diff
changeset
|
181 "PyThreadState_Delete: invalid tstate"); |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5849
diff
changeset
|
182 if (*p == tstate) |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5849
diff
changeset
|
183 break; |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5849
diff
changeset
|
184 } |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5849
diff
changeset
|
185 *p = tstate->next; |
| 11011 | 186 HEAD_UNLOCK(); |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
187 PyMem_DEL(tstate); |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
188 } |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
189 |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
190 |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
191 PyThreadState * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13256
diff
changeset
|
192 PyThreadState_Get(void) |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
193 { |
|
9667
914f83e7fa0a
Make current_tstate a global, _PyThreadState_Current. This is to
Guido van Rossum <guido@python.org>
parents:
7970
diff
changeset
|
194 if (_PyThreadState_Current == NULL) |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5849
diff
changeset
|
195 Py_FatalError("PyThreadState_Get: no current thread"); |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5849
diff
changeset
|
196 |
|
9667
914f83e7fa0a
Make current_tstate a global, _PyThreadState_Current. This is to
Guido van Rossum <guido@python.org>
parents:
7970
diff
changeset
|
197 return _PyThreadState_Current; |
|
5405
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 |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
200 |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
201 PyThreadState * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13256
diff
changeset
|
202 PyThreadState_Swap(PyThreadState *new) |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
203 { |
|
9667
914f83e7fa0a
Make current_tstate a global, _PyThreadState_Current. This is to
Guido van Rossum <guido@python.org>
parents:
7970
diff
changeset
|
204 PyThreadState *old = _PyThreadState_Current; |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5849
diff
changeset
|
205 |
|
9667
914f83e7fa0a
Make current_tstate a global, _PyThreadState_Current. This is to
Guido van Rossum <guido@python.org>
parents:
7970
diff
changeset
|
206 _PyThreadState_Current = new; |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5849
diff
changeset
|
207 |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
208 return old; |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
209 } |
|
7970
4ceee1ef99b0
/* An extension mechanism to store arbitrary additional per-thread state.
Guido van Rossum <guido@python.org>
parents:
6549
diff
changeset
|
210 |
|
4ceee1ef99b0
/* An extension mechanism to store arbitrary additional per-thread state.
Guido van Rossum <guido@python.org>
parents:
6549
diff
changeset
|
211 /* An extension mechanism to store arbitrary additional per-thread state. |
|
4ceee1ef99b0
/* An extension mechanism to store arbitrary additional per-thread state.
Guido van Rossum <guido@python.org>
parents:
6549
diff
changeset
|
212 PyThreadState_GetDict() returns a dictionary that can be used to hold such |
|
4ceee1ef99b0
/* An extension mechanism to store arbitrary additional per-thread state.
Guido van Rossum <guido@python.org>
parents:
6549
diff
changeset
|
213 state; the caller should pick a unique key and store its state there. If |
|
4ceee1ef99b0
/* An extension mechanism to store arbitrary additional per-thread state.
Guido van Rossum <guido@python.org>
parents:
6549
diff
changeset
|
214 PyThreadState_GetDict() returns NULL, an exception has been raised (most |
|
4ceee1ef99b0
/* An extension mechanism to store arbitrary additional per-thread state.
Guido van Rossum <guido@python.org>
parents:
6549
diff
changeset
|
215 likely MemoryError) and the caller should pass on the exception. */ |
|
4ceee1ef99b0
/* An extension mechanism to store arbitrary additional per-thread state.
Guido van Rossum <guido@python.org>
parents:
6549
diff
changeset
|
216 |
|
4ceee1ef99b0
/* An extension mechanism to store arbitrary additional per-thread state.
Guido van Rossum <guido@python.org>
parents:
6549
diff
changeset
|
217 PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13256
diff
changeset
|
218 PyThreadState_GetDict(void) |
|
7970
4ceee1ef99b0
/* An extension mechanism to store arbitrary additional per-thread state.
Guido van Rossum <guido@python.org>
parents:
6549
diff
changeset
|
219 { |
|
9667
914f83e7fa0a
Make current_tstate a global, _PyThreadState_Current. This is to
Guido van Rossum <guido@python.org>
parents:
7970
diff
changeset
|
220 if (_PyThreadState_Current == NULL) |
|
7970
4ceee1ef99b0
/* An extension mechanism to store arbitrary additional per-thread state.
Guido van Rossum <guido@python.org>
parents:
6549
diff
changeset
|
221 Py_FatalError("PyThreadState_GetDict: no current thread"); |
|
4ceee1ef99b0
/* An extension mechanism to store arbitrary additional per-thread state.
Guido van Rossum <guido@python.org>
parents:
6549
diff
changeset
|
222 |
|
9667
914f83e7fa0a
Make current_tstate a global, _PyThreadState_Current. This is to
Guido van Rossum <guido@python.org>
parents:
7970
diff
changeset
|
223 if (_PyThreadState_Current->dict == NULL) |
|
914f83e7fa0a
Make current_tstate a global, _PyThreadState_Current. This is to
Guido van Rossum <guido@python.org>
parents:
7970
diff
changeset
|
224 _PyThreadState_Current->dict = PyDict_New(); |
|
914f83e7fa0a
Make current_tstate a global, _PyThreadState_Current. This is to
Guido van Rossum <guido@python.org>
parents:
7970
diff
changeset
|
225 return _PyThreadState_Current->dict; |
|
7970
4ceee1ef99b0
/* An extension mechanism to store arbitrary additional per-thread state.
Guido van Rossum <guido@python.org>
parents:
6549
diff
changeset
|
226 } |
