瀏覽代碼

Switch back to atomic operations; remove unused sync.Mutex

Aaron Kavlie 10 年之前
父節點
當前提交
14688448ab
共有 1 個文件被更改,包括 2 次插入3 次删除
  1. 2 3
      mocks/consumer.go

+ 2 - 3
mocks/consumer.go

@@ -162,7 +162,6 @@ func (c *Consumer) ExpectConsumePartition(topic string, partition int32, offset
 // Errors and Messages channel, you should specify what values will be provided on these
 // channels using YieldMessage and YieldError.
 type PartitionConsumer struct {
-	l                       sync.Mutex
 	t                       ErrorReporter
 	topic                   string
 	partition               int32
@@ -261,11 +260,11 @@ func (pc *PartitionConsumer) HighWaterMarkOffset() int64 {
 // reasons forthis not to happen. ou can call ExpectMessagesDrainedOnClose so it will
 // verify that the channel is empty on close.
 func (pc *PartitionConsumer) YieldMessage(msg *sarama.ConsumerMessage) {
-	pc.highWaterMarkOffset += 1
+	atomic.AddInt64(&pc.highWaterMarkOffset, 1)
 
 	msg.Topic = pc.topic
 	msg.Partition = pc.partition
-	msg.Offset = pc.highWaterMarkOffset
+	msg.Offset = atomic.LoadInt64(&pc.highWaterMarkOffset)
 
 	pc.messages <- msg
 }