Bug 722575 - make SerialRecordConsumer.consumerIsDone() thread-safe. r=rnewman
authorNick Alexander <nalexander@mozilla.com>
Fri, 02 Mar 2012 17:36:15 -0800
changeset 88391 16bf8c62011d2a8fc922329bed6c995f0b220c4c
parent 88390 bb724346429b54addcec474afcfdc530b946129a
child 88392 6827710a19f1c3c1e2adbaa85ed309377f8bf33a
push id157
push userMs2ger@gmail.com
push dateWed, 07 Mar 2012 19:27:10 +0000
reviewersrnewman
bugs722575
milestone13.0a1
Bug 722575 - make SerialRecordConsumer.consumerIsDone() thread-safe. r=rnewman
mobile/android/base/sync/synchronizer/SerialRecordConsumer.java
--- a/mobile/android/base/sync/synchronizer/SerialRecordConsumer.java
+++ b/mobile/android/base/sync/synchronizer/SerialRecordConsumer.java
@@ -44,17 +44,17 @@ import android.util.Log;
 /**
  * Consume records from a queue inside a RecordsChannel, storing them serially.
  * @author rnewman
  *
  */
 class SerialRecordConsumer extends RecordConsumer {
   private static final String LOG_TAG = "SerialRecordConsumer";
   protected boolean stopEventually = false;
-  private long counter = 0;
+  private volatile long counter = 0;
 
   public SerialRecordConsumer(RecordsConsumerDelegate delegate) {
     this.delegate = delegate;
   }
 
   private static void info(String message) {
     System.out.println("INFO: " + message);
     Log.i(LOG_TAG, message);
@@ -125,17 +125,18 @@ class SerialRecordConsumer extends Recor
       } catch (InterruptedException e) {
         // TODO
       }
       debug("storeSerially() dropped storeSerializer.");
     }
   }
 
   private void consumerIsDone() {
-    info("Consumer is done. Processed " + counter + ((counter == 1) ? " record." : " records."));
+    long counterNow = this.counter;
+    info("Consumer is done. Processed " + counterNow + ((counterNow == 1) ? " record." : " records."));
     delegate.consumerIsDone(stopImmediately);
   }
 
   @Override
   public void run() {
     while (true) {
       synchronized (monitor) {
         debug("run() took monitor.");