Merge branch 'develop'

This commit is contained in:
andy pan 2018-05-21 10:41:59 +08:00
commit 402b7ce123
2 changed files with 9 additions and 8 deletions

13
pool.go
View File

@ -36,27 +36,28 @@ type f func()
// Pool accept the tasks from client,it will limit the total // Pool accept the tasks from client,it will limit the total
// of goroutines to a given number by recycling goroutines. // of goroutines to a given number by recycling goroutines.
type Pool struct { type Pool struct {
// Capacity of the pool. // capacity of the pool.
capacity int32 capacity int32
// The number of the currently running goroutines. // running is the number of the currently running goroutines.
running int32 running int32
// Signal is used to notice pool there are available // signal is used to notice pool there are available
// workers which can be sent to work. // workers which can be sent to work.
freeSignal chan sig freeSignal chan sig
// A slice that store the available workers. // workers is a slice that store the available workers.
workers []*Worker workers []*Worker
// workerPool is a pool that saves a set of temporary objects.
workerPool sync.Pool workerPool sync.Pool
// It is used to notice the pool to closed itself. // release is used to notice the pool to closed itself.
release chan sig release chan sig
lock sync.Mutex lock sync.Mutex
// It is used to confirm whether this pool has been closed. // closed is used to confirm whether this pool has been closed.
closed int32 closed int32
} }

View File

@ -30,10 +30,10 @@ import (
// it will start a goroutine that accept tasks and // it will start a goroutine that accept tasks and
// perform function calls. // perform function calls.
type Worker struct { type Worker struct {
// A pool who owns this worker. // pool who owns this worker.
pool *Pool pool *Pool
// The job should be done. // task is a job should be done.
task chan f task chan f
} }