Skip to content

Commit

Permalink
FT_ATOMIC_STORE_CHAR_RELEASE -> FT_ATOMIC_STORE_CHAR_RELAXED
Browse files Browse the repository at this point in the history
  • Loading branch information
dpdani committed Aug 29, 2024
1 parent 267f995 commit c006e1d
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 34 deletions.
6 changes: 3 additions & 3 deletions Include/cpython/pyatomic.h
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,9 @@ static inline void
_Py_atomic_store_ullong_relaxed(unsigned long long *obj,
unsigned long long value);

static inline void
_Py_atomic_store_char_relaxed(char *obj, char value);


// --- _Py_atomic_load_ptr_acquire / _Py_atomic_store_ptr_release ------------

Expand All @@ -502,9 +505,6 @@ _Py_atomic_store_ssize_release(Py_ssize_t *obj, Py_ssize_t value);
static inline void
_Py_atomic_store_int_release(int *obj, int value);

static inline void
_Py_atomic_store_char_release(char *obj, char value);

static inline void
_Py_atomic_store_uchar_release(unsigned char *obj, unsigned char value);

Expand Down
8 changes: 4 additions & 4 deletions Include/cpython/pyatomic_gcc.h
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,10 @@ _Py_atomic_store_ullong_relaxed(unsigned long long *obj,
unsigned long long value)
{ __atomic_store_n(obj, value, __ATOMIC_RELAXED); }

static inline void
_Py_atomic_store_char_relaxed(char *obj, char value)
{ __atomic_store_n(obj, value, __ATOMIC_RELEASE); }


// --- _Py_atomic_load_ptr_acquire / _Py_atomic_store_ptr_release ------------

Expand All @@ -540,10 +544,6 @@ static inline void
_Py_atomic_store_int_release(int *obj, int value)
{ __atomic_store_n(obj, value, __ATOMIC_RELEASE); }

static inline void
_Py_atomic_store_char_release(char *obj, char value)
{ __atomic_store_n(obj, value, __ATOMIC_RELEASE); }

static inline void
_Py_atomic_store_uchar_release(unsigned char *obj, unsigned char value)
{ __atomic_store_n(obj, value, __ATOMIC_RELEASE); }
Expand Down
19 changes: 6 additions & 13 deletions Include/cpython/pyatomic_msc.h
Original file line number Diff line number Diff line change
Expand Up @@ -947,6 +947,12 @@ _Py_atomic_store_ullong_relaxed(unsigned long long *obj,
*(volatile unsigned long long *)obj = value;
}

static inline void
_Py_atomic_store_char_relaxed(char *obj, char value)
{
*(volatile char *)obj = value;
}


// --- _Py_atomic_load_ptr_acquire / _Py_atomic_store_ptr_release ------------

Expand Down Expand Up @@ -1012,19 +1018,6 @@ _Py_atomic_store_int_release(int *obj, int value)
#endif
}

static inline void
_Py_atomic_store_char_release(char *obj, char value)
{
#if defined(_M_X64) || defined(_M_IX86)
*(char volatile *)obj = value;
#elif defined(_M_ARM64)
_Py_atomic_ASSERT_ARG_TYPE(unsigned __int8);
__stlr8((unsigned __int8 volatile *)obj, (unsigned __int8)value);
#else
# error "no implementation of _Py_atomic_store_char_release"
#endif
}

static inline void
_Py_atomic_store_uchar_release(unsigned char *obj, unsigned char value)
{
Expand Down
16 changes: 8 additions & 8 deletions Include/cpython/pyatomic_std.h
Original file line number Diff line number Diff line change
Expand Up @@ -916,6 +916,14 @@ _Py_atomic_store_ullong_relaxed(unsigned long long *obj,
memory_order_relaxed);
}

static inline void
_Py_atomic_store_char_relaxed(char *obj, char value)
{
_Py_USING_STD;
atomic_store_explicit((_Atomic(char)*)obj, value,
memory_order_relaxed);
}


// --- _Py_atomic_load_ptr_acquire / _Py_atomic_store_ptr_release ------------

Expand Down Expand Up @@ -959,14 +967,6 @@ _Py_atomic_store_int_release(int *obj, int value)
memory_order_release);
}

static inline void
_Py_atomic_store_char_release(char *obj, char value)
{
_Py_USING_STD;
atomic_store_explicit((_Atomic(char)*)obj, value,
memory_order_release);
}

static inline void
_Py_atomic_store_uchar_release(unsigned char *obj, unsigned char value)
{
Expand Down
4 changes: 2 additions & 2 deletions Include/internal/pycore_pyatomic_ft_wrappers.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ extern "C" {
_Py_atomic_store_uint16_relaxed(&value, new_value)
#define FT_ATOMIC_STORE_UINT32_RELAXED(value, new_value) \
_Py_atomic_store_uint32_relaxed(&value, new_value)
#define FT_ATOMIC_STORE_CHAR_RELEASE(value, new_value) \
_Py_atomic_store_char_release(&value, new_value)
#define FT_ATOMIC_STORE_CHAR_RELAXED(value, new_value) \
_Py_atomic_store_char_relaxed(&value, new_value)
#define FT_ATOMIC_LOAD_CHAR_RELAXED(value) \
_Py_atomic_load_char_relaxed(&value)
#define FT_ATOMIC_STORE_UCHAR_RELEASE(value, new_value) \
Expand Down
8 changes: 4 additions & 4 deletions Python/structmember.c
Original file line number Diff line number Diff line change
Expand Up @@ -171,16 +171,16 @@ PyMember_SetOne(char *addr, PyMemberDef *l, PyObject *v)
return -1;
}
if (v == Py_True)
FT_ATOMIC_STORE_CHAR_RELEASE(*(char*)addr, 1);
FT_ATOMIC_STORE_CHAR_RELAXED(*(char*)addr, 1);
else
FT_ATOMIC_STORE_CHAR_RELEASE(*(char*)addr, 0);
FT_ATOMIC_STORE_CHAR_RELAXED(*(char*)addr, 0);
break;
}
case Py_T_BYTE:{
long long_val = PyLong_AsLong(v);
if ((long_val == -1) && PyErr_Occurred())
return -1;
FT_ATOMIC_STORE_CHAR_RELEASE(*(char*)addr, (char)long_val);
FT_ATOMIC_STORE_CHAR_RELAXED(*(char*)addr, (char)long_val);
/* XXX: For compatibility, only warn about truncations
for now. */
if ((long_val > CHAR_MAX) || (long_val < CHAR_MIN))
Expand Down Expand Up @@ -320,7 +320,7 @@ PyMember_SetOne(char *addr, PyMemberDef *l, PyObject *v)
PyErr_BadArgument();
return -1;
}
FT_ATOMIC_STORE_CHAR_RELEASE(*(char*)addr, string[0]);
FT_ATOMIC_STORE_CHAR_RELAXED(*(char*)addr, string[0]);
break;
}
case Py_T_STRING:
Expand Down

0 comments on commit c006e1d

Please sign in to comment.