From 1453afb1304fa9fb7cf62413b537c3a12f0ccd7e Mon Sep 17 00:00:00 2001 From: Fredy Wijaya Date: Fri, 10 May 2024 15:40:04 +0000 Subject: [PATCH] Remove unused OptionalReleasableLockGuard Signed-off-by: Fredy Wijaya --- mobile/library/common/event/BUILD | 1 - .../common/event/provisional_dispatcher.cc | 2 - mobile/library/common/thread/BUILD | 15 ------ mobile/library/common/thread/lock_guard.h | 52 ------------------- mobile/test/common/thread/BUILD | 15 ------ mobile/test/common/thread/lock_guard_test.cc | 27 ---------- 6 files changed, 112 deletions(-) delete mode 100644 mobile/library/common/thread/BUILD delete mode 100644 mobile/library/common/thread/lock_guard.h delete mode 100644 mobile/test/common/thread/BUILD delete mode 100644 mobile/test/common/thread/lock_guard_test.cc diff --git a/mobile/library/common/event/BUILD b/mobile/library/common/event/BUILD index 811e559e3b67..b50a08a0bf09 100644 --- a/mobile/library/common/event/BUILD +++ b/mobile/library/common/event/BUILD @@ -11,7 +11,6 @@ envoy_cc_library( external_deps = ["abseil_optional"], repository = "@envoy", deps = [ - "//library/common/thread:lock_guard_lib", "//library/common/types:c_types_lib", "@envoy//envoy/event:deferred_deletable", "@envoy//envoy/event:dispatcher_interface", diff --git a/mobile/library/common/event/provisional_dispatcher.cc b/mobile/library/common/event/provisional_dispatcher.cc index 1b8f7a2c10f5..299358e13e2a 100644 --- a/mobile/library/common/event/provisional_dispatcher.cc +++ b/mobile/library/common/event/provisional_dispatcher.cc @@ -2,8 +2,6 @@ #include "source/common/common/lock_guard.h" -#include "library/common/thread/lock_guard.h" - namespace Envoy { namespace Event { diff --git a/mobile/library/common/thread/BUILD b/mobile/library/common/thread/BUILD deleted file mode 100644 index 24840332db66..000000000000 --- a/mobile/library/common/thread/BUILD +++ /dev/null @@ -1,15 +0,0 @@ -load("@envoy//bazel:envoy_build_system.bzl", "envoy_cc_library", "envoy_mobile_package") - -licenses(["notice"]) # Apache 2 - -envoy_mobile_package() - -envoy_cc_library( - name = "lock_guard_lib", - hdrs = ["lock_guard.h"], - repository = "@envoy", - deps = [ - "@envoy//envoy/thread:thread_interface", - "@envoy//source/common/common:thread_annotations", - ], -) diff --git a/mobile/library/common/thread/lock_guard.h b/mobile/library/common/thread/lock_guard.h deleted file mode 100644 index f8d12ee4af29..000000000000 --- a/mobile/library/common/thread/lock_guard.h +++ /dev/null @@ -1,52 +0,0 @@ -#pragma once - -#include -#include - -#include "envoy/thread/thread.h" - -namespace Envoy { -namespace Thread { - -/** - * A lock guard that deals with an optional lock and allows call-sites to release the lock prior to - * the lock guard going out of scope. - */ -// TODO(junr03): this could be moved to Envoy's codebase. -class ABSL_SCOPED_LOCKABLE OptionalReleasableLockGuard { -public: - /** - * Establishes a scoped mutex-lock. If non-null, the mutex is locked upon construction. - * - * @param lock the mutex. - */ - OptionalReleasableLockGuard(BasicLockable* lock) ABSL_EXCLUSIVE_LOCK_FUNCTION(lock) - : lock_(lock) { - if (lock_ != nullptr) { - lock_->lock(); - } - } - - /** - * Destruction of the OptionalReleasableLockGuard unlocks the lock, if it is non-null and has not - * already been explicitly released. - */ - ~OptionalReleasableLockGuard() ABSL_UNLOCK_FUNCTION() { release(); } - - /** - * Unlocks the mutex. This enables call-sites to release the mutex prior to the Lock going out of - * scope. - */ - void release() ABSL_UNLOCK_FUNCTION() { - if (lock_ != nullptr) { - lock_->unlock(); - lock_ = nullptr; - } - } - -private: - BasicLockable* lock_; // Set to nullptr on unlock, to prevent double-unlocking. -}; - -} // namespace Thread -} // namespace Envoy diff --git a/mobile/test/common/thread/BUILD b/mobile/test/common/thread/BUILD deleted file mode 100644 index 2c1a905d98a6..000000000000 --- a/mobile/test/common/thread/BUILD +++ /dev/null @@ -1,15 +0,0 @@ -load("@envoy//bazel:envoy_build_system.bzl", "envoy_cc_test", "envoy_mobile_package") - -licenses(["notice"]) # Apache 2 - -envoy_mobile_package() - -envoy_cc_test( - name = "lock_guard_test", - srcs = ["lock_guard_test.cc"], - repository = "@envoy", - deps = [ - "//library/common/thread:lock_guard_lib", - "@envoy//source/common/common:thread_lib", - ], -) diff --git a/mobile/test/common/thread/lock_guard_test.cc b/mobile/test/common/thread/lock_guard_test.cc deleted file mode 100644 index dc35c139e314..000000000000 --- a/mobile/test/common/thread/lock_guard_test.cc +++ /dev/null @@ -1,27 +0,0 @@ -#include "source/common/common/thread.h" - -#include "gtest/gtest.h" -#include "library/common/thread/lock_guard.h" - -namespace Envoy { -namespace Thread { - -class ThreadTest : public testing::Test { -protected: - ThreadTest() = default; - int a_ ABSL_GUARDED_BY(a_mutex_){0}; - MutexBasicLockable a_mutex_; - int b_{0}; -}; - -TEST_F(ThreadTest, TestOptionalReleasableLockGuard) { - OptionalReleasableLockGuard lock(nullptr); - EXPECT_EQ(1, ++b_); - - OptionalReleasableLockGuard lock2(&a_mutex_); - EXPECT_EQ(1, ++a_); - lock2.release(); -} - -} // namespace Thread -} // namespace Envoy