Skip to content

Commit 0276a3e

Browse files
gh-115999: Restore SET_OPCODE_OR_RETURN removed in GH-126414
1 parent 8fa4dc4 commit 0276a3e

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

Python/specialize.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,25 @@ extern const char *_PyUOpName(int index);
2424
* ./adaptive.md
2525
*/
2626

27+
#ifdef Py_GIL_DISABLED
28+
#define SET_OPCODE_OR_RETURN(instr, opcode) \
29+
do { \
30+
uint8_t old_op = _Py_atomic_load_uint8_relaxed(&(instr)->op.code); \
31+
if (old_op >= MIN_INSTRUMENTED_OPCODE) { \
32+
/* Lost race with instrumentation */ \
33+
return; \
34+
} \
35+
if (!_Py_atomic_compare_exchange_uint8(&(instr)->op.code, &old_op, \
36+
(opcode))) { \
37+
/* Lost race with instrumentation */ \
38+
assert(old_op >= MIN_INSTRUMENTED_OPCODE); \
39+
return; \
40+
} \
41+
} while (0)
42+
#else
43+
#define SET_OPCODE_OR_RETURN(instr, opcode) (instr)->op.code = (opcode)
44+
#endif
45+
2746
#ifdef Py_STATS
2847
GCStats _py_gc_stats[NUM_GENERATIONS] = { 0 };
2948
static PyStats _Py_stats_struct = { .gc_stats = _py_gc_stats };

0 commit comments

Comments
 (0)