forked from mirror/ants
update
This commit is contained in:
parent
3a8cc09373
commit
a59f51fefd
4
ants.go
4
ants.go
|
@ -1,8 +1,6 @@
|
|||
package ants
|
||||
|
||||
import "math"
|
||||
|
||||
const DEFAULT_POOL_SIZE = math.MaxInt32
|
||||
const DEFAULT_POOL_SIZE = 10000
|
||||
|
||||
var defaultPool = NewPool(DEFAULT_POOL_SIZE)
|
||||
|
||||
|
|
4
pool.go
4
pool.go
|
@ -105,18 +105,18 @@ func (p *Pool) newWorker() *Worker {
|
|||
exit: make(chan sig),
|
||||
}
|
||||
worker.run()
|
||||
atomic.AddInt32(&p.running, 1)
|
||||
return worker
|
||||
}
|
||||
|
||||
func (p *Pool) getWorker() *Worker {
|
||||
defer atomic.AddInt32(&p.running, 1)
|
||||
if w := p.workers.pop(); w != nil {
|
||||
return w.(*Worker)
|
||||
}
|
||||
return p.newWorker()
|
||||
}
|
||||
|
||||
func (p *Pool) PutWorker(worker *Worker) {
|
||||
func (p *Pool) putWorker(worker *Worker) {
|
||||
p.workers.push(worker)
|
||||
if p.reachLimit() {
|
||||
p.freeSignal <- sig{}
|
||||
|
|
|
@ -18,7 +18,7 @@ func (w *Worker) run() {
|
|||
select {
|
||||
case f := <-w.task:
|
||||
f()
|
||||
w.pool.workers.push(w)
|
||||
w.pool.putWorker(w)
|
||||
w.pool.wg.Done()
|
||||
case <-w.exit:
|
||||
atomic.AddInt32(&w.pool.running, -1)
|
||||
|
@ -58,7 +58,7 @@ func (q *ConcurrentQueue) push(v interface{}) {
|
|||
func (q *ConcurrentQueue) pop() interface{} {
|
||||
defer q.m.Unlock()
|
||||
q.m.Lock()
|
||||
if elem := q.queue.Back(); elem != nil{
|
||||
if elem := q.queue.Back(); elem != nil {
|
||||
return q.queue.Remove(elem)
|
||||
}
|
||||
return nil
|
||||
|
|
Loading…
Reference in New Issue