-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathentry.go
50 lines (43 loc) · 817 Bytes
/
entry.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package godisson
import (
"context"
"sync"
)
type RenewEntry struct {
sync.Mutex
goroutineIds map[uint64]int64
cancelFunc context.CancelFunc
}
func NewRenewEntry() *RenewEntry {
return &RenewEntry{
goroutineIds: make(map[uint64]int64),
}
}
func (r *RenewEntry) addGoroutineId(goroutineId uint64) {
r.Lock()
defer r.Unlock()
count, ok := r.goroutineIds[goroutineId]
if ok {
count++
} else {
count = 1
}
r.goroutineIds[goroutineId] = count
}
func (r *RenewEntry) removeGoroutineId(goroutineId uint64) {
r.Lock()
defer r.Unlock()
count, ok := r.goroutineIds[goroutineId]
if !ok {
return
}
count--
if count == 0 {
delete(r.goroutineIds, goroutineId)
} else {
r.goroutineIds[goroutineId] = count
}
}
func (r *RenewEntry) hasNoThreads() bool {
return len(r.goroutineIds) == 0
}