Delete unused ConcurrentCache class
Bug: none
Change-Id: Iff3eab6855e76bdb026ab7006c73103598923d66
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/187580
Commit-Queue: Austin Eng <enga@chromium.org>
Reviewed-by: Ben Clayton <bclayton@google.com>
diff --git a/src/dawn/common/BUILD.gn b/src/dawn/common/BUILD.gn
index 189030f..66ca53a 100644
--- a/src/dawn/common/BUILD.gn
+++ b/src/dawn/common/BUILD.gn
@@ -246,7 +246,6 @@
"Assert.h",
"BitSetIterator.h",
"Compiler.h",
- "ConcurrentCache.h",
"Constants.h",
"ContentLessObjectCache.h",
"ContentLessObjectCacheable.h",
diff --git a/src/dawn/common/CMakeLists.txt b/src/dawn/common/CMakeLists.txt
index ce3bb2b..32c4b95 100644
--- a/src/dawn/common/CMakeLists.txt
+++ b/src/dawn/common/CMakeLists.txt
@@ -53,7 +53,6 @@
"Assert.h"
"BitSetIterator.h"
"Compiler.h"
- "ConcurrentCache.h"
"Constants.h"
"ContentLessObjectCache.h"
"ContentLessObjectCacheable.h"
diff --git a/src/dawn/common/ConcurrentCache.h b/src/dawn/common/ConcurrentCache.h
deleted file mode 100644
index c5e98be..0000000
--- a/src/dawn/common/ConcurrentCache.h
+++ /dev/null
@@ -1,71 +0,0 @@
-// Copyright 2021 The Dawn & Tint Authors
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are met:
-//
-// 1. Redistributions of source code must retain the above copyright notice, this
-// list of conditions and the following disclaimer.
-//
-// 2. Redistributions in binary form must reproduce the above copyright notice,
-// this list of conditions and the following disclaimer in the documentation
-// and/or other materials provided with the distribution.
-//
-// 3. Neither the name of the copyright holder nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
-// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-#ifndef SRC_DAWN_COMMON_CONCURRENTCACHE_H_
-#define SRC_DAWN_COMMON_CONCURRENTCACHE_H_
-
-#include <mutex>
-#include <unordered_set>
-#include <utility>
-
-#include "dawn/common/NonMovable.h"
-
-namespace dawn {
-
-template <typename T>
-class ConcurrentCache : public NonMovable {
- public:
- ConcurrentCache() = default;
-
- T* Find(T* object) {
- std::lock_guard<std::mutex> lock(mMutex);
- auto iter = mCache.find(object);
- if (iter == mCache.end()) {
- return nullptr;
- }
- return *iter;
- }
-
- std::pair<T*, bool> Insert(T* object) {
- std::lock_guard<std::mutex> lock(mMutex);
- auto [value, inserted] = mCache.insert(object);
- return {*value, inserted};
- }
-
- size_t Erase(T* object) {
- std::lock_guard<std::mutex> lock(mMutex);
- return mCache.erase(object);
- }
-
- private:
- std::mutex mMutex;
- std::unordered_set<T*, typename T::HashFunc, typename T::EqualityFunc> mCache;
-};
-
-} // namespace dawn
-
-#endif // SRC_DAWN_COMMON_CONCURRENTCACHE_H_
diff --git a/src/dawn/tests/BUILD.gn b/src/dawn/tests/BUILD.gn
index 6158b5d..9af0d8b 100644
--- a/src/dawn/tests/BUILD.gn
+++ b/src/dawn/tests/BUILD.gn
@@ -325,7 +325,6 @@
"unittests/BuddyMemoryAllocatorTests.cpp",
"unittests/ChainUtilsTests.cpp",
"unittests/CommandAllocatorTests.cpp",
- "unittests/ConcurrentCacheTests.cpp",
"unittests/ContentLessObjectCacheTests.cpp",
"unittests/DefaultTests.cpp",
"unittests/EnumClassBitmasksTests.cpp",
diff --git a/src/dawn/tests/unittests/ConcurrentCacheTests.cpp b/src/dawn/tests/unittests/ConcurrentCacheTests.cpp
deleted file mode 100644
index 3250061..0000000
--- a/src/dawn/tests/unittests/ConcurrentCacheTests.cpp
+++ /dev/null
@@ -1,126 +0,0 @@
-// Copyright 2021 The Dawn & Tint Authors
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are met:
-//
-// 1. Redistributions of source code must retain the above copyright notice, this
-// list of conditions and the following disclaimer.
-//
-// 2. Redistributions in binary form must reproduce the above copyright notice,
-// this list of conditions and the following disclaimer in the documentation
-// and/or other materials provided with the distribution.
-//
-// 3. Neither the name of the copyright holder nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
-// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-#include <memory>
-#include <utility>
-
-#include "dawn/common/ConcurrentCache.h"
-#include "dawn/native/AsyncTask.h"
-#include "dawn/platform/DawnPlatform.h"
-#include "dawn/utils/SystemUtils.h"
-#include "gtest/gtest.h"
-
-namespace dawn {
-namespace {
-
-class SimpleCachedObject {
- public:
- explicit SimpleCachedObject(size_t value) : mValue(value) {}
-
- size_t GetValue() const { return mValue; }
-
- struct EqualityFunc {
- bool operator()(const SimpleCachedObject* a, const SimpleCachedObject* b) const {
- return a->mValue == b->mValue;
- }
- };
-
- struct HashFunc {
- size_t operator()(const SimpleCachedObject* obj) const { return obj->mValue; }
- };
-
- private:
- size_t mValue;
-};
-
-class ConcurrentCacheTest : public testing::Test {
- public:
- ConcurrentCacheTest() : mPool(mPlatform.CreateWorkerTaskPool()), mTaskManager(mPool.get()) {}
-
- protected:
- platform::Platform mPlatform;
- std::unique_ptr<platform::WorkerTaskPool> mPool;
- native::AsyncTaskManager mTaskManager;
- ConcurrentCache<SimpleCachedObject> mCache;
-};
-
-// Test inserting two objects that are equal to each other into the concurrent cache works as
-// expected.
-TEST_F(ConcurrentCacheTest, InsertAtSameTime) {
- SimpleCachedObject cachedObject(1);
- SimpleCachedObject anotherCachedObject(1);
-
- std::pair<SimpleCachedObject*, bool> insertOutput = {};
- std::pair<SimpleCachedObject*, bool> anotherInsertOutput = {};
-
- ConcurrentCache<SimpleCachedObject>* cachePtr = &mCache;
- native::AsyncTask asyncTask1([&insertOutput, cachePtr, &cachedObject] {
- insertOutput = cachePtr->Insert(&cachedObject);
- });
- native::AsyncTask asyncTask2([&anotherInsertOutput, cachePtr, &anotherCachedObject] {
- anotherInsertOutput = cachePtr->Insert(&anotherCachedObject);
- });
- mTaskManager.PostTask(std::move(asyncTask1));
- mTaskManager.PostTask(std::move(asyncTask2));
-
- mTaskManager.WaitAllPendingTasks();
-
- ASSERT_TRUE(insertOutput.first == &cachedObject || insertOutput.first == &anotherCachedObject);
- ASSERT_EQ(insertOutput.first, anotherInsertOutput.first);
- ASSERT_EQ(insertOutput.second, !anotherInsertOutput.second);
-}
-
-// Testing erasing an object after inserting into the cache works as expected.
-TEST_F(ConcurrentCacheTest, EraseAfterInsertion) {
- SimpleCachedObject cachedObject(1);
-
- std::pair<SimpleCachedObject*, bool> insertOutput = {};
- ConcurrentCache<SimpleCachedObject>* cachePtr = &mCache;
- native::AsyncTask insertTask([&insertOutput, cachePtr, &cachedObject] {
- insertOutput = cachePtr->Insert(&cachedObject);
- });
-
- size_t erasedObjectCount = 0;
- native::AsyncTask eraseTask([&erasedObjectCount, cachePtr, &cachedObject] {
- while (cachePtr->Find(&cachedObject) == nullptr) {
- utils::USleep(100);
- }
- erasedObjectCount = cachePtr->Erase(&cachedObject);
- });
-
- mTaskManager.PostTask(std::move(insertTask));
- mTaskManager.PostTask(std::move(eraseTask));
-
- mTaskManager.WaitAllPendingTasks();
-
- ASSERT_EQ(&cachedObject, insertOutput.first);
- ASSERT_TRUE(insertOutput.second);
- ASSERT_EQ(1u, erasedObjectCount);
-}
-
-} // anonymous namespace
-} // namespace dawn