mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-06-27 14:58: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
23
third_party/dlmalloc/locks.inc
vendored
23
third_party/dlmalloc/locks.inc
vendored
|
@ -30,6 +30,8 @@
|
|||
|
||||
*/
|
||||
|
||||
#ifdef USE_SPIN_LOCKS
|
||||
|
||||
#define MLOCK_T atomic_uint
|
||||
|
||||
static int malloc_wipe(MLOCK_T *lk) {
|
||||
|
@ -51,6 +53,27 @@ static int malloc_unlock(MLOCK_T *lk) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
#define MLOCK_T nsync_mu
|
||||
|
||||
static int malloc_wipe(MLOCK_T *lk) {
|
||||
bzero(lk, sizeof(*lk));
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int malloc_lock(MLOCK_T *lk) {
|
||||
nsync_mu_lock(lk);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int malloc_unlock(MLOCK_T *lk) {
|
||||
nsync_mu_unlock(lk);
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#define ACQUIRE_LOCK(lk) malloc_lock(lk)
|
||||
#define RELEASE_LOCK(lk) malloc_unlock(lk)
|
||||
#define INITIAL_LOCK(lk) malloc_wipe(lk)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue