瀏覽代碼

use atomic to gate framer release so we dont copy the sync cond mutex

Chris Bannister 9 年之前
父節點
當前提交
26f7e6e96d
共有 1 個文件被更改,包括 4 次插入3 次删除
  1. 4 3
      session.go

+ 4 - 3
session.go

@@ -14,6 +14,7 @@ import (
 	"strconv"
 	"strings"
 	"sync"
+	"sync/atomic"
 	"time"
 	"unicode"
 
@@ -909,7 +910,7 @@ type Iter struct {
 	host    *HostInfo
 
 	framer *framer
-	once   sync.Once
+	closed int32
 }
 
 // Host returns the host which the query was sent to.
@@ -1001,12 +1002,12 @@ func (iter *Iter) Scan(dest ...interface{}) bool {
 // Close closes the iterator and returns any errors that happened during
 // the query or the iteration.
 func (iter *Iter) Close() error {
-	iter.once.Do(func() {
+	if atomic.CompareAndSwapInt32(&iter.closed, 0, 1) {
 		if iter.framer != nil {
 			framerPool.Put(iter.framer)
 			iter.framer = nil
 		}
-	})
+	}
 
 	return iter.err
 }