chore: modernize

This commit is contained in:
andig 2026-05-05 08:43:23 +02:00
parent 0eca536c9e
commit 77067ef783
3 changed files with 7 additions and 7 deletions

View file

@ -7,6 +7,7 @@ import (
"reflect" "reflect"
"slices" "slices"
"sync" "sync"
"sync/atomic"
"testing" "testing"
"time" "time"
@ -85,7 +86,7 @@ type Loadpoint struct {
lpChan chan<- *Loadpoint // update requests lpChan chan<- *Loadpoint // update requests
log *util.Logger log *util.Logger
rwMutex int64 // count reentrant RWMutex rwMutex atomic.Int64 // count reentrant RWMutex
sync.RWMutex // guard status sync.RWMutex // guard status
vmu sync.RWMutex // guard vehicle vmu sync.RWMutex // guard vehicle

View file

@ -1,12 +1,11 @@
package core package core
import ( import (
"sync/atomic"
"testing" "testing"
) )
func (lp *Loadpoint) RLock() { func (lp *Loadpoint) RLock() {
if testing.Testing() && atomic.AddInt64(&lp.rwMutex, 1) > 1 { if testing.Testing() && lp.rwMutex.Add(1) > 1 {
panic("reentrant RLock") panic("reentrant RLock")
} }
lp.RWMutex.RLock() lp.RWMutex.RLock()
@ -14,13 +13,13 @@ func (lp *Loadpoint) RLock() {
func (lp *Loadpoint) RUnlock() { func (lp *Loadpoint) RUnlock() {
if testing.Testing() { if testing.Testing() {
atomic.AddInt64(&lp.rwMutex, -1) lp.rwMutex.Add(-1)
} }
lp.RWMutex.RUnlock() lp.RWMutex.RUnlock()
} }
func (lp *Loadpoint) Lock() { func (lp *Loadpoint) Lock() {
if testing.Testing() && atomic.AddInt64(&lp.rwMutex, 1) > 1 { if testing.Testing() && lp.rwMutex.Add(1) > 1 {
panic("reentrant Lock") panic("reentrant Lock")
} }
lp.RWMutex.Lock() lp.RWMutex.Lock()
@ -28,7 +27,7 @@ func (lp *Loadpoint) Lock() {
func (lp *Loadpoint) Unlock() { func (lp *Loadpoint) Unlock() {
if testing.Testing() { if testing.Testing() {
atomic.AddInt64(&lp.rwMutex, -1) lp.rwMutex.Add(-1)
} }
lp.RWMutex.Unlock() lp.RWMutex.Unlock()
} }

View file

@ -224,7 +224,7 @@ func modbusCRC16(data []byte) []byte {
crc := uint16(0xFFFF) crc := uint16(0xFFFF)
for _, b := range data { for _, b := range data {
crc ^= uint16(b) crc ^= uint16(b)
for i := 0; i < 8; i++ { for range 8 {
if crc&0x0001 != 0 { if crc&0x0001 != 0 {
crc = (crc >> 1) ^ 0xA001 crc = (crc >> 1) ^ 0xA001
} else { } else {