mirror of
https://github.com/duanhf2012/origin.git
synced 2026-02-03 22:45:13 +08:00
优化concurrent,禁止重复打开
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
|||||||
"runtime"
|
"runtime"
|
||||||
|
|
||||||
"github.com/duanhf2012/origin/log"
|
"github.com/duanhf2012/origin/log"
|
||||||
|
"sync/atomic"
|
||||||
)
|
)
|
||||||
|
|
||||||
const defaultMaxTaskChannelNum = 1000000
|
const defaultMaxTaskChannelNum = 1000000
|
||||||
@@ -21,6 +22,7 @@ type Concurrent struct {
|
|||||||
|
|
||||||
tasks chan task
|
tasks chan task
|
||||||
cbChannel chan func(error)
|
cbChannel chan func(error)
|
||||||
|
open int32
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -33,6 +35,10 @@ func (c *Concurrent) OpenConcurrentByNumCPU(cpuNumMul float32) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *Concurrent) OpenConcurrent(minGoroutineNum int32, maxGoroutineNum int32, maxTaskChannelNum int) {
|
func (c *Concurrent) OpenConcurrent(minGoroutineNum int32, maxGoroutineNum int32, maxTaskChannelNum int) {
|
||||||
|
if atomic.AddInt32(&c.open,1) > 1 {
|
||||||
|
panic("repeated calls to OpenConcurrent are not allowed!")
|
||||||
|
}
|
||||||
|
|
||||||
c.tasks = make(chan task, maxTaskChannelNum)
|
c.tasks = make(chan task, maxTaskChannelNum)
|
||||||
c.cbChannel = make(chan func(error), maxTaskChannelNum)
|
c.cbChannel = make(chan func(error), maxTaskChannelNum)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user