MCPcopy
hub / github.com/valyala/fasthttp / getCh

Method getCh

workerpool.go:171–202  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

169}()
170
171func (wp *workerPool) getCh() *workerChan {
172 var ch *workerChan
173 createWorker := false
174
175 wp.lock.Lock()
176 ready := wp.ready
177 n := len(ready) - 1
178 if n < 0 {
179 if wp.workersCount < wp.MaxWorkersCount {
180 createWorker = true
181 wp.workersCount++
182 }
183 } else {
184 ch = ready[n]
185 ready[n] = nil
186 wp.ready = ready[:n]
187 }
188 wp.lock.Unlock()
189
190 if ch == nil {
191 if !createWorker {
192 return nil
193 }
194 vch := wp.workerChanPool.Get()
195 ch = vch.(*workerChan)
196 go func() {
197 wp.workerFunc(ch)
198 wp.workerChanPool.Put(vch)
199 }()
200 }
201 return ch
202}
203
204func (wp *workerPool) release(ch *workerChan) bool {
205 ch.lastUseTime = time.Now()

Callers 1

ServeMethod · 0.95

Calls 4

workerFuncMethod · 0.95
LockMethod · 0.65
UnlockMethod · 0.65
GetMethod · 0.65

Tested by

no test coverage detected