use the new atomic types introduced in Go 1.19

we depend on Go 1.19 anyway

Signed-off-by: Nicola Murino <nicola.murino@gmail.com>
This commit is contained in:
Nicola Murino
2022-08-30 15:47:41 +02:00
parent da03f6c4e3
commit 95e9106902
22 changed files with 231 additions and 231 deletions

View File

@@ -23,13 +23,13 @@ import (
// clienstMap is a struct containing the map of the connected clients
type clientsMap struct {
totalConnections int32
totalConnections atomic.Int32
mu sync.RWMutex
clients map[string]int
}
func (c *clientsMap) add(source string) {
atomic.AddInt32(&c.totalConnections, 1)
c.totalConnections.Add(1)
c.mu.Lock()
defer c.mu.Unlock()
@@ -42,7 +42,7 @@ func (c *clientsMap) remove(source string) {
defer c.mu.Unlock()
if val, ok := c.clients[source]; ok {
atomic.AddInt32(&c.totalConnections, -1)
c.totalConnections.Add(-1)
c.clients[source]--
if val > 1 {
return
@@ -54,7 +54,7 @@ func (c *clientsMap) remove(source string) {
}
func (c *clientsMap) getTotal() int32 {
return atomic.LoadInt32(&c.totalConnections)
return c.totalConnections.Load()
}
func (c *clientsMap) getTotalFrom(source string) int {