Skip to content

Commit

Permalink
Address code review
Browse files Browse the repository at this point in the history
  • Loading branch information
corona10 committed Nov 10, 2024
1 parent aa8a81c commit 1f4a350
Showing 1 changed file with 2 additions and 23 deletions.
25 changes: 2 additions & 23 deletions Python/specialize.c
Original file line number Diff line number Diff line change
Expand Up @@ -689,24 +689,6 @@ set_opcode(_Py_CODEUNIT *instr, uint8_t opcode)
#endif
}

static inline int
set_cache_version(uint16_t *old_version, uint32_t new_version)
{
#ifdef Py_GIL_DISABLED
uint16_t old_version_val = _Py_atomic_load_uint16_relaxed(old_version);
if (old_version_val > (uint16_t)new_version) {
return 0;
}
if (!_Py_atomic_compare_exchange_uint16(old_version, &old_version_val, new_version)) {
return 0;
}
return 1;
#else
write_u32(old_version, new_version);
return 1;
#endif
}

static inline void
set_counter(_Py_BackoffCounter *counter, _Py_BackoffCounter value)
{
Expand Down Expand Up @@ -2755,16 +2737,13 @@ _Py_Specialize_ToBool(_PyStackRef value_o, _Py_CODEUNIT *instr)
unspecialize(instr, SPEC_FAIL_OUT_OF_VERSIONS);
return;
}
uint32_t version = FT_ATOMIC_LOAD_UINT32_RELAXED(Py_TYPE(value)->tp_version_tag);
uint32_t version = Py_TYPE(value)->tp_version_tag;
if (version == 0) {
unspecialize(instr, SPEC_FAIL_OUT_OF_VERSIONS);
return;
}
if (!set_cache_version(cache->version, version)) {
unspecialize(instr, SPEC_FAIL_OUT_OF_VERSIONS);
return;
}
specialize(instr, TO_BOOL_ALWAYS_TRUE);
write_u32(cache->version, version);
assert(version);
return;
}
Expand Down

0 comments on commit 1f4a350

Please sign in to comment.