From 59ad1fa56cee30b66881884cd74fadb8b682b6bf Mon Sep 17 00:00:00 2001 From: andy pan Date: Tue, 31 Jul 2018 11:05:05 +0800 Subject: [PATCH] optimization for structure --- pool.go | 21 +++++++++++---------- pool_func.go | 21 +++++++++++---------- 2 files changed, 22 insertions(+), 20 deletions(-) diff --git a/pool.go b/pool.go index ad78fe0..03f88c0 100644 --- a/pool.go +++ b/pool.go @@ -129,16 +129,6 @@ func (p *Pool) Running() int { 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 func (p *Pool) Free() int { 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. func (p *Pool) getWorker() *Worker { var w *Worker diff --git a/pool_func.go b/pool_func.go index c672bd2..4b59bc1 100644 --- a/pool_func.go +++ b/pool_func.go @@ -134,16 +134,6 @@ func (p *PoolWithFunc) Running() int { 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 func (p *PoolWithFunc) Free() int { 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. func (p *PoolWithFunc) getWorker() *WorkerWithFunc { var w *WorkerWithFunc