Use atomic loads for the clients counter

This commit is contained in:
Frank Denis 2018-03-02 09:41:12 +01:00
parent 4e7631bfcd
commit 97156c3ad3
1 changed files with 2 additions and 2 deletions

View File

@ -227,7 +227,7 @@ func (proxy *Proxy) exchangeWithTCPServer(serverInfo *ServerInfo, encryptedQuery
func (proxy *Proxy) clientsCountInc() bool {
for {
count := proxy.clientsCount
count := atomic.LoadUint32(&proxy.clientsCount)
if count >= proxy.maxClients {
return false
}
@ -240,7 +240,7 @@ func (proxy *Proxy) clientsCountInc() bool {
func (proxy *Proxy) clientsCountDec() {
for {
if count := proxy.clientsCount; count == 0 || atomic.CompareAndSwapUint32(&proxy.clientsCount, count, count-1) {
if count := atomic.LoadUint32(&proxy.clientsCount); count == 0 || atomic.CompareAndSwapUint32(&proxy.clientsCount, count, count-1) {
break
}
}