Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Lib/test/test_thread_local_bytecode.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ def f(a, b, q=None):
""")
assert_python_ok("-X", "tlbc=1", "-c", code)

@support.skip_if_sanitizer("gh-129752: data race on adaptive counter", thread=True)
def test_no_copies_if_tlbc_disabled(self):
code = textwrap.dedent("""
import queue
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Don't update adaptive counters in the free-threaded build when thread-local
bytecode is disabled (``-X tlbc=0``). Patch by Donghee Na.
20 changes: 20 additions & 0 deletions Python/ceval_macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,25 @@ GETITEM(PyObject *v, Py_ssize_t i) {
#define ADAPTIVE_COUNTER_TRIGGERS(COUNTER) \
backoff_counter_triggers(forge_backoff_counter((COUNTER)))

#ifdef Py_GIL_DISABLED
/* Counters are unreachable when thread-local bytecode is disabled,
* so there is no need to update them. */
#define ADVANCE_ADAPTIVE_COUNTER(COUNTER) \
do { \
_Py_BackoffCounter cnt = (COUNTER); \
if (!is_unreachable_backoff_counter(cnt)) { \
(COUNTER) = advance_backoff_counter(cnt); \
} \
} while (0);

#define PAUSE_ADAPTIVE_COUNTER(COUNTER) \
do { \
_Py_BackoffCounter cnt = (COUNTER); \
if (!is_unreachable_backoff_counter(cnt)) { \
(COUNTER) = pause_backoff_counter(cnt); \
} \
} while (0);
#else
#define ADVANCE_ADAPTIVE_COUNTER(COUNTER) \
do { \
(COUNTER) = advance_backoff_counter((COUNTER)); \
Expand All @@ -294,6 +313,7 @@ GETITEM(PyObject *v, Py_ssize_t i) {
do { \
(COUNTER) = pause_backoff_counter((COUNTER)); \
} while (0);
#endif

#ifdef ENABLE_SPECIALIZATION_FT
/* Multiple threads may execute these concurrently if thread-local bytecode is
Expand Down
Loading