Repository navigation
feat(libc): implement _Mtx_timedlock - #10688
Conversation
MarcZX10
left a comment
There was a problem hiding this comment.
Reviewed exact head e46fd5038350e4a0e4d5e7112af00e14f480736a. The shared XtimePoint conversion keeps the existing overflow/normalization checks while giving both timed condition waits and timed mutex acquisition the same absolute deadline. The timed path checks ownership before locking, preserves recursive-count handling, and maps timeout and system errors to the stated thread results. The Linux guest_libc_threads and guest_libc_cnd_timed_wait runs are reported passing by the author; locally, both changed translation units passed MinGW syntax checks (with a define for a high-resolution timer constant missing from this container's older MinGW headers). git diff --check and merge-tree checks pass. Hosted product tests are skipped, and no Windows runtime test is reported, so Windows behavior remains unverified here; I found no blocking source issue in the reviewed code.
MarcZX10
left a comment
There was a problem hiding this comment.
Reviewed the full diff at e46fd50. The new export uses the shared absolute-xtime conversion, preserves recursive ownership bookkeeping, returns busy for a same-thread plain mutex and timedout on expiry; the Windows native mutex/condition pair is unified with the timed-capable standard primitives so _Cnd_wait and _Cnd_timedwait share the same mutex. The focused test covers future acquisition, same-thread busy, cross-thread timeout, invalid arguments and recursive acquisition; the author reports the libc thread tests pass on Linux. Hosted Linux/Windows/macOS relinker and ASAN jobs, register-context on Ubuntu/macOS and write-watch on macOS pass; product Linux/Windows jobs were skipped. No title execution is claimed.
MarcZX10
left a comment
There was a problem hiding this comment.
The implementation adds the missing timed-lock export, shares the absolute XTIME conversion with timed condition waits, and retains the existing recursive/non-recursive ownership bookkeeping. The Linux tests cover future acquisition, same-thread busy, another-thread timeout, recursive reacquisition, invalid handles/deadline, and the existing timed condition wait; the PR also reports inspection of the console error mapping and export NID. I verified the diff against current main, git diff --check, and conventions. Hosted relinker/ASan, register-context and write-watch matrices pass across the available platforms; product build jobs are path-skipped.
e46fd50 to
b3c9d35
Compare
|
Rebased onto |
|
@edubox Full CI on b3c9d35 (merged onto current main) fails on Windows only: |
|
Windows reproduction of the CI failure on this PR, measured on the PR head
AI-assisted (Claude Code). |
std::condition_variable_any regressed guest_libc_cnd_timed_wait on the Windows runner. Keep CRITICAL_SECTION/CONDITION_VARIABLE on Windows and poll TryEnterCriticalSection for _Mtx_timedlock.
|
Thanks for the Windows report. Pushed Linux: |
|
Windows rerun on the new head
AI-assisted (Claude Code). |
What
Export
_Mtx_timedlock(hPzYSd5Nasc), the timed counterpart of_Mtx_lock, which Minecraft Legends (PPSA05510) imports fromlibc.prx.It takes the same absolute
xtimeas_Cnd_timedwait, converts it once through the sharedXtimePointhelper, and keeps the mutex's recursive bookkeeping: a non-recursive mutex already held by the caller returns_Thrd_busy(3), a recursive one raises the count, and a free mutex acquires immediately. Expiry returns_Thrd_timedout(2); other host failures return 5, matching the console'slibc.prxat0x5d50(PPSA02530), where0x8002003cbecomes 2 and every other nonzero result becomes 5.On non-Windows hosts the native mutex and condition are
std::timed_mutexandstd::condition_variable_any. Windows keeps the previousCRITICAL_SECTION/CONDITION_VARIABLEpair and itsWaitUntilloop because the standardcondition_variable_anypath failedguest_libc_cnd_timed_waiton the full Windows runner;_Mtx_timedlockpollsTryEnterCriticalSectionwithSleep(1)until the deadline.docs/dev/debt/libc.mdrecords that the Windows timing of both the standard primitives and this polling path is not measured on the console.pr_overlapfinds no shared export. It sharesdocs/dev/debt/libc.md:38with #8903, and the PRs that conflict with the base also touchThreads.cpp/GuestLibcThreads.cpp(#1835, #5021, #7201, #9447, #10615, #10648); their diffs do not implement_Mtx_timedlockor change the native mutex type.Tested
CachyOS Linux 7.3.0-3, Ryzen 9 9900X, GCC 16.2.1,
main137a8fab89plus this PR.guest_libc_threadspasses withTimedMutex: acquire with a future deadline, same-thread non-recursive busy, another thread times out (2) while the mutex is held, release, null handle and null deadline throws, and a recursive mutex takes the timed lock twice.guest_libc_cnd_timed_waitpasses with the restored Windows path (Linux host).libc.prxexportshPzYSd5Nasc(nm -D).guest_libc_cnd_timed_waiton the Windows full CI; this head restores the path that passed there. A Windows rerun is pending (no MinGW locally).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)