/*
 * Copyright (c) 2015-present, Facebook, Inc.
 * All rights reserved.
 *
 * This source code is licensed under the BSD-style license found in the
 * LICENSE file in the root directory of this source tree. An additional grant
 * of patent rights can be found in the PATENTS file in the same directory.
 */

package com.facebook.imagepipeline.memory;

public class BitmapCounterProvider {
  private static final long KB = 1024;
  private static final long MB = 1024 * KB;

  /**
   * Our Bitmaps live in ashmem, meaning that they are pinned in Android's shared native memory.
   *
   * <p> Therefore, we are not constrained by the max heap size of the dalvik heap, but we want to
   * make sure we don't use too much memory on low end devices, so that we don't force other
   * background process to be killed.
   */
  public static final int MAX_BITMAP_TOTAL_SIZE = getMaxSizeHardCap();
  public static final int MAX_BITMAP_COUNT = 384;

  private static BitmapCounter sBitmapCounter;

  private static int getMaxSizeHardCap() {
    final int maxMemory = (int) Math.min(Runtime.getRuntime().maxMemory(), Integer.MAX_VALUE);
    if (maxMemory > 16 * MB) {
      return maxMemory / 4 * 3;
    } else {
      return maxMemory / 2;
    }
  }

  public static BitmapCounter get() {
    if (sBitmapCounter == null) {
      sBitmapCounter = new BitmapCounter(MAX_BITMAP_COUNT, MAX_BITMAP_TOTAL_SIZE);
    }
    return sBitmapCounter;
  }
}

@@ -346,16 +346,66 @@
 emory;%0A%0A
+import com.facebook.infer.annotation.ThreadSafe;%0A%0A
 public c
@@ -992,32 +992,41 @@
  private static 
+volatile 
 BitmapCounter sB
@@ -1293,16 +1293,30 @@
  %7D%0A  %7D%0A%0A
+  @ThreadSafe%0A
   public
@@ -1375,24 +1375,116 @@
  == null) %7B%0A
+      synchronized (BitmapCounterProvider.class) %7B%0A        if (sBitmapCounter == null) %7B%0A   
       sBitma
@@ -1550,24 +1550,42 @@
 OTAL_SIZE);%0A
+        %7D%0A      %7D%0A
     %7D%0A    re

Make BitmapCounterProvider.get() ThreadSafe