浏览代码

put unlock after lock

Bas van Kervel 10 年之前
父节点
当前提交
652eea71fe
共有 1 个文件被更改,包括 3 次插入5 次删除
  1. 3 5
      miner/agent.go

+ 3 - 5
miner/agent.go

@@ -61,10 +61,10 @@ func (self *CpuAgent) Stop() {
 }
 
 func (self *CpuAgent) Start() {
-	defer self.mu.Unlock()
 	self.mu.Lock()
-
-	if atomic.LoadInt32(&self.isMining) == 1 {
+	defer self.mu.Unlock()
+	
+	if !atomic.CompareAndSwapInt32(&self.isMining, 0, 1) {
 		return // agent already started
 	}
 
@@ -74,8 +74,6 @@ func (self *CpuAgent) Start() {
 	self.workCh = make(chan *Work, 1)
 
 	go self.update()
-
-	atomic.StoreInt32(&self.isMining, 1)
 }
 
 func (self *CpuAgent) update() {