summaryrefslogtreecommitdiffstats
path: root/Modules/_threadmodule.c
diff options
context:
space:
mode:
authorEric Snow <ericsnowcurrently@gmail.com>2017-09-08 05:51:28 (GMT)
committerGitHub <noreply@github.com>2017-09-08 05:51:28 (GMT)
commit2ebc5ce42a8a9e047e790aefbf9a94811569b2b6 (patch)
treef8c483f24e0d1ee43ac5cc9ad82d2ee7cccf69d2 /Modules/_threadmodule.c
parentbab21faded31c70b142776b9a6075a4cda055d7f (diff)
downloadcpython-2ebc5ce42a8a9e047e790aefbf9a94811569b2b6.zip
cpython-2ebc5ce42a8a9e047e790aefbf9a94811569b2b6.tar.gz
cpython-2ebc5ce42a8a9e047e790aefbf9a94811569b2b6.tar.bz2
bpo-30860: Consolidate stateful runtime globals. (#3397)
* group the (stateful) runtime globals into various topical structs * consolidate the topical structs under a single top-level _PyRuntimeState struct * add a check-c-globals.py script that helps identify runtime globals Other globals are excluded (see globals.txt and check-c-globals.py).
Diffstat (limited to 'Modules/_threadmodule.c')
-rw-r--r--Modules/_threadmodule.c12
1 files changed, 7 insertions, 5 deletions
diff --git a/Modules/_threadmodule.c b/Modules/_threadmodule.c
index d58ebc3..2657a1f 100644
--- a/Modules/_threadmodule.c
+++ b/Modules/_threadmodule.c
@@ -3,11 +3,11 @@
/* Interface to Sjoerd's portable C thread library */
#include "Python.h"
+#include "internal/pystate.h"
#include "structmember.h" /* offsetof */
#include "pythread.h"
static PyObject *ThreadError;
-static long nb_threads = 0;
static PyObject *str_dict;
_Py_IDENTIFIER(stderr);
@@ -986,7 +986,7 @@ t_bootstrap(void *boot_raw)
tstate->thread_id = PyThread_get_thread_ident();
_PyThreadState_Init(tstate);
PyEval_AcquireThread(tstate);
- nb_threads++;
+ tstate->interp->num_threads++;
res = PyObject_Call(boot->func, boot->args, boot->keyw);
if (res == NULL) {
if (PyErr_ExceptionMatches(PyExc_SystemExit))
@@ -1013,7 +1013,7 @@ t_bootstrap(void *boot_raw)
Py_DECREF(boot->args);
Py_XDECREF(boot->keyw);
PyMem_DEL(boot_raw);
- nb_threads--;
+ tstate->interp->num_threads--;
PyThreadState_Clear(tstate);
PyThreadState_DeleteCurrent();
PyThread_exit_thread();
@@ -1152,7 +1152,8 @@ A thread's identity may be reused for another thread after it exits.");
static PyObject *
thread__count(PyObject *self)
{
- return PyLong_FromLong(nb_threads);
+ PyThreadState *tstate = PyThreadState_Get();
+ return PyLong_FromLong(tstate->interp->num_threads);
}
PyDoc_STRVAR(_count_doc,
@@ -1345,6 +1346,7 @@ PyInit__thread(void)
PyObject *m, *d, *v;
double time_max;
double timeout_max;
+ PyThreadState *tstate = PyThreadState_Get();
/* Initialize types: */
if (PyType_Ready(&localdummytype) < 0)
@@ -1389,7 +1391,7 @@ PyInit__thread(void)
if (PyModule_AddObject(m, "_local", (PyObject *)&localtype) < 0)
return NULL;
- nb_threads = 0;
+ tstate->interp->num_threads = 0;
str_dict = PyUnicode_InternFromString("__dict__");
if (str_dict == NULL)