mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
Merge pull request #10955 from lzhfromustc/master
Avoid potential double lock of tsafeSet
This commit is contained in:
commit
03bd10076f
@ -148,6 +148,14 @@ func (ts *tsafeSet) Contains(value string) (exists bool) {
|
|||||||
func (ts *tsafeSet) Equals(other Set) bool {
|
func (ts *tsafeSet) Equals(other Set) bool {
|
||||||
ts.m.RLock()
|
ts.m.RLock()
|
||||||
defer ts.m.RUnlock()
|
defer ts.m.RUnlock()
|
||||||
|
|
||||||
|
// If ts and other represent the same variable, avoid calling
|
||||||
|
// ts.us.Equals(other), to avoid double RLock bug
|
||||||
|
if _other, ok := other.(*tsafeSet); ok {
|
||||||
|
if _other == ts {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
return ts.us.Equals(other)
|
return ts.us.Equals(other)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -173,6 +181,15 @@ func (ts *tsafeSet) Copy() Set {
|
|||||||
func (ts *tsafeSet) Sub(other Set) Set {
|
func (ts *tsafeSet) Sub(other Set) Set {
|
||||||
ts.m.RLock()
|
ts.m.RLock()
|
||||||
defer ts.m.RUnlock()
|
defer ts.m.RUnlock()
|
||||||
|
|
||||||
|
// If ts and other represent the same variable, avoid calling
|
||||||
|
// ts.us.Sub(other), to avoid double RLock bug
|
||||||
|
if _other, ok := other.(*tsafeSet); ok {
|
||||||
|
if _other == ts {
|
||||||
|
usResult := NewUnsafeSet()
|
||||||
|
return &tsafeSet{usResult, sync.RWMutex{}}
|
||||||
|
}
|
||||||
|
}
|
||||||
usResult := ts.us.Sub(other).(*unsafeSet)
|
usResult := ts.us.Sub(other).(*unsafeSet)
|
||||||
return &tsafeSet{usResult, sync.RWMutex{}}
|
return &tsafeSet{usResult, sync.RWMutex{}}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user