OSDN Git Service

Rename LruCache -> LegacyLruCache
authorMartin Brabham <optedoblivion@google.com>
Tue, 8 Sep 2020 20:02:48 +0000 (13:02 -0700)
committerMartin Brabham <optedoblivion@google.com>
Tue, 8 Sep 2020 22:53:04 +0000 (15:53 -0700)
There is a naming conflict with common/lru.h
and gd/common/lru_cache.h.  In order to make the
metrics calls from the shim on the actual events
the legacy version has been renamed to reflect.

Bug: 162984360
Tag: #gd-refactor
Test: cert/run --host SecurityTest
Test: atest --host bluetooth_test_gd
Test: Manual testing with hybrid stack
Change-Id: I4e8656915359fb29b57dcd8405ee295d8ab2a536

btif/include/btif_config_cache.h
common/lru.h
common/lru_unittest.cc
common/metric_id_allocator.h

index 61406f9..212d829 100644 (file)
@@ -55,6 +55,7 @@ class BtifConfigCache {
                               const std::string& key);
 
  private:
-  bluetooth::common::LruCache<std::string, section_t> unpaired_devices_cache_;
+  bluetooth::common::LegacyLruCache<std::string, section_t>
+      unpaired_devices_cache_;
   config_t paired_devices_list_;
 };
