Skip to content

Commit

Permalink
Add test support
Browse files Browse the repository at this point in the history
  • Loading branch information
andig committed Feb 8, 2025
1 parent 3245de7 commit 5748a2d
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
4 changes: 2 additions & 2 deletions core/loadpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,11 @@ type Loadpoint struct {
lpChan chan<- *Loadpoint // update requests
log *util.Logger

// exposed public configuration
rwMutex int64 // count reentrant RWMutex
sync.RWMutex // guard status

vmu sync.RWMutex // guard vehicle

// exposed public configuration
CircuitRef string `mapstructure:"circuit"` // Circuit reference
ChargerRef string `mapstructure:"charger"` // Charger reference
VehicleRef string `mapstructure:"vehicle"` // Vehicle reference
Expand Down
34 changes: 34 additions & 0 deletions core/loadpoint_mutex.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package core

import (
"sync/atomic"
"testing"
)

func (lp *Loadpoint) RLock() {
if testing.Testing() && atomic.AddInt64(&lp.rwMutex, 1) > 1 {
panic("reentrant RLock")
}
lp.RWMutex.RLock()
}

func (lp *Loadpoint) RUnlock() {
if testing.Testing() {
atomic.AddInt64(&lp.rwMutex, -1)
}
lp.RWMutex.RUnlock()
}

func (lp *Loadpoint) Lock() {
if testing.Testing() && atomic.AddInt64(&lp.rwMutex, 1) > 1 {
panic("reentrant Lock")
}
lp.RWMutex.Lock()
}

func (lp *Loadpoint) Unlock() {
if testing.Testing() {
atomic.AddInt64(&lp.rwMutex, -1)
}
lp.RWMutex.Unlock()
}

0 comments on commit 5748a2d

Please sign in to comment.