Skip to content

Commit

Permalink
Merge 6ddca90 into 4bd9866
Browse files Browse the repository at this point in the history
  • Loading branch information
gfyrag authored Jan 26, 2022
2 parents 4bd9866 + 6ddca90 commit a33d4f1
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions pkg/ledger/lock.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ type Locker interface {

type InMemoryLocker struct {
globalLock sync.RWMutex
locks map[string]sync.Mutex
locks map[string]*sync.Mutex
}

func (d *InMemoryLocker) Lock(ledger string) (Unlock, error) {
Expand All @@ -24,6 +24,7 @@ func (d *InMemoryLocker) Lock(ledger string) (Unlock, error) {
d.globalLock.Lock()
lock, ok = d.locks[ledger] // Double check, the lock can have been acquired by another go routing between RUnlock and Lock
if !ok {
lock = &sync.Mutex{}
d.locks[ledger] = lock
}
d.globalLock.Unlock()
Expand All @@ -34,6 +35,6 @@ ret:

func NewInMemoryLocker() *InMemoryLocker {
return &InMemoryLocker{
locks: map[string]sync.Mutex{},
locks: map[string]*sync.Mutex{},
}
}

0 comments on commit a33d4f1

Please sign in to comment.