Skip to content

Commit

Permalink
Merge pull request #12 from blendle/mutex-2
Browse files Browse the repository at this point in the history
add missing mutex locks
  • Loading branch information
JeanMertz authored Nov 2, 2018
2 parents 87f0bcb + 2ee4606 commit 5d84653
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions core.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,13 @@ func (c *core) With(fields []zap.Field) zapcore.Core {
var lbls *labels
lbls, fields = c.extractLabels(fields)

lbls.mutex.Lock()
lbls.mutex.RLock()
c.permLabels.mutex.Lock()
for k, v := range lbls.store {
c.permLabels.store[k] = v
}
lbls.mutex.Unlock()
c.permLabels.mutex.Unlock()
lbls.mutex.RUnlock()

return &core{c.Core.With(fields), c.permLabels, newLabels()}
}
Expand All @@ -69,11 +71,13 @@ func (c *core) Write(ent zapcore.Entry, fields []zapcore.Field) error {
var lbls *labels
lbls, fields = c.extractLabels(fields)

lbls.mutex.Lock()
lbls.mutex.RLock()
c.tempLabels.mutex.Lock()
for k, v := range lbls.store {
c.tempLabels.store[k] = v
}
lbls.mutex.Unlock()
c.tempLabels.mutex.Unlock()
lbls.mutex.RUnlock()

fields = append(fields, labelsField(c.allLabels()))
fields = c.withSourceLocation(ent, fields)
Expand All @@ -92,13 +96,17 @@ func (c *core) allLabels() *labels {
lbls := newLabels()

lbls.mutex.Lock()
c.permLabels.mutex.RLock()
for k, v := range c.permLabels.store {
lbls.store[k] = v
}
c.permLabels.mutex.RUnlock()

c.tempLabels.mutex.RLock()
for k, v := range c.tempLabels.store {
lbls.store[k] = v
}
c.tempLabels.mutex.RUnlock()
lbls.mutex.Unlock()

return lbls
Expand Down

0 comments on commit 5d84653

Please sign in to comment.