From 77067ef783be0e91d64ca3dea7edbfbacb3e1582 Mon Sep 17 00:00:00 2001 From: andig Date: Tue, 5 May 2026 08:43:23 +0200 Subject: [PATCH] chore: modernize --- core/loadpoint.go | 3 ++- core/loadpoint_mutex.go | 9 ++++----- plugin/aa55udp.go | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/core/loadpoint.go b/core/loadpoint.go index bf46a1df1..b4b962635 100644 --- a/core/loadpoint.go +++ b/core/loadpoint.go @@ -7,6 +7,7 @@ import ( "reflect" "slices" "sync" + "sync/atomic" "testing" "time" @@ -85,7 +86,7 @@ type Loadpoint struct { lpChan chan<- *Loadpoint // update requests log *util.Logger - rwMutex int64 // count reentrant RWMutex + rwMutex atomic.Int64 // count reentrant RWMutex sync.RWMutex // guard status vmu sync.RWMutex // guard vehicle diff --git a/core/loadpoint_mutex.go b/core/loadpoint_mutex.go index b5a8cebb5..96d223adf 100644 --- a/core/loadpoint_mutex.go +++ b/core/loadpoint_mutex.go @@ -1,12 +1,11 @@ package core import ( - "sync/atomic" "testing" ) func (lp *Loadpoint) RLock() { - if testing.Testing() && atomic.AddInt64(&lp.rwMutex, 1) > 1 { + if testing.Testing() && lp.rwMutex.Add(1) > 1 { panic("reentrant RLock") } lp.RWMutex.RLock() @@ -14,13 +13,13 @@ func (lp *Loadpoint) RLock() { func (lp *Loadpoint) RUnlock() { if testing.Testing() { - atomic.AddInt64(&lp.rwMutex, -1) + lp.rwMutex.Add(-1) } lp.RWMutex.RUnlock() } func (lp *Loadpoint) Lock() { - if testing.Testing() && atomic.AddInt64(&lp.rwMutex, 1) > 1 { + if testing.Testing() && lp.rwMutex.Add(1) > 1 { panic("reentrant Lock") } lp.RWMutex.Lock() @@ -28,7 +27,7 @@ func (lp *Loadpoint) Lock() { func (lp *Loadpoint) Unlock() { if testing.Testing() { - atomic.AddInt64(&lp.rwMutex, -1) + lp.rwMutex.Add(-1) } lp.RWMutex.Unlock() } diff --git a/plugin/aa55udp.go b/plugin/aa55udp.go index 1866ba4f5..6e4385ce8 100644 --- a/plugin/aa55udp.go +++ b/plugin/aa55udp.go @@ -224,7 +224,7 @@ func modbusCRC16(data []byte) []byte { crc := uint16(0xFFFF) for _, b := range data { crc ^= uint16(b) - for i := 0; i < 8; i++ { + for range 8 { if crc&0x0001 != 0 { crc = (crc >> 1) ^ 0xA001 } else {