Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IDM: Implement lock-free smart pointers #16403

Merged
merged 1 commit into from
Dec 22, 2024
Merged

Conversation

elad335
Copy link
Contributor

@elad335 elad335 commented Dec 13, 2024

Replaces std::shared_pointer with stx::atomic_ptr and stx::shared_ptr.

Notes to programmers:

  • This pr kills the use of dynamic_cast, std::dynamic_pointer_cast and std::weak_ptr on IDM objects, possible replacement is to save the object ID on the base object, then use idm::check/get_unlocked to the destination type via the saved ID which may be null. Null pointer check is how you can tell type mismatch (as dynamic cast) or object destruction (as weak_ptr locking).
  • Double-inheritance on IDM objects should be used with care, stx::shared_ptr does not support constant-evaluated pointer offsetting to parent/child type.
  • idm::check/get_unlocked can now be used anywhere.
  • idm::find_unlocked has been removed, idm::withdraw and idm::remove_verify now have unlocked overloads with std::true_type.

Misc fixes:

  • Fixes some segfaults with RPCN with interaction with IDM.
  • Fix deadlocks in access violation handler due locking recursion.
  • Fixes race condition in process exit-spawn on memory containers read.
  • Fix bug that theoretically can prevent RPCS3 from booting - fix id_manager::typeinfo comparison to compare members instead of memcmp which can fail spuriously on padding bytes.
  • Ensure all IDM inherited types of base, either has id_base or id_type defined locally, this allows to make getters such as idm::get_unlocked<lv2_socket, lv2_socket_raw>() which were broken before. (requires save-states invalidation)
  • Removes broken operator[] overload of stx::shared_ptr and stx::single_ptr for non-array types.

@elad335 elad335 added Refactoring Refactors or simplifies existing code Performance Performance related, not directly an optimization. labels Dec 13, 2024
@elad335 elad335 force-pushed the events branch 2 times, most recently from 497879c to db65615 Compare December 15, 2024 05:19
@elad335 elad335 force-pushed the events branch 25 times, most recently from c377cf8 to da87016 Compare December 22, 2024 14:23
@elad335 elad335 force-pushed the events branch 5 times, most recently from 01850b5 to 4cb62f0 Compare December 22, 2024 14:54
@elad335 elad335 marked this pull request as ready for review December 22, 2024 14:58
@elad335 elad335 added the Bugfix label Dec 22, 2024
@elad335 elad335 force-pushed the events branch 6 times, most recently from 493c58e to 8a6fe0d Compare December 22, 2024 16:45
@elad335 elad335 merged commit 575a245 into RPCS3:master Dec 22, 2024
8 checks passed
@Darkhost1999
Copy link
Contributor

Darkhost1999 commented Dec 22, 2024

Do you need testers for performance now?
Or should performance differences be subtle? With 124 files changed we're testing for any change from the master branch or what should we look for?
I see it merged as I was typing.

Xcedf pushed a commit to Xcedf/rpcs3 that referenced this pull request Jan 19, 2025
Replaces `std::shared_pointer` with `stx::atomic_ptr` and `stx::shared_ptr`.

Notes to programmers:

* This pr kills the use of `dynamic_cast`, `std::dynamic_pointer_cast` and `std::weak_ptr` on IDM objects, possible replacement is to save the object ID on the base object, then use idm::check/get_unlocked to the destination type via the saved ID which may be null. Null pointer check is how you can tell type mismatch (as dynamic cast) or object destruction (as weak_ptr locking).
* Double-inheritance on IDM objects should be used with care, `stx::shared_ptr` does not support constant-evaluated pointer offsetting to parent/child type.
* `idm::check/get_unlocked` can now be used anywhere.

Misc fixes:
* Fixes some segfaults with RPCN with interaction with IDM.
* Fix deadlocks in access violation handler due locking recursion.
* Fixes race condition in process exit-spawn on memory containers read.
* Fix bug that theoretically can prevent RPCS3 from booting - fix `id_manager::typeinfo` comparison to compare members instead of `memcmp` which can fail spuriously on padding bytes.
* Ensure all IDM inherited types of base, either has `id_base` or `id_type` defined locally, this allows to make getters such as `idm::get_unlocked<lv2_socket, lv2_socket_raw>()` which were broken before. (requires save-states invalidation)
* Removes broken operator[] overload of `stx::shared_ptr` and `stx::single_ptr` for non-array types.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bugfix Performance Performance related, not directly an optimization. Refactoring Refactors or simplifies existing code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants