Make more fixups and quality assurance

This commit is contained in:
Justine Tunney 2024-10-07 15:29:01 -07:00
parent 85c58be942
commit dcf9596620
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
17 changed files with 80 additions and 78 deletions

View file

@ -33,10 +33,6 @@ LOCAL CHANGES
lets us use weak cas when appropriate. It also avoids a superfluous
relaxed load on failure. This mostly impacts aarch64, not x86_64.
- Modified *NSYNC to allocate waiter objects on the stack. We need it
because we use *NSYNC mutexes to implement POSIX mutexes, which are
too low-level to safely depend on malloc, or even mmap in our case.
- Rewrote most of the semaphore and futex system call support code so
it works well with Cosmopolitan's fat runtime portability. *NSYNC's
unit test suite passes on all supported platforms. However the BSDs

View file

@ -477,9 +477,9 @@ void nsync_mu_unlock (nsync_mu *mu) {
and deallocate the mutex before the current thread touched the mutex
word again. */
uint32_t old_word = MU_WLOCK;
if (!atomic_compare_exchange_weak_explicit (&mu->word, &old_word, 0,
memory_order_release,
memory_order_relaxed)) {
if (!atomic_compare_exchange_strong_explicit (&mu->word, &old_word, 0,
memory_order_release,
memory_order_relaxed)) {
/* Clear MU_ALL_FALSE because the critical section we're just
leaving may have made some conditions true. */
uint32_t new_word = (old_word - MU_WLOCK) & ~MU_ALL_FALSE;
@ -508,9 +508,9 @@ void nsync_mu_runlock (nsync_mu *mu) {
IGNORE_RACES_START ();
/* See comment in nsync_mu_unlock(). */
uint32_t old_word = MU_RLOCK;
if (!atomic_compare_exchange_weak_explicit (&mu->word, &old_word, 0,
memory_order_release,
memory_order_relaxed)) {
if (!atomic_compare_exchange_strong_explicit (&mu->word, &old_word, 0,
memory_order_release,
memory_order_relaxed)) {
/* Sanity check: mutex must not be held in write mode and
reader count must not be 0. */
if (((old_word ^ MU_WLOCK) & (MU_WLOCK | MU_RLOCK_FIELD)) == 0) {