Repository navigation
Conversation
The versioned Dinkumware entries operate on libkernel's own mutex, condition and thread handles: _Mtx_init(_with_name), _Mtx_destroy, _Mtx_lock, _Mtx_trylock, _Mtx_unlock, _Cnd_init(_with_name), _Cnd_destroy, _Cnd_wait, _Cnd_signal, _Cnd_broadcast, _Thrd_detach, _Thrd_join, _Thrd_yield, _Thrd_id and _Throw_Cpp_error. libkernel registers the pthread calls with libc next to the C11 forwards. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01RbLgECLQ2bpDM7oe2urGZK
The console's std::__sce_v2::_Throw_Cpp_error raises a std::__sce_v2::system_error, not the unversioned std::system_error this forwarded to. It moves to the versioned exception change, which adds that type. Review on boykopovar#8885: the versioned unlock, wait, signal and broadcast calls return 0 whatever the kernel returns, as the console's do (each calls the kernel and clears eax). The test now shows the kernel failing an unowned unlock and wait while the wrappers report success. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01RbLgECLQ2bpDM7oe2urGZK
…read-sync # Conflicts: # core/libs/tests/GuestLibcThreads.cpp
Progress report (a6dcea9 → 2dc7b70)📈 System libraries: 42.44% (+0.11%, +20 implemented functions) ✅ 20 implemented
|
|
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.
|
MarcZX10
left a comment
There was a problem hiding this comment.
The focused condition-variable cases cover signalled, expired and future deadlines, and the thread-start/current-affinity paths are backed by guest tests. I found a conversion boundary defect in MicrosecondsUntil: with a normalized deadline exactly 4,294 seconds ahead and a fractional component above 967,295 microseconds, the computed total exceeds UINT_MAX, but the guard only clamps when seconds > 4294; casting the larger total to unsigned int wraps it to a short timeout. Please clamp/check the total microseconds (including the fractional part) before conversion and add a boundary test around UINT_MAX.
The PR correctly declares its dependency on #8885 and says to rebase after that PR merges. Keep that ordering; once #8885 lands, rebase this branch onto then-current main and rerun the focused thread tests, conventions and overlap checks. The current head is tied to the older #8885 branch and its Linux tests were run on fork CI; Windows/title/console runs are explicitly not claimed. I did not run local tests.
|
Windows run of 2dc7b70 merged onto The merge conflicts only in |
…start, timed wait, clock and processor count calls Dropped the PR's copy of boykopovar#8885 (already in our tree); took _Thrd_start, _Cnd_timedwait, now_v1_compat, the create/condTimedwait/getAffinity forwards and the PR's affinity-mask _Thrd_hardware_concurrency over ours (host count, CxxAbiSupport.cpp), so guest_hardware_concurrency (host-count test) is removed; removed two stale duplicate _Pad debt bullets.
|
@AlxcBTW this conflicts with main now ( |
What
#8885 adds the versioned (
std::__sce_v2)_Mtx,_Cndand_Thrdcalls on the libkernelscePthread*functions and lists the calls it leaves out. This adds three of them and one clock, inThreads.cppandTime.cppnext to #8885's, each written from the console'slibc.prxdisassembly:std::__sce_v2::_Thrd_start(pthread**, void*(*)(void*), void*)(2cXiHqvKFUM)scePthreadCreatewith default attributes and the nameThr; returns 0, or 4 for any failure (the console returns nothing else)std::__sce_v2::_Thrd_hardware_concurrency()(dt3C+gjXHKk)scePthreadGetaffinityof the first calling thread), computed oncestd::__sce_v2::_Cnd_timedwait(pthread_cond**, pthread_mutex**, const timespec*)(230scaAkbIU)scePthreadCondTimedwait; returns 0 when signalled, 2 onETIMEDOUT, 4 for other errors and 5 forEPERM, as the console's result mapping doesstd::__sce_v2::chrono::steady_clock::now_v1_compat()(EMwrSFcyowE)gettimeofdayasseconds * 1000000 + microseconds, the unversioned_Xtime_get_ticksvalueWhat the disassembly says that the topic's first description did not:
now_v1_compatdoes not readCLOCK_MONOTONICand does not count nanoseconds; the console callsgettimeofdayand returns microseconds of the realtime clock, so that is what it does here (and it is not monotonic if the system clock steps)._Thrd_hardware_concurrencyis not the host's processor count: the module caches the population count of the main thread's affinity mask (13 with the libkernel default mask0x1FFF). The libkernel forwards forscePthreadCreate,scePthreadCondTimedwaitandscePthreadGetaffinityare three more members of #8885'sPthreadSyncForwards_nid_no_patch, registered where #8885 registers the others (libkernel/Pthread/Posix/Thread.cpp,libc/include/General.hpp).Not in this PR:
std::__sce_v2::_Xtime_get_ticks(XXOOIxrIKDM) is in feat(libc): add the std::__sce_v2 exception types and throwers #8901 with the same body (the unversioned call, microseconds);tools/pr_overlap.pylists it, so it is left to that PR.std::__sce_v2::_Cnd_do_broadcast_at_thread_exit(2s6aLdPIA4I) is left out. The disassembled body does not register a broadcast; it walks the per-process table of registrations for the calling thread, signals and broadcasts each and clears it. That table is filled by_Cnd_register_at_thread_exit, which is not implemented in libc (the_Pad::_Launchentry in the debt file says the same), so an implementation now would be a function that never finds anything. The debt entry says so.Known differences, in
docs/dev/debt/libc.md: the remaining time saturates at 4294967295 microseconds where the console wraps its 32-bit result; the processor count is read from the first caller's mask, not the main thread's at module start.Titles that import these: Minecraft Dungeons II (PPSA16064) imports the four calls above and the two left out below.
Tested
guest_libc|guest_freebsd|libc_|libkernel|pthread): 33 of 33 passed, among themguest_libc_threads(0.10 s). Not run on Windows, and not run on a console or with a title.guest_libc_threads(core/libs/tests/GuestLibcThreads.cpp) has three new cases, written the way feat(libc): add the std::__sce_v2 mutex, condition and thread calls #8885'sVersionedSyncis._Thrd_startruns a function with a distinct argument and the test joins it (_Thrd_join): the argument arrives, the return value 7 comes back as the exit code, and_Thrd_startreturns 0._Cnd_timedwaitwith the mutex held: a deadline 50 ms ahead and nobody signalling returns 2 after at least 45 ms and under 2 s; a deadline 1 s in the past returns 2 in under 500 ms; a second thread that locks the mutex and signals while the first waits on a deadline 10 s ahead makes the wait return 0 in under 5 s.now_v1_compatis non-decreasing over 1000 samples, advances by 9000 to 500000 across a 10 ms sleep (microsecond unit) and lies within one second of the realtime clock._Thrd_hardware_concurrencyis between 1 and 64.python3 tools/check_conventions.py --base origin/mainpasses.tools/pr_overlap.py --branchlists feat(libc): add the std::__sce_v2 exception types and throwers #8901 (_Xtime_get_ticks, left out of this PR above) and feat(libc): implement system_category and future_category error categ… #9416 (_Thrd_detach,_Cnd_broadcast, which are feat(libc): add the std::__sce_v2 mutex, condition and thread calls #8885's), and textual overlaps indocs/dev/debt/libc.mdline 136 (feat(libc): implement siginterrupt through the sigaction libkernel registers #8872, feat(libc): export the num_get and time_get locale objects as data #8880, test(libc): cover siginterrupt state boundaries #9001, feat(libSceLibcInternal): implement posix_spawn process creation and reaping #9133, fix(libc): return the calling thread from _Thrd_id as the console's libc.prx does #9170) andTime.cppnear line 570 (feat(libc): implement C11 timespec_get for PPSA34015 #9388); none implements the same function.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)mainafter it merges)