update locks

This commit is contained in:
shoopea
2025-10-19 14:12:31 +02:00
parent ace13b68a8
commit 73f9551c8f
6 changed files with 75 additions and 37 deletions

18
box.go
View File

@@ -21,6 +21,16 @@ type Box struct {
mx sync.Mutex
}
func (b *Box) Lock() {
log.WithFields(log.Fields{"name": b.name}).Debugf("starting")
b.mx.Lock()
}
func (b *Box) Unlock() {
log.WithFields(log.Fields{"name": b.name}).Debugf("starting")
b.mx.Unlock()
}
func (c *Config) NewBox(name, addr, user, key string) (b *Box, err error) {
log.WithFields(log.Fields{"name": name, "addr": addr, "user": user, "key": key}).Debugf("starting")
defer log.WithFields(log.Fields{"name": name, "addr": addr, "user": user, "key": key}).Debugf("done")
@@ -60,8 +70,8 @@ func (b *Box) Open() error {
log.WithFields(log.Fields{"name": b.name}).Debugf("starting")
defer log.WithFields(log.Fields{"name": b.name}).Debugf("done")
b.mx.Lock()
defer b.mx.Unlock()
b.Lock()
defer b.Unlock()
if b.online {
return nil
@@ -89,8 +99,8 @@ func (b *Box) Close() error {
log.WithFields(log.Fields{"name": b.name}).Debugf("starting")
defer log.WithFields(log.Fields{"name": b.name}).Debugf("done")
b.mx.Lock()
defer b.mx.Unlock()
b.Lock()
defer b.Unlock()
if !b.online {
return nil