فهرست منبع

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

Chris Bannister 10 سال پیش
والد
کامیت
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
 }