Переглянути джерело

Merge pull request #655 from Zariel/go16

use atomic to gate framer release so we dont copy the sync cond mutex
Chris Bannister 9 роки тому
батько
коміт
7376f065b4
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
 }