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

Thread local refactor #11

Merged
merged 10 commits into from
Apr 9, 2024
Merged

Thread local refactor #11

merged 10 commits into from
Apr 9, 2024

Conversation

pedromfedricci
Copy link
Owner

@pedromfedricci pedromfedricci commented Apr 7, 2024

This PR removes previous thread_local's Mutex and MutexGuard types. Thread local nodes now need to be explicitly declared via thread_local_node! macro, instead of the previous approach of transparently defining them. The problem with transparent thread local nodes design is that locking APIs are easy to use incorrectly and cause panics (for the safe APIs) and undefined behiavior (for the unchecked variants). The new design requires explicit definition of static thread local node keys, and locking APIs require taking references to those static node keys, which makes a lot easier for callers to track them on source code and evaluate if they are already referenced (borrowed) within a closure scope. Operating over thread local nodes for locking is now part of the raw::Mutex's API, instead of defining a separated type just for them. Thread local nodes are borrowed at runtime, and their borrows live up to the end o the closure scope operating over them. See thread_local_node! macro, LocalMutexNode type and ..._lock_with_local_... functions documentation for more information.

Breaking changes:

  • Removed thread_local module.
  • Removed thread_local's Mutex and MutexGuard and their aliases.

Added:

  • New thread_local_node! macro.
  • New LocalMutexNode type.
  • New try_lock_with_local function for raw::Mutex.
  • New lock_with_local function for raw::Mutex.
  • New try_lock_with_local_unchecked function for raw::Mutex.
  • New lock_with_local_unchecked function for raw::Mutex.

@codecov-commenter
Copy link

codecov-commenter commented Apr 7, 2024

Codecov Report

Attention: Patch coverage is 95.00000% with 1 lines in your changes are missing coverage. Please review.

Project coverage is 97.95%. Comparing base (ecea470) to head (e45840b).

Files Patch % Lines
src/thread_local.rs 94.44% 1 Missing ⚠️

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #11      +/-   ##
==========================================
+ Coverage   96.99%   97.95%   +0.96%     
==========================================
  Files           5        5              
  Lines         233      196      -37     
==========================================
- Hits          226      192      -34     
+ Misses          7        4       -3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@pedromfedricci pedromfedricci marked this pull request as ready for review April 9, 2024 03:57
@pedromfedricci pedromfedricci merged commit 563e5f9 into main Apr 9, 2024
9 checks passed
@pedromfedricci pedromfedricci deleted the thread-local-refactor branch April 9, 2024 20:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants