MCPcopy Create free account
hub / github.com/IBM/sarama / getZstdEncoderChannel

Function getZstdEncoderChannel

zstd.go:33–48  ·  view source on GitHub ↗

getZstdEncoderChannel returns the buffered channel that retains idle zstd encoders for the given params. The slow path holds a single global mutex and re-checks the sync.Map under the lock so that a stampede of goroutines arriving for the same not-yet-seen ZstdEncoderParams cannot create multiple co

(params ZstdEncoderParams)

Source from the content-addressed store, hash-verified

31// the previous size-1 cap can no longer force concurrent callers to
32// allocate a fresh encoder per batch.
33func getZstdEncoderChannel(params ZstdEncoderParams) chan *zstd.Encoder {
34 if c, ok := zstdAvailableEncoders.Load(params); ok {
35 return c.(chan *zstd.Encoder)
36 }
37
38 zstdEncoderInitMu.Lock()
39 defer zstdEncoderInitMu.Unlock()
40
41 if c, ok := zstdAvailableEncoders.Load(params); ok {
42 return c.(chan *zstd.Encoder)
43 }
44
45 ch := make(chan *zstd.Encoder, max(runtime.GOMAXPROCS(0), 1))
46 zstdAvailableEncoders.Store(params, ch)
47 return ch
48}
49
50func newZstdEncoder(params ZstdEncoderParams) (*zstd.Encoder, error) {
51 encoderLevel := zstd.SpeedDefault

Callers 2

getZstdEncoderFunction · 0.85
releaseEncoderFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected