Repository navigation
Conversation
pthread_mutex_trylock returns an errno value, unlike the Sce function it wraps, and had no test. Check the FreeBSD 11.4 results of __pthread_mutex_trylock and mutex_self_trylock (lib/libthr/thread/thr_mutex.c lines 611-640 and 850-873): a free or statically initialised mutex returns 0, a mutex held by the caller returns EBUSY for the error-checking and normal types and 0 for the recursive type, and a mutex held by another thread returns EBUSY. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
MarcZX10
left a comment
There was a problem hiding this comment.
The test cases match the current POSIX wrapper behavior: ToErrno maps the SCE busy result to EBUSY, same-thread reacquisition of normal/error-checking mutexes returns busy, recursive reacquisition succeeds, and a different thread holding the mutex returns busy. The Open Group specification requires EBUSY when trylock cannot acquire an already locked mutex, and FreeBSD 11.4's mutex_self_trylock explicitly returns EBUSY for normal/error-checking mutexes and allows recursive acquisition. The author reports five successful runs each on Windows and WSL/Linux; I have not independently run this C++ test. Current-main conventions and git diff --check pass.
The branch is based on 48c160c, while current main is 88795ed. CONTRIBUTING.md requires branches to stay up to date. Main has no intervening change to the CMake file or test source, but please sync before merge and rerun the registered test on the resulting head.
|
Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.
|
|
Merged AI-assisted (Claude Code). |
MarcZX10
left a comment
There was a problem hiding this comment.
The branch is now based on current main (88795ed448) and the author reports the registered test passing five times each on Windows and Ubuntu under WSL2. The cases cover free/static/error-checking/normal/recursive mutexes and a mutex held by another thread; the FreeBSD behavior reference supports the expected EBUSY results. Conventions and diff checks pass.
I built the exact test and registration in a current-main scratch checkout; guest_posix_mutex_trylock_tests passed under QEMU user-mode emulation. Native execution is unavailable on this host because it lacks the required CPU extensions. Hosted product jobs are skipped, but the author supplied repeat runs on the updated head. I found no remaining blocker and approve.
|
macOS run of head
AI-assisted: yes |
The test block of guest_posix_specific landed in main at the place where this branch adds its own; keep both blocks.
|
Merged AI-assisted (Claude Code). |
What
Adds
guest_posix_mutex_trylock, a behaviour test forpthread_mutex_trylock, the POSIX export that returns an errno value. It wrapsscePthreadMutexTrylock, which has tests, but the wrapper's own results had none. It follows FreeBSD 11.4'slib/libthr/thread/thr_mutex.c(__pthread_mutex_trylockandmutex_self_trylock):EBUSY(16) for the statically initialised, the error-checking and the normal type;EBUSY; the helper thread signals that it holds the lock, the main thread waits for that with a 5 s deadline, and then checks;No production code changes. There is no failing arm on
main: this is coverage of the POSIX wrapper over an already tested Sce function, not a fix. The test takes well under a second.Tested
fc08fd38c4onmain48c160c58b(ninja exit code 0):guest_posix_mutex_trylockpasses 5 of 5 runs.fc08fd38c4(ninja exit code 0): passes 5 of 5 runs.pthread_mutex_trylock_nid_postfix(Pthread/Posix/Mutex.cpp): the result ofscePthreadMutexTrylockreturned withoutToErrno(line 74),EBUSYreported as success (line 74) and a timed lock with no wait instead of the trylock (line 74) each fail the check "trylock of a held statically initialised mutex returns EBUSY". In the Sce trylock logic (Pthread/src/Mutex.cpp): giving a recursive holderEBUSY(line 68,owned && tryOnly) fails "recursive trylock by the holder returns 0 again", and reporting success for a busy mutex (line 248,sceBusyreplaced by 0) fails "trylock of a mutex held by another thread returns EBUSY". Removing the wrapper's static initialisation (line 73) is not caught:scePthreadMutexTrylockinitialises a static mutex itself. Each change was reverted afterwards.check_conventions --base upstream/mainpasses.main801d5b9bc1plus the open macOS build PRs, this PR's diff on top):guest_posix_mutex_trylockpasses 6 of 6 on head6a6ffb62d4(comment).EAGAINoverflow of a recursive mutex, the rest of the libkernel tests on this head. The expected behaviour comes from the FreeBSD 11.4 source; the console itself is not measured.Overlap
No open PR adds a test for
pthread_mutex_trylock;git greponmainfinds no test that calls it. 55 open PRs changecore/libs/prx/libkernel/CMakeLists.txtor this test.git merge-treeof this head with each of them conflicts for 17 (measured againstmain761eaba441); 16 of those already conflict withmainon their own. The seventeenth is my own #10979, where both PRs add a test block beforeguest_rename_dot_testsand #10979 merges cleanly intomainalone. Whichever lands second rebases; this PR depends on none of them.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)AI-assisted (Claude Code).
🤖 Generated with Claude Code