Skip to content

Commit

Permalink
bitseq: fix races
Browse files Browse the repository at this point in the history
Signed-off-by: Alexander Morozov <lk4d4@docker.com>
  • Loading branch information
LK4D4 committed Mar 29, 2016
1 parent a05a474 commit fe222b2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
2 changes: 2 additions & 0 deletions bitseq/sequence.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
func (h *Handle) validateOrdinal(ordinal uint64) error {
h.Lock()
defer h.Unlock()
if ordinal >= h.bits {
return fmt.Errorf("bit does not belong to the sequence")
}
Expand Down
5 changes: 5 additions & 0 deletions bitseq/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ func (h *Handle) CopyTo(o datastore.KVObject) error {
defer h.Unlock()

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

return nil
}
Expand Down

0 comments on commit fe222b2

Please sign in to comment.