Skip to content

refactor: Shared to use internal mutability#197

Open
akaladarshi wants to merge 4 commits into
libp2p:masterfrom
akaladarshi:akaladarshi/refactor-shared
Open

refactor: Shared to use internal mutability#197
akaladarshi wants to merge 4 commits into
libp2p:masterfrom
akaladarshi:akaladarshi/refactor-shared

Conversation

@akaladarshi

Copy link
Copy Markdown

Fixes: #170

This PR changes:

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

@elenaf9 elenaf9 left a comment

Copy link
Copy Markdown
Member

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.

Comment thread yamux/src/connection.rs Outdated
Comment thread yamux/src/connection.rs
Comment thread yamux/src/connection/stream.rs Outdated
Comment thread yamux/src/connection/stream.rs Outdated
Comment thread yamux/src/connection/stream.rs Outdated
Comment thread yamux/src/connection/stream.rs Outdated
Comment thread yamux/src/connection/stream.rs Outdated
@akaladarshi akaladarshi force-pushed the akaladarshi/refactor-shared branch from aabc8a2 to f7ad5e9 Compare January 31, 2025 06:41
@akaladarshi

Copy link
Copy Markdown
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

@elenaf9 elenaf9 left a comment

Copy link
Copy Markdown
Member

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?

Comment thread yamux/src/connection/stream.rs
@caniko

caniko commented Feb 23, 2026

Copy link
Copy Markdown

Will this be merged? @elenaf9 @akaladarshi ?

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

3 participants