casaroli opened a new pull request, #21451: URL: https://github.com/apache/nuttx/pull/21451
## Summary `pthread_spin_trylock()` of a held spin lock does not return `EBUSY`. POSIX: "[EBUSY] A thread currently holds the lock". - **The caller holds the lock:** it returns 0. The lock is not recursive: the first `pthread_spin_unlock()` releases it. It now returns `EBUSY`. - **Another thread holds the lock:** it returns 1 (`EPERM`). `boardctl()` returns -1 and sets `errno`, but the code returns `-ret`. `pthread_spin_trylock()` and `pthread_spin_lock()` now return `errno`. ## Impact - All build modes and architectures: the change is in common libc code, with `CONFIG_PTHREAD_SPINLOCKS` only. - A program that calls `pthread_spin_trylock()` on a lock that it holds now gets `EBUSY`, not 0. This is a change of behaviour that flat-build programs can see. Nothing in nuttx or nuttx-apps calls `pthread_spin_trylock()` or `pthread_spin_lock()`. - `pthread_spin_lock()` by the holder still returns `EDEADLOCK`. - No documentation change: `Documentation/standards/posix.rst` lists only that the function exists. ## Testing Test program `spintryself.c`, 12 checks: | check | master | this PR | | --- | --- | --- | | trylock by the holder, taken with `pthread_spin_lock()` | FAIL 0 | PASS `EBUSY` | | trylock by the holder, taken with `pthread_spin_trylock()` | FAIL 0 | PASS `EBUSY` | | trylock by another thread, the lock is held | FAIL 1 | PASS `EBUSY` | | init, lock, unlock, trylock of a free lock (also by another thread), destroy | 9 PASS | 9 PASS | The results are the same on qemu-armv8a:knsh (kernel, arm64, QEMU with HVF) and qemu-armv8a:nsh (flat, arm64, HVF): master 9 PASS, 3 FAIL; this PR 12 PASS. ostest exits with status 0 on master and with this PR: qemu-armv8a:knsh, qemu-armv8a:nsh, and the flat qemu-armv8a:nsh build with the test. All have `CONFIG_PTHREAD_SPINLOCKS`. No test in CI checks the result for a lock that the caller holds. Builds with `EXTRAFLAGS="-Wno-cpp -Werror"`, each OK: qemu-armv8a:knsh, qemu-armv8a:nsh, mps2-an500:knsh (protected) and sim:nsh (macOS host), each with `CONFIG_PTHREAD_SPINLOCKS`; rv-virt:citest, which has it in its defconfig. The only warnings come from the linkers: `-ld_classic` on macOS, RWX segment on rv-virt:citest. The protected build is built only. The tests ran on master 39a1f27900c; the branch is rebased on 3d57048f1e1 (no change in the touched files). `tools/checkpatch.sh -c -u -m -g` passes. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
