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: fixed the unnecessary mutex lock operation #1616

Merged
merged 1 commit into from
Sep 12, 2024

Conversation

Chasing1020
Copy link
Contributor

Relevant Issue (if applicable)

If there are Issues related to this PullRequest, please list it.

Details

This PR is a preliminary proposal, and I welcome friendly discussions on this issue.

Due to Rc is neither Send or Sync, it cannot be sent between threads safely. Rust cannot send an Rc to another thread, then you have to construct the value on the thread that will use it, or send the value to that thread before wrapping it in an Rc. So rustc's mechanism will not exploit the Mutex's protection.

IMHO, for the most part, we should use Rc<RefCell<T>> for single thread or Arc<Mutex<T>> for exclusive access (until compiler complain about our code need Send or Sync).

Thank you for your time!

Types of changes

What types of changes does your PullRequest introduce? Put an x in all the boxes that apply:

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation Update (if none of the other choices apply)

Checklist

Go over all the following points, and put an x in all the boxes that apply.

  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.

@Chasing1020 Chasing1020 requested a review from a team as a code owner September 11, 2024 14:03
@Chasing1020 Chasing1020 requested review from bergwolf, changweige and adamqqqplay and removed request for a team September 11, 2024 14:03
Copy link

codecov bot commented Sep 11, 2024

Codecov Report

Attention: Patch coverage is 78.12500% with 14 lines in your changes missing coverage. Please review.

Project coverage is 61.28%. Comparing base (d89410f) to head (85ae482).
Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
builder/src/directory.rs 0.00% 3 Missing ⚠️
builder/src/chunkdict_generator.rs 0.00% 2 Missing ⚠️
builder/src/core/prefetch.rs 85.71% 2 Missing ⚠️
builder/src/compact.rs 66.66% 1 Missing ⚠️
builder/src/core/blob.rs 0.00% 1 Missing ⚠️
builder/src/core/layout.rs 66.66% 0 Missing and 1 partial ⚠️
builder/src/core/v6.rs 75.00% 0 Missing and 1 partial ⚠️
src/bin/nydus-image/deduplicate.rs 0.00% 1 Missing ⚠️
src/bin/nydus-image/stat.rs 0.00% 1 Missing ⚠️
src/bin/nydus-image/validator.rs 0.00% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1616      +/-   ##
==========================================
- Coverage   61.29%   61.28%   -0.01%     
==========================================
  Files         146      146              
  Lines       48143    48143              
  Branches    46110    46110              
==========================================
- Hits        29510    29506       -4     
- Misses      17074    17075       +1     
- Partials     1559     1562       +3     
Files with missing lines Coverage Δ
builder/src/core/bootstrap.rs 77.33% <100.00%> (ø)
builder/src/core/tree.rs 83.86% <100.00%> (-0.29%) ⬇️
builder/src/core/v5.rs 76.64% <100.00%> (ø)
builder/src/merge.rs 70.79% <100.00%> (ø)
builder/src/stargz.rs 74.67% <100.00%> (ø)
builder/src/tarball.rs 62.84% <100.00%> (ø)
builder/src/compact.rs 80.32% <66.66%> (ø)
builder/src/core/blob.rs 41.33% <0.00%> (ø)
builder/src/core/layout.rs 92.10% <66.66%> (ø)
builder/src/core/v6.rs 75.51% <75.00%> (ø)
... and 6 more

... and 1 file with indirect coverage changes

Copy link
Collaborator

@imeoer imeoer left a comment

Choose a reason for hiding this comment

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

Thanks for the changes, let's add SOB for the commit by following https://github.com/dragonflyoss/nydus/pull/1616/checks?check_run_id=29996970070

Signed-off-by: Jiancong Zhu <Chasing1020@gmail.com>
@imeoer imeoer merged commit 6106fbc into dragonflyoss:master Sep 12, 2024
25 checks passed
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