optimization for structure

This commit is contained in:
andy pan 2018-07-31 11:05:05 +08:00
parent 042109890a
commit 59ad1fa56c
2 changed files with 22 additions and 20 deletions

21
pool.go
View File

@ -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

View File

@ -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