mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-07-06 11:18:30 +00:00
Fix nsync_mu_unlock_slow_() on Apple Silicon
We torture test dlmalloc() in test/libc/stdio/memory_test.c. That test was crashing on occasion on Apple M1 microprocessors when dlmalloc was using *NSYNC locks. It was relatively easy to spot the cause, which is this one particular compare and swap operation, which needed to change to use sequentially-consistent ordering rather than an acquire barrier
This commit is contained in:
parent
3b15d31247
commit
751d20d98d
5 changed files with 36 additions and 2 deletions
8
third_party/nsync/atomic.internal.h
vendored
8
third_party/nsync/atomic.internal.h
vendored
|
@ -86,6 +86,13 @@ static inline int atm_cas_relacq_u32_(nsync_atomic_uint32_ *p, uint32_t o,
|
|||
memory_order_relaxed);
|
||||
}
|
||||
|
||||
static inline int atm_cas_seqcst_u32_(nsync_atomic_uint32_ *p, uint32_t o,
|
||||
uint32_t n) {
|
||||
return atomic_compare_exchange_strong_explicit(NSYNC_ATOMIC_UINT32_PTR_(p),
|
||||
&o, n, memory_order_seq_cst,
|
||||
memory_order_relaxed);
|
||||
}
|
||||
|
||||
#define ATM_CAS_HELPER_(barrier, p, o, n) \
|
||||
(atm_cas_##barrier##_u32_((p), (o), (n)))
|
||||
|
||||
|
@ -93,6 +100,7 @@ static inline int atm_cas_relacq_u32_(nsync_atomic_uint32_ *p, uint32_t o,
|
|||
#define ATM_CAS_ACQ(p, o, n) ATM_CAS_HELPER_(acq, (p), (o), (n))
|
||||
#define ATM_CAS_REL(p, o, n) ATM_CAS_HELPER_(rel, (p), (o), (n))
|
||||
#define ATM_CAS_RELACQ(p, o, n) ATM_CAS_HELPER_(relacq, (p), (o), (n))
|
||||
#define ATM_CAS_SEQCST(p, o, n) ATM_CAS_HELPER_(seqcst, (p), (o), (n))
|
||||
|
||||
/* Need a cast to remove "const" from some uses. */
|
||||
#define ATM_LOAD(p) \
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue