mirror of https://github.com/panjf2000/ants.git
optimization for structure
This commit is contained in:
parent
042109890a
commit
59ad1fa56c
21
pool.go
21
pool.go
|
@ -129,16 +129,6 @@ func (p *Pool) Running() int {
|
||||||
return int(atomic.LoadInt32(&p.running))
|
return int(atomic.LoadInt32(&p.running))
|
||||||
}
|
}
|
||||||
|
|
||||||
// incrRunning increases the number of the currently running goroutines
|
|
||||||
func (p *Pool) incrRunning() {
|
|
||||||
atomic.AddInt32(&p.running, 1)
|
|
||||||
}
|
|
||||||
|
|
||||||
// decrRunning decreases the number of the currently running goroutines
|
|
||||||
func (p *Pool) decrRunning() {
|
|
||||||
atomic.AddInt32(&p.running, -1)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Free returns the available goroutines to work
|
// Free returns the available goroutines to work
|
||||||
func (p *Pool) Free() int {
|
func (p *Pool) Free() int {
|
||||||
return int(atomic.LoadInt32(&p.capacity) - atomic.LoadInt32(&p.running))
|
return int(atomic.LoadInt32(&p.capacity) - atomic.LoadInt32(&p.running))
|
||||||
|
@ -182,6 +172,17 @@ func (p *Pool) Release() error {
|
||||||
|
|
||||||
//-------------------------------------------------------------------------
|
//-------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// incrRunning increases the number of the currently running goroutines
|
||||||
|
func (p *Pool) incrRunning() {
|
||||||
|
atomic.AddInt32(&p.running, 1)
|
||||||
|
}
|
||||||
|
|
||||||
|
// decrRunning decreases the number of the currently running goroutines
|
||||||
|
func (p *Pool) decrRunning() {
|
||||||
|
atomic.AddInt32(&p.running, -1)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// getWorker returns a available worker to run the tasks.
|
// getWorker returns a available worker to run the tasks.
|
||||||
func (p *Pool) getWorker() *Worker {
|
func (p *Pool) getWorker() *Worker {
|
||||||
var w *Worker
|
var w *Worker
|
||||||
|
|
21
pool_func.go
21
pool_func.go
|
@ -134,16 +134,6 @@ func (p *PoolWithFunc) Running() int {
|
||||||
return int(atomic.LoadInt32(&p.running))
|
return int(atomic.LoadInt32(&p.running))
|
||||||
}
|
}
|
||||||
|
|
||||||
// incrRunning increases the number of the currently running goroutines
|
|
||||||
func (p *PoolWithFunc) incrRunning() {
|
|
||||||
atomic.AddInt32(&p.running, 1)
|
|
||||||
}
|
|
||||||
|
|
||||||
// decrRunning decreases the number of the currently running goroutines
|
|
||||||
func (p *PoolWithFunc) decrRunning() {
|
|
||||||
atomic.AddInt32(&p.running, -1)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Free returns the available goroutines to work
|
// Free returns the available goroutines to work
|
||||||
func (p *PoolWithFunc) Free() int {
|
func (p *PoolWithFunc) Free() int {
|
||||||
return int(atomic.LoadInt32(&p.capacity) - atomic.LoadInt32(&p.running))
|
return int(atomic.LoadInt32(&p.capacity) - atomic.LoadInt32(&p.running))
|
||||||
|
@ -187,6 +177,17 @@ func (p *PoolWithFunc) Release() error {
|
||||||
|
|
||||||
//-------------------------------------------------------------------------
|
//-------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// incrRunning increases the number of the currently running goroutines
|
||||||
|
func (p *PoolWithFunc) incrRunning() {
|
||||||
|
atomic.AddInt32(&p.running, 1)
|
||||||
|
}
|
||||||
|
|
||||||
|
// decrRunning decreases the number of the currently running goroutines
|
||||||
|
func (p *PoolWithFunc) decrRunning() {
|
||||||
|
atomic.AddInt32(&p.running, -1)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// getWorker returns a available worker to run the tasks.
|
// getWorker returns a available worker to run the tasks.
|
||||||
func (p *PoolWithFunc) getWorker() *WorkerWithFunc {
|
func (p *PoolWithFunc) getWorker() *WorkerWithFunc {
|
||||||
var w *WorkerWithFunc
|
var w *WorkerWithFunc
|
||||||
|
|
Loading…
Reference in New Issue