File tree 1 file changed +6
-0
lines changed
1 file changed +6
-0
lines changed Original file line number Diff line number Diff line change @@ -16,6 +16,7 @@ type Score struct {
16
16
DefaultScoreMagnification int64
17
17
18
18
mu sync.RWMutex
19
+ cmu sync.RWMutex
19
20
total sumTable
20
21
count int32
21
22
queue chan ScoreTag
@@ -27,6 +28,7 @@ func NewScore(ctx context.Context) *Score {
27
28
Table : make (ScoreTable ),
28
29
DefaultScoreMagnification : 0 ,
29
30
mu : sync.RWMutex {},
31
+ cmu : sync.RWMutex {},
30
32
total : make (sumTable ),
31
33
count : 0 ,
32
34
queue : make (chan ScoreTag ),
@@ -71,15 +73,19 @@ func (s *Score) Add(tag ScoreTag) {
71
73
defer func () { recover () }()
72
74
73
75
if atomic .CompareAndSwapUint32 (& s .closed , 0 , 0 ) {
76
+ s .cmu .RLock ()
74
77
s .queue <- tag
78
+ s .cmu .RUnlock ()
75
79
atomic .AddInt32 (& s .count , 1 )
76
80
}
77
81
}
78
82
79
83
func (s * Score ) Close () {
80
84
if atomic .CompareAndSwapUint32 (& s .closed , 0 , 1 ) {
81
85
atomic .AddInt32 (& s .count , 1 )
86
+ s .cmu .Lock ()
82
87
close (s .queue )
88
+ s .cmu .Unlock ()
83
89
}
84
90
}
85
91
You can’t perform that action at this time.
0 commit comments