@@ -3,6 +3,7 @@ package kinetic
33import (
44 "errors"
55 "sync"
6+ "sync/atomic"
67 "time"
78
89 gokinesis "github.com/rewardStyle/go-kinesis"
@@ -57,11 +58,8 @@ type kinesis struct {
5758
5859 client gokinesis.KinesisClient
5960
60- msgCount int
61- msgCountMu sync.Mutex
62-
63- errCount int
64- errCountMu sync.Mutex
61+ msgCount int64
62+ errCount int64
6563}
6664
6765func (k * kinesis ) init (stream , shard , shardIteratorType , accessKey , secretKey , region string ) (* kinesis , error ) {
@@ -157,39 +155,27 @@ func (k *kinesis) refreshClient(accessKey, secretKey, region string) {
157155}
158156
159157func (k * kinesis ) decMsgCount () {
160- k .msgCountMu .Lock ()
161- k .msgCount --
162- k .msgCountMu .Unlock ()
158+ atomic .AddInt64 (& k .msgCount , - 1 )
163159}
164160
165161func (k * kinesis ) incMsgCount () {
166- k .msgCountMu .Lock ()
167- k .msgCount ++
168- k .msgCountMu .Unlock ()
162+ atomic .AddInt64 (& k .msgCount , 1 )
169163}
170164
171- func (k * kinesis ) getMsgCount () int {
172- k .msgCountMu .Lock ()
173- defer k .msgCountMu .Unlock ()
174- return k .msgCount
165+ func (k * kinesis ) getMsgCount () int64 {
166+ return atomic .LoadInt64 (& k .msgCount )
175167}
176168
177169func (k * kinesis ) decErrCount () {
178- k .errCountMu .Lock ()
179- k .errCount --
180- k .errCountMu .Unlock ()
170+ atomic .AddInt64 (& k .errCount , - 1 )
181171}
182172
183173func (k * kinesis ) incErrCount () {
184- k .errCountMu .Lock ()
185- k .errCount ++
186- k .errCountMu .Unlock ()
174+ atomic .AddInt64 (& k .errCount , 1 )
187175}
188176
189- func (k * kinesis ) getErrCount () int {
190- k .errCountMu .Lock ()
191- defer k .errCountMu .Unlock ()
192- return k .errCount
177+ func (k * kinesis ) getErrCount () int64 {
178+ return atomic .LoadInt64 (& k .errCount )
193179}
194180
195181func getLock (sem chan bool ) {
0 commit comments