Skip to content

Commit

Permalink
feat: add mx on writing in p
Browse files Browse the repository at this point in the history
  • Loading branch information
Denis Evdokimov committed Jan 16, 2025
1 parent a5374f0 commit 6c15230
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions internal/topic/topicwriterinternal/encoders.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ func newEncoderPool() *encoderPool {

type EncoderMap struct {
m map[rawtopiccommon.Codec]PublicCreateEncoderFunc
p map[rawtopiccommon.Codec]*encoderPool

mx sync.Mutex
p map[rawtopiccommon.Codec]*encoderPool
}

func NewEncoderMap() *EncoderMap {
Expand All @@ -57,7 +59,8 @@ func NewEncoderMap() *EncoderMap {
return gzip.NewWriter(writer), nil
},
},
p: make(map[rawtopiccommon.Codec]*encoderPool),
mx: sync.Mutex{},
p: make(map[rawtopiccommon.Codec]*encoderPool),
}
}

Expand All @@ -82,7 +85,9 @@ func (e *EncoderMap) Encode(codec rawtopiccommon.Codec, target io.Writer, data [
resetableEnc, ok := enc.(PublicResetableWriter)
if ok {
if _, ok := e.p[codec]; !ok {
e.mx.Lock()
e.p[codec] = newEncoderPool()
e.mx.Unlock()
}

e.p[codec].Put(resetableEnc)
Expand Down

0 comments on commit 6c15230

Please sign in to comment.