Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions util/modbus/modbus.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ type meterConnection struct {
proto Protocol
refs int // count of references; first connection has ref count 0

// largest value requested by any of the sharing logical connections
mu sync.Mutex
delay time.Duration
connectDelay time.Duration
timeout time.Duration
Expand All @@ -114,23 +114,23 @@ type meterConnection struct {

// setDelay applies the delay if larger than the current value
func (c *meterConnection) setDelay(delay time.Duration) {
mu.Lock()
defer mu.Unlock()
c.mu.Lock()
defer c.mu.Unlock()

c.delay = max(c.delay, delay)
}

func (c *meterConnection) getDelay() time.Duration {
mu.Lock()
defer mu.Unlock()
c.mu.Lock()
defer c.mu.Unlock()

return c.delay
}

// setConnectDelay applies the connect delay if larger than the current value
func (c *meterConnection) setConnectDelay(delay time.Duration) {
mu.Lock()
defer mu.Unlock()
c.mu.Lock()
defer c.mu.Unlock()

if delay > c.connectDelay {
c.connectDelay = delay
Expand All @@ -140,8 +140,8 @@ func (c *meterConnection) setConnectDelay(delay time.Duration) {

// setTimeout applies the timeout if larger than the current value
func (c *meterConnection) setTimeout(timeout time.Duration) {
mu.Lock()
defer mu.Unlock()
c.mu.Lock()
defer c.mu.Unlock()

if timeout > c.timeout {
c.timeout = timeout
Expand Down
Loading