This repository has been archived by the owner on Jun 26, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 26
use RW lock for the File
's lock
#43
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,8 +28,9 @@ type File struct { | |
// of a particular sub-DAG that abstract an upper layer's entity. | ||
node ipld.Node | ||
|
||
// TODO: Rename. | ||
nodelk sync.Mutex | ||
// Lock around the `node` that represents this file, necessary because | ||
// there may be many `FileDescriptor`s operating on this `File`. | ||
nodeLock sync.RWMutex | ||
|
||
RawLeaves bool | ||
} | ||
|
@@ -58,9 +59,9 @@ const ( | |
) | ||
|
||
func (fi *File) Open(flags int, sync bool) (FileDescriptor, error) { | ||
fi.nodelk.Lock() | ||
fi.nodeLock.RLock() | ||
node := fi.node | ||
fi.nodelk.Unlock() | ||
fi.nodeLock.RUnlock() | ||
|
||
// TODO: Move this `switch` logic outside (maybe even | ||
// to another package, this seems like a job of UnixFS), | ||
|
@@ -118,8 +119,8 @@ func (fi *File) Open(flags int, sync bool) (FileDescriptor, error) { | |
// pretty much the same thing as here, we should at least call | ||
// that function and wrap the `ErrNotUnixfs` with an MFS text. | ||
func (fi *File) Size() (int64, error) { | ||
fi.nodelk.Lock() | ||
defer fi.nodelk.Unlock() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Doesn't have to happen in this PR but, ideally, we'd call There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, I have a couple of |
||
fi.nodeLock.RLock() | ||
defer fi.nodeLock.RUnlock() | ||
switch nd := fi.node.(type) { | ||
case *dag.ProtoNode: | ||
fsn, err := ft.FSNodeFromBytes(nd.Data()) | ||
|
@@ -135,10 +136,10 @@ func (fi *File) Size() (int64, error) { | |
} | ||
|
||
// GetNode returns the dag node associated with this file | ||
// TODO: Use this method and do not access the `nodelk` directly anywhere else. | ||
// TODO: Use this method and do not access the `nodeLock` directly anywhere else. | ||
func (fi *File) GetNode() (ipld.Node, error) { | ||
fi.nodelk.Lock() | ||
defer fi.nodelk.Unlock() | ||
fi.nodeLock.RLock() | ||
defer fi.nodeLock.RUnlock() | ||
return fi.node, nil | ||
} | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could also call
GetNode
here.