Skip to content

Commit abf568a

Browse files
committed
Use Py_BEGIN_CRITICAL_SECTION
1 parent 900dd6a commit abf568a

File tree

1 file changed

+6
-17
lines changed

1 file changed

+6
-17
lines changed

Python/Python-tokenize.c

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
#include "Python.h"
22
#include "errcode.h"
3-
#include "internal/pycore_lock.h" // PyMutex
3+
#include "internal/pycore_critical_section.h" // Py_BEGIN_CRITICAL_SECTION
44
#include "../Parser/lexer/state.h"
55
#include "../Parser/lexer/lexer.h"
66
#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()
88

99
static struct PyModuleDef _tokenizemodule;
1010

@@ -38,10 +38,6 @@ typedef struct
3838
PyObject *last_line;
3939
Py_ssize_t last_lineno;
4040
Py_ssize_t byte_col_offset_diff;
41-
42-
#ifdef Py_GIL_DISABLED
43-
PyMutex mutex;
44-
#endif
4541
} tokenizeriterobject;
4642

4743
/*[clinic input]
@@ -79,10 +75,6 @@ tokenizeriter_new_impl(PyTypeObject *type, PyObject *readline,
7975
}
8076
self->done = 0;
8177

82-
#ifdef Py_GIL_DISABLED
83-
self->mutex = (PyMutex) {_Py_UNLOCKED};
84-
#endif
85-
8678
self->last_line = NULL;
8779
self->byte_col_offset_diff = 0;
8880
self->last_lineno = 0;
@@ -191,13 +183,10 @@ tokenizeriter_next(tokenizeriterobject *it)
191183
struct token token;
192184
_PyToken_Init(&token);
193185

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();
201190

202191
if (type == ERRORTOKEN) {
203192
if(!PyErr_Occurred()) {

0 commit comments

Comments
 (0)