Skip to content

pthread: fix m68k test-and-set return value - #1847

Open
JJDSNT wants to merge 1 commit into
aros-development-team:masterfrom
JJDSNT:review/pthread-m68k-tas
Open

JJDSNT wants to merge 1 commit into
aros-development-team:masterfrom
JJDSNT:review/pthread-m68k-tas

Conversation

@JJDSNT

@JJDSNT JJDSNT commented Oct 25, 2026

Copy link
Copy Markdown
Contributor

Summary

  • make the m68k __sync_lock_test_and_set fallback return the value that was
    in the lock before the exchange;
  • remove the now-obsolete m68k warnings from the pthread AutoDocs;
  • add a focused test for spin trylock/lock/unlock and pthread_once.

Why

GCC defines __sync_lock_test_and_set as an atomic exchange that returns the
previous contents. The m68k fallback wrote the requested value and returned
that same value. Consequently the first acquisition of a clear spinlock wrote
one and reported one: pthread_spin_trylock() returned EBUSY, while
pthread_spin_lock() kept yielding indefinitely. This is reached by
libstdc++/Mesa through pthread_once() before rendering starts.

The fix preserves the old value while interrupts are disabled and returns it
after the exchange. It does not change the existing m68k locking model. The
separate m68k compare-and-swap fallback is outside this PR.

This is one commit directly on AROS master and has no PR dependencies.

Validation

  • complete libpthread.a builds for linux-x86_64 and amiga-m68k;
  • the new test builds and links with -Wall -Wextra -Werror on both targets;
  • the test passes inside Linux-hosted AROS;
  • the linked m68k test binary was inspected: it loads the old lock word before
    the store and returns that saved value;
  • cppcheck warning/performance/portability passes for the new test;
  • git diff --check passes.

The m68k test binary was cross-built but was not executed on m68k hardware or
an emulator during this validation.

The m68k fallback returned the value it stored instead of the previous
contents. This left spin locks permanently contended on their first
acquisition.

Preserve the old value and add coverage for spin trylock, lock, unlock and
pthread_once.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant