feat(libwebrtc): implement rtc::RecursiveCriticalSection and rtc::CritScope #14232

Merged
jacknieland merged 5 commits from upstream-pr/14232 into main 2026-11-06 03:37:01 +00:00
jacknieland commented 2026-11-01 01:49:12 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by jacknieland on 2026-11-01T01:49:12Z.


What

Implements rtc::RecursiveCriticalSection (constructor, destructor, Enter, Leave) and rtc::CritScope (constructor, destructor) in libwebrtc. All six threw.

rtc_base/deprecated/recursive_critical_section.h and .cc are the same at M127 branch-heads/6533 and M134 branch-heads/6998, the revisions the debt file pins. src/RecursiveCriticalSection.cpp follows their POSIX path, with WebRTC's copyright notice and BSD licence at the top, as ExpFilter.cpp does:

  • The constructor makes a PTHREAD_MUTEX_RECURSIVE (2) guest mutex through libkernel's pthread_mutexattr_* and pthread_mutex_init, and the destructor destroys it. Enter and Leave lock and unlock it.
  • CritScope stores the section it is given, enters it, and leaves it in its destructor.
  • include/RecursiveCriticalSection.hpp gives the 24-byte layout of the header: pthread_mutex_t mutex_ (a pointer on the console) at 0, thread_ at 8 and recursion_count_ at 16. thread_ and recursion_count_ are only written by RTC_DCHECK_IS_ON builds, which also check the owning thread. Whether the module is one is unknown, so neither is written or checked, and the debt entry says so.
  • A non-zero return from a guest pthread call throws, where upstream ignores it, and a null section or scope throws std::invalid_argument, as ExpFilter does.
  • The pending count drops from 390 to 384.

Tested

Windows 11 Pro (26200), WinLibs GCC 15.2.0 (x86_64-ucrt-posix-seh, r7), Release, BUILD_TESTING=ON, Ninja, on head 418462fbac (this branch, on main 029463ceb6).

  • New guest_webrtc_recursive_critical_section test:
    • A new section is free; after two Enters a trylock from another thread gets EBUSY, still after one Leave, and succeeds after the second.
    • CritScope stores its section and holds it; a nested scope's destructor leaves the outer one held, and the outer destructor frees it.
    • Four threads each increment a shared counter 20,000 times under CritScope, and no increment is lost.
    • Every null this or section throws std::invalid_argument.
  • ctest -R guest_webrtc --repeat until-fail:3: all six libwebrtc tests pass 3/3. ctest -R public_headers: 65/65 pass.
  • Negative control: with NotImplemented_nid_no_patch(__func__) at the top of each of the six functions, as the main stubs do, the test fails 3/3 with _ZN3rtc24RecursiveCriticalSectionC1Ev_nid_postfix not implemented.
  • check_conventions.py --base upstream/main passes. An overlap scan of the diffs of all open pull requests that touch libwebrtc found none that changes these exports; they conflict with this one only in appended CMakeLists.txt and debt lines.
  • Not tested: Linux, a title. Only the targets above were built, not the full test suite.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none; the older open libwebrtc PRs can land first, and I'll merge main after each
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5103436874 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/14232). Originally posted by [jacknieland](https://github.com/jacknieland) on 2026-11-01T01:49:12Z. --- ### What Implements `rtc::RecursiveCriticalSection` (constructor, destructor, `Enter`, `Leave`) and `rtc::CritScope` (constructor, destructor) in libwebrtc. All six threw. `rtc_base/deprecated/recursive_critical_section.h` and `.cc` are the same at [M127 branch-heads/6533](https://webrtc.googlesource.com/src/+/e0b28a6a81a989c1f5c89e30fcd247870047390d/rtc_base/deprecated/recursive_critical_section.cc) and [M134 branch-heads/6998](https://webrtc.googlesource.com/src/+/8d78f5de6c27b2c793039989ea381f1428fb0100/rtc_base/deprecated/recursive_critical_section.cc), the revisions the debt file pins. `src/RecursiveCriticalSection.cpp` follows their POSIX path, with WebRTC's copyright notice and BSD licence at the top, as `ExpFilter.cpp` does: - The constructor makes a `PTHREAD_MUTEX_RECURSIVE` (2) guest mutex through libkernel's `pthread_mutexattr_*` and `pthread_mutex_init`, and the destructor destroys it. `Enter` and `Leave` lock and unlock it. - `CritScope` stores the section it is given, enters it, and leaves it in its destructor. - `include/RecursiveCriticalSection.hpp` gives the 24-byte layout of the header: `pthread_mutex_t mutex_` (a pointer on the console) at 0, `thread_` at 8 and `recursion_count_` at 16. `thread_` and `recursion_count_` are only written by `RTC_DCHECK_IS_ON` builds, which also check the owning thread. Whether the module is one is unknown, so neither is written or checked, and the debt entry says so. - A non-zero return from a guest pthread call throws, where upstream ignores it, and a null section or scope throws `std::invalid_argument`, as `ExpFilter` does. - The pending count drops from 390 to 384. ### Tested <!-- OS, title or homebrew, what was checked. "Not tested" is a valid answer. A performance change: the summary lines of main and of this PR from the same machine and scene, with the traces attached, captured as the Performance report issue form describes. --> Windows 11 Pro (26200), WinLibs GCC 15.2.0 (`x86_64-ucrt-posix-seh`, r7), Release, `BUILD_TESTING=ON`, Ninja, on head `418462fbac` (this branch, on `main` `029463ceb6`). - New `guest_webrtc_recursive_critical_section` test: - A new section is free; after two `Enter`s a trylock from another thread gets `EBUSY`, still after one `Leave`, and succeeds after the second. - `CritScope` stores its section and holds it; a nested scope's destructor leaves the outer one held, and the outer destructor frees it. - Four threads each increment a shared counter 20,000 times under `CritScope`, and no increment is lost. - Every null `this` or section throws `std::invalid_argument`. - `ctest -R guest_webrtc --repeat until-fail:3`: all six libwebrtc tests pass 3/3. `ctest -R public_headers`: 65/65 pass. - Negative control: with `NotImplemented_nid_no_patch(__func__)` at the top of each of the six functions, as the `main` stubs do, the test fails 3/3 with `_ZN3rtc24RecursiveCriticalSectionC1Ev_nid_postfix not implemented`. - `check_conventions.py --base upstream/main` passes. An overlap scan of the diffs of all open pull requests that touch libwebrtc found none that changes these exports; they conflict with this one only in appended `CMakeLists.txt` and debt lines. - Not tested: Linux, a title. Only the targets above were built, not the full test suite. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none; the older open libwebrtc PRs can land first, and I'll merge `main` after each - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
MarcZX10 commented 2026-11-01 02:25:15 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-01T02:25:15Z.

Review: APPROVED


Reviewed — looks good

I reviewed head 418462fbac5002d043e60645fa67710f0306d90c; the implementation follows the pinned WebRTC recursive-mutex path, and I found no blocking defect.

What I ran

The PR records base 029463ceb62c97e3a82cfea423f884f158a4f023; the current main tip is 0e9dc7bc4c9755c3ce803f6bbdff9dc9f25d68bb, and the no-build current-main preview was clean. Environment: Debian 12 x86-64, Python 3.11.2, GCC 12.2.0.

python3 tools/pr_precheck.py --repo boykopovar/AnyPS5 --pr 14232
python3 tools/pr_abi_audit.py --repo /marc/AnyPS5 --base 029463ceb62c97e3a82cfea423f884f158a4f023 --head 418462fbac5002d043e60645fa67710f0306d90c --json
gh pr checks 14232

Results

Check Result
Diff and conventions Passed in the precheck and hosted conventions job.
Current-main merge preview Clean against 0e9dc7bc4c9755c3ce803f6bbdff9dc9f25d68bb.
Export/declaration audit Passed with 60 warnings, all for pre-existing libwebrtcUnknown* NID aliases; none refers to the six changed exports.
Test registration The new CTest target and guest_webrtc_recursive_critical_section registration are present in CMakeLists.txt; the quality heuristic's unregistered-test signal is a false positive.
Hosted checks Eligibility, intake, conventions, labels, library portability, and report passed. Windows was pending; Linux and specialized jobs were skipped.
Focused C++ tests The author reports a Windows build, six guest_webrtc tests passing 3/3, and 65/65 public-header tests. I did not build or run CTest locally.
Selected unedited output
All conventions checks passed.

status: passed_with_warnings
symbols: 412
findings: 60
PR #14232: clean against current base; head `418462fbac5002d043e60645fa67710f0306d90c`
windows	pending	0	https://github.com/boykopovar/AnyPS5/actions/runs/41262653622/job/124720403300

Negative control

Assertion Change to code under test Did the new test fail?
The six calls must not remain unimplemented The author reports restoring NotImplemented_nid_no_patch at each function; the test failed 3/3 with the expected not-implemented error. Author-reported; I did not reproduce it.

Sources

Not verified

No local build, CTest, or console/title run. The independent hosted Windows job was still pending at the final check; Linux and specialized product jobs were skipped.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5726027699 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/14232#pullrequestreview-5726027699). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-01T02:25:15Z. **Review:** APPROVED --- # Reviewed — looks good I reviewed head `418462fbac5002d043e60645fa67710f0306d90c`; the implementation follows the pinned WebRTC recursive-mutex path, and I found no blocking defect. ## What I ran The PR records base `029463ceb62c97e3a82cfea423f884f158a4f023`; the current `main` tip is `0e9dc7bc4c9755c3ce803f6bbdff9dc9f25d68bb`, and the no-build current-main preview was clean. Environment: Debian 12 x86-64, Python 3.11.2, GCC 12.2.0. ```sh python3 tools/pr_precheck.py --repo boykopovar/AnyPS5 --pr 14232 python3 tools/pr_abi_audit.py --repo /marc/AnyPS5 --base 029463ceb62c97e3a82cfea423f884f158a4f023 --head 418462fbac5002d043e60645fa67710f0306d90c --json gh pr checks 14232 ``` ## Results | Check | Result | |---|---| | Diff and conventions | Passed in the precheck and hosted conventions job. | | Current-main merge preview | Clean against `0e9dc7bc4c9755c3ce803f6bbdff9dc9f25d68bb`. | | Export/declaration audit | Passed with 60 warnings, all for pre-existing `libwebrtcUnknown*` NID aliases; none refers to the six changed exports. | | Test registration | The new CTest target and `guest_webrtc_recursive_critical_section` registration are present in `CMakeLists.txt`; the quality heuristic's unregistered-test signal is a false positive. | | Hosted checks | Eligibility, intake, conventions, labels, library portability, and report passed. Windows was pending; Linux and specialized jobs were skipped. | | Focused C++ tests | The author reports a Windows build, six `guest_webrtc` tests passing 3/3, and 65/65 public-header tests. I did not build or run CTest locally. | <details><summary>Selected unedited output</summary> ```text All conventions checks passed. ``` ```text status: passed_with_warnings symbols: 412 findings: 60 ``` ```text PR #14232: clean against current base; head `418462fbac5002d043e60645fa67710f0306d90c` ``` ```text windows pending 0 https://github.com/boykopovar/AnyPS5/actions/runs/41262653622/job/124720403300 ``` </details> ## Negative control | Assertion | Change to code under test | Did the new test fail? | |---|---|---| | The six calls must not remain unimplemented | The author reports restoring `NotImplemented_nid_no_patch` at each function; the test failed 3/3 with the expected not-implemented error. | Author-reported; I did not reproduce it. | ## Sources - [WebRTC recursive critical section implementation at commit `8d78f5de6c27b2c793039989ea381f1428fb0100`](https://webrtc.googlesource.com/src/+/8d78f5de6c27b2c793039989ea381f1428fb0100/rtc_base/deprecated/recursive_critical_section.cc) - [PR implementation at exact head](https://github.com/boykopovar/AnyPS5/tree/418462fbac5002d043e60645fa67710f0306d90c/core/libs/prx/libwebrtc) ## Not verified No local build, CTest, or console/title run. The independent hosted Windows job was still pending at the final check; Linux and specialized product jobs were skipped.
CnRJay commented 2026-11-01 20:00:42 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by CnRJay on 2026-11-01T20:00:42Z.

Review: COMMENTED


Withdrawn. The title-ID demand was not a CONTRIBUTING requirement; Unblocks: none is allowed and no title is known for these exports.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5729959552 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/14232#pullrequestreview-5729959552). Originally posted by [CnRJay](https://github.com/CnRJay) on 2026-11-01T20:00:42Z. **Review:** COMMENTED --- Withdrawn. The title-ID demand was not a CONTRIBUTING requirement; `Unblocks: none` is allowed and no title is known for these exports.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!14232
No description provided.