index 36f8707..4263683 100644 (file)
@@ -33,7 +33,7 @@ namespace bluetooth {
 namespace common {
 
 template <typename K, typename V>
-class LruCache {
+class LegacyLruCache {
  public:
   using Node = std::pair<K, V>;
   /**
@@ -42,7 +42,7 @@ class LruCache {
    * @param capacity maximum size of the cache
    * @param log_tag, keyword to put at the head of log.
    */
-  LruCache(const size_t& capacity, const std::string& log_tag)
+  LegacyLruCache(const size_t& capacity, const std::string& log_tag)
       : capacity_(capacity) {
     if (capacity_ == 0) {
       // don't allow invalid capacity
@@ -51,10 +51,10 @@ class LruCache {
   }
 
   // delete copy constructor
-  LruCache(LruCache const&) = delete;
-  LruCache& operator=(LruCache const&) = delete;
+  LegacyLruCache(LegacyLruCache const&) = delete;
+  LegacyLruCache& operator=(LegacyLruCache const&) = delete;
 
-  ~LruCache() { Clear(); }
+  ~LegacyLruCache() { Clear(); }
 
   /**
    * Clear the cache
index 6e1d5e4..b58f1df 100644 (file)
 
 namespace testing {
 
-using bluetooth::common::LruCache;
+using bluetooth::common::LegacyLruCache;
 
-TEST(BluetoothLruCacheTest, LruCacheMainTest1) {
+TEST(BluetoothLegacyLruCacheTest, LegacyLruCacheMainTest1) {
   int* value = new int(0);
-  LruCache<int, int> cache(3, "testing");  // capacity = 3;
+  LegacyLruCache<int, int> cache(3, "testing");  // capacity = 3;
   cache.Put(1, 10);
   EXPECT_EQ(cache.Size(), 1);
   EXPECT_FALSE(cache.Put(2, 20));
@@ -74,9 +74,9 @@ TEST(BluetoothLruCacheTest, LruCacheMainTest1) {
   EXPECT_EQ(*value, 60);
 }
 
-TEST(BluetoothLruCacheTest, LruCacheMainTest2) {
+TEST(BluetoothLegacyLruCacheTest, LegacyLruCacheMainTest2) {
   int* value = new int(0);
-  LruCache<int, int> cache(2, "testing");  // size = 2;
+  LegacyLruCache<int, int> cache(2, "testing");  // size = 2;
   EXPECT_FALSE(cache.Put(1, 10));
   EXPECT_FALSE(cache.Put(2, 20));
   EXPECT_THAT(cache.Put(3, 30), Optional(Pair(1, 10)));
@@ -126,8 +126,8 @@ TEST(BluetoothLruCacheTest, LruCacheMainTest2) {
   EXPECT_EQ(*value, 50);
 }
 
-TEST(BluetoothLruCacheTest, LruCacheFindTest) {
-  LruCache<int, int> cache(10, "testing");
+TEST(BluetoothLegacyLruCacheTest, LegacyLruCacheFindTest) {
+  LegacyLruCache<int, int> cache(10, "testing");
   cache.Put(1, 10);
   cache.Put(2, 20);
   int value = 0;
@@ -143,8 +143,8 @@ TEST(BluetoothLruCacheTest, LruCacheFindTest) {
   EXPECT_EQ(cache.Find(10), nullptr);
 }
 
-TEST(BluetoothLruCacheTest, LruCacheGetTest) {
-  LruCache<int, int> cache(10, "testing");
+TEST(BluetoothLegacyLruCacheTest, LegacyLruCacheGetTest) {
+  LegacyLruCache<int, int> cache(10, "testing");
   cache.Put(1, 10);
   cache.Put(2, 20);
   int value = 0;
@@ -157,8 +157,8 @@ TEST(BluetoothLruCacheTest, LruCacheGetTest) {
   EXPECT_EQ(value, 10);
 }
 
-TEST(BluetoothLruCacheTest, LruCacheRemoveTest) {
-  LruCache<int, int> cache(10, "testing");
+TEST(BluetoothLegacyLruCacheTest, LegacyLruCacheRemoveTest) {
+  LegacyLruCache<int, int> cache(10, "testing");
   for (int key = 0; key <= 30; key++) {
     cache.Put(key, key * 100);
   }
@@ -176,8 +176,8 @@ TEST(BluetoothLruCacheTest, LruCacheRemoveTest) {
   }
 }
 
-TEST(BluetoothLruCacheTest, LruCacheClearTest) {
-  LruCache<int, int> cache(10, "testing");
+TEST(BluetoothLegacyLruCacheTest, LegacyLruCacheClearTest) {
+  LegacyLruCache<int, int> cache(10, "testing");
   for (int key = 0; key < 10; key++) {
     cache.Put(key, key * 100);
   }
@@ -197,10 +197,10 @@ TEST(BluetoothLruCacheTest, LruCacheClearTest) {
   }
 }
 
-TEST(BluetoothLruCacheTest, LruCachePressureTest) {
+TEST(BluetoothLegacyLruCacheTest, LegacyLruCachePressureTest) {
   auto started = std::chrono::high_resolution_clock::now();
   int max_size = 0xFFFFF;  // 2^20 = 1M
-  LruCache<int, int> cache(static_cast<size_t>(max_size), "testing");
+  LegacyLruCache<int, int> cache(static_cast<size_t>(max_size), "testing");
 
   // fill the cache
   for (int key = 0; key < max_size; key++) {
@@ -239,8 +239,8 @@ TEST(BluetoothLruCacheTest, LruCachePressureTest) {
   EXPECT_LT(execution_time, 10000);
 }
 
-TEST(BluetoothLruCacheTest, BluetoothLruMultiThreadPressureTest) {
-  LruCache<int, int> cache(100, "testing");
+TEST(BluetoothLegacyLruCacheTest, BluetoothLruMultiThreadPressureTest) {
+  LegacyLruCache<int, int> cache(100, "testing");
   auto pointer = &cache;
   // make sure no deadlock
   std::vector<std::thread> workers;
index 63236e4..cd18d5c 100644 (file)
@@ -119,8 +119,8 @@ class MetricIdAllocator {
   static const std::string LOGGING_TAG;
   mutable std::mutex id_allocator_mutex_;
 
-  LruCache<RawAddress, int> paired_device_cache_;
-  LruCache<RawAddress, int> temporary_device_cache_;
+  LegacyLruCache<RawAddress, int> paired_device_cache_;
+  LegacyLruCache<RawAddress, int> temporary_device_cache_;
   std::unordered_set<int> id_set_;
 
   int next_id_{kMinId};