Skip to content

Commit

Permalink
atomics: Use acquire/release semantics by default
Browse files Browse the repository at this point in the history
  • Loading branch information
LekKit authored Mar 11, 2024
1 parent d67501b commit 77cb988
Showing 1 changed file with 20 additions and 20 deletions.
40 changes: 20 additions & 20 deletions src/atomics.h
Original file line number Diff line number Diff line change
Expand Up @@ -317,52 +317,52 @@ static forceinline uint32_t atomic_or_uint32_ex(void* addr, uint32_t val, int me

static forceinline uint32_t atomic_load_uint32(const void* addr)
{
return atomic_load_uint32_ex(addr, ATOMIC_SEQ_CST);
return atomic_load_uint32_ex(addr, ATOMIC_ACQUIRE);
}

static forceinline void atomic_store_uint32(void* addr, uint32_t val)
{
atomic_store_uint32_ex(addr, val, ATOMIC_SEQ_CST);
atomic_store_uint32_ex(addr, val, ATOMIC_RELEASE);
}

static forceinline uint32_t atomic_swap_uint32(void* addr, uint32_t val)
{
return atomic_swap_uint32_ex(addr, val, ATOMIC_SEQ_CST);
return atomic_swap_uint32_ex(addr, val, ATOMIC_ACQ_REL);
}

static forceinline bool atomic_cas_uint32(void* addr, uint32_t exp, uint32_t val)
{
return atomic_cas_uint32_ex(addr, exp, val, false, ATOMIC_SEQ_CST, ATOMIC_SEQ_CST);
return atomic_cas_uint32_ex(addr, exp, val, false, ATOMIC_ACQ_REL, ATOMIC_ACQUIRE);
}

static forceinline bool atomic_cas_uint32_weak(void* addr, uint32_t exp, uint32_t val)
{
return atomic_cas_uint32_ex(addr, exp, val, true, ATOMIC_SEQ_CST, ATOMIC_SEQ_CST);
return atomic_cas_uint32_ex(addr, exp, val, true, ATOMIC_ACQ_REL, ATOMIC_ACQUIRE);
}

static forceinline uint32_t atomic_add_uint32(void* addr, uint32_t val)
{
return atomic_add_uint32_ex(addr, val, ATOMIC_SEQ_CST);
return atomic_add_uint32_ex(addr, val, ATOMIC_ACQ_REL);
}

static forceinline uint32_t atomic_sub_uint32(void* addr, uint32_t val)
{
return atomic_sub_uint32_ex(addr, val, ATOMIC_SEQ_CST);
return atomic_sub_uint32_ex(addr, val, ATOMIC_ACQ_REL);
}

static forceinline uint32_t atomic_and_uint32(void* addr, uint32_t val)
{
return atomic_and_uint32_ex(addr, val, ATOMIC_SEQ_CST);
return atomic_and_uint32_ex(addr, val, ATOMIC_ACQ_REL);
}

static forceinline uint32_t atomic_xor_uint32(void* addr, uint32_t val)
{
return atomic_xor_uint32_ex(addr, val, ATOMIC_SEQ_CST);
return atomic_xor_uint32_ex(addr, val, ATOMIC_ACQ_REL);
}

static forceinline uint32_t atomic_or_uint32(void* addr, uint32_t val)
{
return atomic_or_uint32_ex(addr, val, ATOMIC_SEQ_CST);
return atomic_or_uint32_ex(addr, val, ATOMIC_ACQ_REL);
}

/*
Expand Down Expand Up @@ -541,52 +541,52 @@ static forceinline uint64_t atomic_or_uint64_ex(void* addr, uint64_t val, int me

static forceinline uint64_t atomic_load_uint64(const void* addr)
{
return atomic_load_uint64_ex(addr, ATOMIC_SEQ_CST);
return atomic_load_uint64_ex(addr, ATOMIC_ACQUIRE);
}

static forceinline void atomic_store_uint64(void* addr, uint64_t val)
{
atomic_store_uint64_ex(addr, val, ATOMIC_SEQ_CST);
atomic_store_uint64_ex(addr, val, ATOMIC_RELEASE);
}

static forceinline uint64_t atomic_swap_uint64(void* addr, uint64_t val)
{
return atomic_swap_uint64_ex(addr, val, ATOMIC_SEQ_CST);
return atomic_swap_uint64_ex(addr, val, ATOMIC_ACQ_REL);
}

static forceinline bool atomic_cas_uint64(void* addr, uint64_t exp, uint64_t val)
{
return atomic_cas_uint64_ex(addr, exp, val, false, ATOMIC_SEQ_CST, ATOMIC_SEQ_CST);
return atomic_cas_uint64_ex(addr, exp, val, false, ATOMIC_ACQ_REL, ATOMIC_ACQUIRE);
}

static forceinline bool atomic_cas_uint64_weak(void* addr, uint64_t exp, uint64_t val)
{
return atomic_cas_uint64_ex(addr, exp, val, true, ATOMIC_SEQ_CST, ATOMIC_SEQ_CST);
return atomic_cas_uint64_ex(addr, exp, val, true, ATOMIC_ACQ_REL, ATOMIC_ACQUIRE);
}

static forceinline uint64_t atomic_add_uint64(void* addr, uint64_t val)
{
return atomic_add_uint64_ex(addr, val, ATOMIC_SEQ_CST);
return atomic_add_uint64_ex(addr, val, ATOMIC_ACQ_REL);
}

static forceinline uint64_t atomic_sub_uint64(void* addr, uint64_t val)
{
return atomic_sub_uint64_ex(addr, val, ATOMIC_SEQ_CST);
return atomic_sub_uint64_ex(addr, val, ATOMIC_ACQ_REL);
}

static forceinline uint64_t atomic_and_uint64(void* addr, uint64_t val)
{
return atomic_and_uint64_ex(addr, val, ATOMIC_SEQ_CST);
return atomic_and_uint64_ex(addr, val, ATOMIC_ACQ_REL);
}

static forceinline uint64_t atomic_xor_uint64(void* addr, uint64_t val)
{
return atomic_xor_uint64_ex(addr, val, ATOMIC_SEQ_CST);
return atomic_xor_uint64_ex(addr, val, ATOMIC_ACQ_REL);
}

static forceinline uint64_t atomic_or_uint64(void* addr, uint64_t val)
{
return atomic_or_uint64_ex(addr, val, ATOMIC_SEQ_CST);
return atomic_or_uint64_ex(addr, val, ATOMIC_ACQ_REL);
}

/*
Expand Down

0 comments on commit 77cb988

Please sign in to comment.