1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

bitseq: fix races

Signed-off-by: Alexander Morozov <lk4d4@docker.com>
This commit is contained in:
Alexander Morozov 2016-03-29 11:56:39 -07:00
parent 9ca3964233
commit a9c3a9821b
2 changed files with 7 additions and 0 deletions

View file

@ -370,6 +370,8 @@ func (h *Handle) set(ordinal, start, end uint64, any bool, release bool) (uint64
// checks is needed because to cover the case where the number of bits is not a multiple of blockLen // checks is needed because to cover the case where the number of bits is not a multiple of blockLen
func (h *Handle) validateOrdinal(ordinal uint64) error { func (h *Handle) validateOrdinal(ordinal uint64) error {
h.Lock()
defer h.Unlock()
if ordinal >= h.bits { if ordinal >= h.bits {
return fmt.Errorf("bit does not belong to the sequence") return fmt.Errorf("bit does not belong to the sequence")
} }

View file

@ -75,6 +75,10 @@ func (h *Handle) CopyTo(o datastore.KVObject) error {
defer h.Unlock() defer h.Unlock()
dstH := o.(*Handle) dstH := o.(*Handle)
if h == dstH {
return nil
}
dstH.Lock()
dstH.bits = h.bits dstH.bits = h.bits
dstH.unselected = h.unselected dstH.unselected = h.unselected
dstH.head = h.head.getCopy() dstH.head = h.head.getCopy()
@ -83,6 +87,7 @@ func (h *Handle) CopyTo(o datastore.KVObject) error {
dstH.dbIndex = h.dbIndex dstH.dbIndex = h.dbIndex
dstH.dbExists = h.dbExists dstH.dbExists = h.dbExists
dstH.store = h.store dstH.store = h.store
dstH.Unlock()
return nil return nil
} }