Skip to content

Commit 723aa4a

Browse files
authored
Update count when Lock() is called (#807)
This is important as it will unable to delete lock from sync pool if `isNew` is false.
1 parent e0b595f commit 723aa4a

File tree

1 file changed

+3
-4
lines changed
  • code/go/0chain.net/core/common

1 file changed

+3
-4
lines changed

code/go/0chain.net/core/common/lock.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ type Lock struct {
1919

2020
// Lock Acquire lock
2121
func (l *Lock) Lock() {
22+
l.countMu.Lock()
23+
l.count++
24+
l.countMu.Unlock()
2225
for {
2326
l.actualLock.Lock()
2427
if l.stale {
@@ -53,15 +56,11 @@ func (m *MapLocker) GetLock(key string) (l *Lock, isNew bool) {
5356
valueI, ok := m.m.Load(key)
5457
if ok {
5558
l = valueI.(*Lock)
56-
l.countMu.Lock()
57-
l.count++
58-
l.countMu.Unlock()
5959
return
6060
}
6161

6262
l = &Lock{
6363
key: key,
64-
count: 1,
6564
pMap: m,
6665
actualLock: new(sync.Mutex),
6766
countMu: new(sync.Mutex),

0 commit comments

Comments
 (0)