diff options
| author | Eric Snow <ericsnowcurrently@gmail.com> | 2017-09-06 01:26:16 (GMT) |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-09-06 01:26:16 (GMT) |
| commit | 76d5abc8684bac4f2fc7cccfe2cd940923357351 (patch) | |
| tree | 4ae6a3bd88bef1266a8d9723c589f925d90bf848 /Modules/_threadmodule.c | |
| parent | 501b324d3a940d26e0021a38aae8d896a30fbcff (diff) | |
| download | cpython-76d5abc8684bac4f2fc7cccfe2cd940923357351.zip cpython-76d5abc8684bac4f2fc7cccfe2cd940923357351.tar.gz cpython-76d5abc8684bac4f2fc7cccfe2cd940923357351.tar.bz2 | |
bpo-30860: Consolidate stateful runtime globals. (#2594)
* 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.c | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/Modules/_threadmodule.c b/Modules/_threadmodule.c index da750c0..89be96c 100644 --- a/Modules/_threadmodule.c +++ b/Modules/_threadmodule.c @@ -14,7 +14,6 @@ #include "pythread.h" static PyObject *ThreadError; -static long nb_threads = 0; static PyObject *str_dict; _Py_IDENTIFIER(stderr); @@ -993,7 +992,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)) @@ -1020,7 +1019,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(); @@ -1159,7 +1158,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, @@ -1352,6 +1352,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) @@ -1396,7 +1397,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) |
