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

refactor: Shared to use internal mutability #197

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

akaladarshi
Copy link

Fixes: #170

This PR changes:

  • Now the Shared struct internally handles the mutex.
  • Shared struct now has inner: Arc<Mutex<SharedInner>>

Copy link
Contributor

@elenaf9 elenaf9 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your PR @akaladarshi!

Some comments.

yamux/src/connection.rs Outdated Show resolved Hide resolved
yamux/src/connection.rs Show resolved Hide resolved
yamux/src/connection/stream.rs Outdated Show resolved Hide resolved
yamux/src/connection/stream.rs Outdated Show resolved Hide resolved
yamux/src/connection/stream.rs Outdated Show resolved Hide resolved
yamux/src/connection/stream.rs Outdated Show resolved Hide resolved
yamux/src/connection/stream.rs Outdated Show resolved Hide resolved
@akaladarshi akaladarshi force-pushed the akaladarshi/refactor-shared branch from aabc8a2 to f7ad5e9 Compare January 31, 2025 06:41
@akaladarshi
Copy link
Author

@elenaf9 Thanks for the review 🙏.

I have removed the lock and directly using with_mut, just one small change I have refactored Stream write_zero_err fn to be a static as it was just for creating error and it was causing few issues with borrow checkers in poll_write.

@akaladarshi akaladarshi requested a review from elenaf9 February 10, 2025 09:47
Copy link
Contributor

@elenaf9 elenaf9 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One comment, rest LGTM. Thank you for the follow-ups @akaladarshi!

cc @jxs: think this change is an improvement because it hides the mutex-locking logic behind the Shared type and prevents deadlocks that would otherwise been possible when trying to locking the Mutex re-entrantly. Are you okay with merging?

yamux/src/connection/stream.rs Outdated Show resolved Hide resolved
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.

Refactor stream::Shared to use internal mutability
2 participants