GeezerVison is showing github.com — Use Py_BEGIN_CRITICAL_SECTION · python/cpython@abf568a
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: Python/Python-tokenize.c +6-17Lines changed: 6 additions & 17 deletions | Original file line number | Diff line number | Diff line change |
|---|
|
1 | 1 | #include "Python.h" |
2 | 2 | #include "errcode.h" |
3 | | -#include "internal/pycore_lock.h" // PyMutex |
| 3 | +#include "internal/pycore_critical_section.h" // Py_BEGIN_CRITICAL_SECTION |
4 | 4 | #include "../Parser/lexer/state.h" |
5 | 5 | #include "../Parser/lexer/lexer.h" |
6 | 6 | #include "../Parser/tokenizer/tokenizer.h" |
7 | | -#include "../Parser/pegen.h" // _PyPegen_byte_offset_to_character_offset() |
| 7 | +#include "../Parser/pegen.h" // _PyPegen_byte_offset_to_character_offset() |
8 | 8 |
|
9 | 9 | static struct PyModuleDef _tokenizemodule; |
10 | 10 |
|
@@ -38,10 +38,6 @@ typedef struct |
38 | 38 | PyObject *last_line; |
39 | 39 | Py_ssize_t last_lineno; |
40 | 40 | Py_ssize_t byte_col_offset_diff; |
41 | | - |
42 | | -#ifdef Py_GIL_DISABLED |
43 | | - PyMutex mutex; |
44 | | -#endif |
45 | 41 | } tokenizeriterobject; |
46 | 42 |
|
47 | 43 | /*[clinic input] |
@@ -79,10 +75,6 @@ tokenizeriter_new_impl(PyTypeObject *type, PyObject *readline, |
79 | 75 | } |
80 | 76 | self->done = 0; |
81 | 77 |
|
82 | | -#ifdef Py_GIL_DISABLED |
83 | | - self->mutex = (PyMutex) {_Py_UNLOCKED}; |
84 | | -#endif |
85 | | - |
86 | 78 | self->last_line = NULL; |
87 | 79 | self->byte_col_offset_diff = 0; |
88 | 80 | self->last_lineno = 0; |
@@ -191,13 +183,10 @@ tokenizeriter_next(tokenizeriterobject *it) |
191 | 183 | struct token token; |
192 | 184 | _PyToken_Init(&token); |
193 | 185 |
|
194 | | -#ifdef Py_GIL_DISABLED |
195 | | - PyMutex_Lock(&it->mutex); |
196 | | -#endif |
197 | | - int type = _PyTokenizer_Get(it->tok, &token); |
198 | | -#ifdef Py_GIL_DISABLED |
199 | | - PyMutex_Unlock(&it->mutex); |
200 | | -#endif |
| 186 | + int type; |
| 187 | + Py_BEGIN_CRITICAL_SECTION(it); |
| 188 | + type = _PyTokenizer_Get(it->tok, &token); |
| 189 | + Py_END_CRITICAL_SECTION(); |
201 | 190 |
|
202 | 191 | if (type == ERRORTOKEN) { |
203 | 192 | if(!PyErr_Occurred()) { |
|