diff --git a/README.md b/README.md index 04aca9b..7b7868c 100644 --- a/README.md +++ b/README.md @@ -1062,7 +1062,7 @@ func (slf *TestTcpService) OnRequest (clientid uint64,msg proto.Message){ 提交bug及特性: https://github.com/duanhf2012/origin/issues [因服务器是由个人维护,如果这个项目对您有帮助,您可以点我进行捐赠,感谢!](http://www.cppblog.com/images/cppblog_com/API/21416/r_pay.jpg "Thanks!") - +![](http://www.cppblog.com/images/cppblog_com/API/21416/r_pay.jpg) 特别感谢以下赞助网友: ``` @@ -1071,4 +1071,5 @@ _ 死磕代码 bp-li 阿正 +大头 ``` diff --git a/cluster/cluster.go b/cluster/cluster.go index c2daaa7..797ddea 100644 --- a/cluster/cluster.go +++ b/cluster/cluster.go @@ -477,3 +477,14 @@ func (cls *Cluster) GetGlobalCfg() interface{} { return cls.globalCfg } +func (cls *Cluster) GetNodeInfo(nodeId int) (NodeInfo,bool) { + cls.locker.RLock() + defer cls.locker.RUnlock() + + nodeInfo,ok:= cls.mapRpc[nodeId] + if ok == false || nodeInfo == nil { + return NodeInfo{},false + } + + return nodeInfo.nodeInfo,true +} diff --git a/concurrent/concurrent.go b/concurrent/concurrent.go index 6b97059..702c020 100644 --- a/concurrent/concurrent.go +++ b/concurrent/concurrent.go @@ -5,6 +5,7 @@ import ( "runtime" "github.com/duanhf2012/origin/log" + "sync/atomic" ) const defaultMaxTaskChannelNum = 1000000 @@ -21,6 +22,7 @@ type Concurrent struct { tasks chan task 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) { + if atomic.AddInt32(&c.open,1) > 1 { + panic("repeated calls to OpenConcurrent are not allowed!") + } + c.tasks = make(chan task, maxTaskChannelNum) c.cbChannel = make(chan func(error), maxTaskChannelNum)