|
@@ -1,19 +1,19 @@
|
|
|
package wkrp
|
|
package wkrp
|
|
|
|
|
|
|
|
-import "sync"
|
|
|
|
|
|
|
+import (
|
|
|
|
|
+ "git.wanbits.io/joe/kettle/utl"
|
|
|
|
|
+ "sync"
|
|
|
|
|
+)
|
|
|
|
|
|
|
|
const (
|
|
const (
|
|
|
def_POOL_SIZE = 64
|
|
def_POOL_SIZE = 64
|
|
|
def_ENQCHAN_SIZE = 64
|
|
def_ENQCHAN_SIZE = 64
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
-type TJobChan chan *Job
|
|
|
|
|
-type TJobPool chan TJobChan
|
|
|
|
|
-
|
|
|
|
|
type Dispacher struct {
|
|
type Dispacher struct {
|
|
|
- enqchan TJobChan
|
|
|
|
|
|
|
+ enqchan utl.TJobChan
|
|
|
enqchanSz int
|
|
enqchanSz int
|
|
|
- pool TJobPool
|
|
|
|
|
|
|
+ pool utl.TJobPool
|
|
|
poolSz int
|
|
poolSz int
|
|
|
workers map[int]*Worker
|
|
workers map[int]*Worker
|
|
|
quit chan struct{}
|
|
quit chan struct{}
|
|
@@ -31,8 +31,8 @@ func NewDispacher(pool_size int, cache_size int) *Dispacher {
|
|
|
p := &Dispacher{
|
|
p := &Dispacher{
|
|
|
poolSz: pool_size,
|
|
poolSz: pool_size,
|
|
|
enqchanSz: cache_size,
|
|
enqchanSz: cache_size,
|
|
|
- enqchan: make(TJobChan, cache_size),
|
|
|
|
|
- pool: make(TJobPool, pool_size),
|
|
|
|
|
|
|
+ enqchan: make(utl.TJobChan, cache_size),
|
|
|
|
|
+ pool: make(utl.TJobPool, pool_size),
|
|
|
workers: make(map[int]*Worker),
|
|
workers: make(map[int]*Worker),
|
|
|
quit: make(chan struct{}),
|
|
quit: make(chan struct{}),
|
|
|
wg: sync.WaitGroup{},
|
|
wg: sync.WaitGroup{},
|
|
@@ -58,7 +58,7 @@ func (self *Dispacher) Stop() {
|
|
|
}()
|
|
}()
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-func (self *Dispacher) Do(job *Job) {
|
|
|
|
|
|
|
+func (self *Dispacher) Do(job *utl.Job) {
|
|
|
go func() {
|
|
go func() {
|
|
|
select {
|
|
select {
|
|
|
case <-self.quit:
|
|
case <-self.quit:
|