Skip to content

Commit

Permalink
libflac.go: Fix data race in ptr map
Browse files Browse the repository at this point in the history
  • Loading branch information
Will Newton committed May 20, 2016
1 parent 49d771b commit 8a4f0c0
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions libflac.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,20 +91,20 @@ type decoderPtrMap struct {
ptrs map[uintptr]*Decoder
}

func (m decoderPtrMap) get(d *C.FLAC__StreamDecoder) *Decoder {
func (m *decoderPtrMap) get(d *C.FLAC__StreamDecoder) *Decoder {
ptr := uintptr(unsafe.Pointer(d))
m.RLock()
defer m.RUnlock()
return m.ptrs[ptr]
}

func (m decoderPtrMap) add(d *Decoder) {
func (m *decoderPtrMap) add(d *Decoder) {
m.Lock()
defer m.Unlock()
m.ptrs[uintptr(unsafe.Pointer(d.d))] = d
}

func (m decoderPtrMap) del(d *Decoder) {
func (m *decoderPtrMap) del(d *Decoder) {
m.Lock()
defer m.Unlock()
delete(m.ptrs, uintptr(unsafe.Pointer(d.d)))
Expand Down

0 comments on commit 8a4f0c0

Please sign in to comment.