-
Notifications
You must be signed in to change notification settings - Fork 19
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
Fix deadlock due to incorrect mutex #91
Fix deadlock due to incorrect mutex #91
Conversation
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.
Thanks! Some questions on the design.
Co-authored-by: Runchao Han <[email protected]>
This reverts commit 4e0f9f5.
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.
LGTM except for some minor issues!
types/btccache.go
Outdated
if b.size() >= b.maxEntries { | ||
b.blocks = b.blocks[1:] | ||
} | ||
|
||
b.blocks = append(b.blocks, ib) | ||
return nil |
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.
if b.size() >= b.maxEntries { | |
b.blocks = b.blocks[1:] | |
} | |
b.blocks = append(b.blocks, ib) | |
return nil | |
return b.add(ib) |
} | ||
|
||
// Reverse reverses the order of blocks in cache in place. Thread-safe. | ||
func (b *BTCCache) Reverse() error { | ||
b.Lock() | ||
defer b.Unlock() | ||
|
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.
Ditto, you can just do
return b.reverse()
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.
fixed
types/btccache.go
Outdated
return nil | ||
} | ||
|
||
// Lock free version of Add |
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.
Lock-free has its own meaning. So perhaps just say "thread-unsafe" here.
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.
fixed
types/btccache.go
Outdated
func (b *BTCCache) Size() uint64 { | ||
b.RLock() | ||
defer b.RUnlock() | ||
|
||
return uint64(len(b.blocks)) | ||
} | ||
|
||
func (b *BTCCache) reverse() error { | ||
// lock free version of Size |
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.
ditto
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.
fixed
types/btccache.go
Outdated
@@ -94,6 +112,15 @@ func (b *BTCCache) reverse() error { | |||
return nil | |||
} | |||
|
|||
// lock free version of reverse |
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.
ditto
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.
fixed
No description provided.