mirror of https://github.com/jackc/pgx.git
use `atomic.Int32` instead of `int + atomic calls`
parent
c3d62c8783
commit
89475c4c91
|
@ -99,7 +99,7 @@ type NetConn struct {
|
||||||
writeDeadline time.Time
|
writeDeadline time.Time
|
||||||
|
|
||||||
// nbOperCnt Tracks how many operations performing simultaneously
|
// nbOperCnt Tracks how many operations performing simultaneously
|
||||||
nbOperCnt int32
|
nbOperCnt atomic.Int32
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewNetConn(conn net.Conn, fakeNonBlockingIO bool) *NetConn {
|
func NewNetConn(conn net.Conn, fakeNonBlockingIO bool) *NetConn {
|
||||||
|
|
|
@ -6,7 +6,6 @@ import (
|
||||||
"errors"
|
"errors"
|
||||||
"golang.org/x/sys/windows"
|
"golang.org/x/sys/windows"
|
||||||
"io"
|
"io"
|
||||||
"sync/atomic"
|
|
||||||
"syscall"
|
"syscall"
|
||||||
"unsafe"
|
"unsafe"
|
||||||
)
|
)
|
||||||
|
@ -133,12 +132,12 @@ func (c *NetConn) SetBlockingMode(blocking bool) error {
|
||||||
|
|
||||||
if blocking {
|
if blocking {
|
||||||
// Not ready to exit from non-blocking mode, there are pending non-blocking operations
|
// Not ready to exit from non-blocking mode, there are pending non-blocking operations
|
||||||
if atomic.AddInt32(&c.nbOperCnt, -1) > 0 {
|
if c.nbOperCnt.Add(-1) > 0 {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Socket is already in non-blocking state
|
// Socket is already in non-blocking state
|
||||||
if atomic.AddInt32(&c.nbOperCnt, 1) > 1 {
|
if c.nbOperCnt.Add(1) > 1 {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -157,9 +156,9 @@ func (c *NetConn) SetBlockingMode(blocking bool) error {
|
||||||
if ctrlErr != nil || err != nil {
|
if ctrlErr != nil || err != nil {
|
||||||
// Revert counters inc/dec in case of error
|
// Revert counters inc/dec in case of error
|
||||||
if blocking {
|
if blocking {
|
||||||
atomic.AddInt32(&c.nbOperCnt, 1)
|
c.nbOperCnt.Add(1)
|
||||||
} else {
|
} else {
|
||||||
atomic.AddInt32(&c.nbOperCnt, -1)
|
c.nbOperCnt.Add(-1)
|
||||||
}
|
}
|
||||||
|
|
||||||
if ctrlErr != nil {
|
if ctrlErr != nil {
|
||||||
|
|
Loading…
Reference in New Issue