Mark legacy Mutex methods and MutexLock pointer constructors as deprecated
Updates `absl::Mutex` and related RAII lockers (`absl::MutexLock`,
etc) to deprecate legacy APIs in favor of standard-compliant
alternatives.
* `absl::Mutex`: Adds `[[deprecated]]` to legacy CamelCase methods
(e.g., `Lock`, `ReaderLock`) in favor of standard C++ lower-case
methods (`lock`, `lock_shared`) which support `std::scoped_lock`.
* `absl::MutexLock` (and friends): Adds `[[deprecated]]` to
constructors accepting raw pointers, favoring new
reference-accepting constructors.
To support this change, warnings coming from external repositories
are now suppressed in Bazel CI builds.
PiperOrigin-RevId: 852978576
Change-Id: I54ae951f28a1b7d90fcb46ceeaf09f192af257df
diff --git a/absl/synchronization/mutex.h b/absl/synchronization/mutex.h
index 3af74c2..39ea0d0 100644
--- a/absl/synchronization/mutex.h
+++ b/absl/synchronization/mutex.h
@@ -178,6 +178,7 @@
// then acquires it exclusively. (This lock is also known as a "write lock.")
void lock() ABSL_EXCLUSIVE_LOCK_FUNCTION();
+ ABSL_DEPRECATE_AND_INLINE()
inline void Lock() ABSL_EXCLUSIVE_LOCK_FUNCTION() { lock(); }
// Mutex::unlock()
@@ -186,6 +187,7 @@
// free state. Calling thread must hold the `Mutex` exclusively.
void unlock() ABSL_UNLOCK_FUNCTION();
+ ABSL_DEPRECATE_AND_INLINE()
inline void Unlock() ABSL_UNLOCK_FUNCTION() { unlock(); }
// Mutex::try_lock()
@@ -195,6 +197,7 @@
// probability if the `Mutex` was free.
[[nodiscard]] bool try_lock() ABSL_EXCLUSIVE_TRYLOCK_FUNCTION(true);
+ ABSL_DEPRECATE_AND_INLINE()
[[nodiscard]] bool TryLock() ABSL_EXCLUSIVE_TRYLOCK_FUNCTION(true) {
return try_lock();
}
@@ -249,6 +252,7 @@
// lock on the mutex.
void lock_shared() ABSL_SHARED_LOCK_FUNCTION();
+ ABSL_DEPRECATE_AND_INLINE()
void ReaderLock() ABSL_SHARED_LOCK_FUNCTION() { lock_shared(); }
// Mutex::unlock_shared()
@@ -258,6 +262,7 @@
// Note that you cannot call `unlock_shared()` on a mutex held in write mode.
void unlock_shared() ABSL_UNLOCK_FUNCTION();
+ ABSL_DEPRECATE_AND_INLINE()
void ReaderUnlock() ABSL_UNLOCK_FUNCTION() { unlock_shared(); }
// Mutex::try_lock_shared()
@@ -267,6 +272,7 @@
// `true` with high probability if the `Mutex` was free or shared.
[[nodiscard]] bool try_lock_shared() ABSL_SHARED_TRYLOCK_FUNCTION(true);
+ ABSL_DEPRECATE_AND_INLINE()
[[nodiscard]] bool ReaderTryLock() ABSL_SHARED_TRYLOCK_FUNCTION(true) {
return try_lock_shared();
}
@@ -291,10 +297,13 @@
// These methods may be used (along with the complementary `Reader*()`
// methods) to distinguish simple exclusive `Mutex` usage (`Lock()`,
// etc.) from reader/writer lock usage.
+ ABSL_DEPRECATE_AND_INLINE()
void WriterLock() ABSL_EXCLUSIVE_LOCK_FUNCTION() { lock(); }
+ ABSL_DEPRECATE_AND_INLINE()
void WriterUnlock() ABSL_UNLOCK_FUNCTION() { unlock(); }
+ ABSL_DEPRECATE_AND_INLINE()
[[nodiscard]] bool WriterTryLock() ABSL_EXCLUSIVE_TRYLOCK_FUNCTION(true) {
return try_lock();
}
@@ -608,6 +617,8 @@
// Calls `mu->lock()` and returns when that call returns. That is, `*mu` is
// guaranteed to be locked when this object is constructed. Requires that
// `mu` be dereferenceable.
+ [[deprecated("Use the constructor that takes a reference instead")]]
+ ABSL_REFACTOR_INLINE
explicit MutexLock(Mutex* absl_nonnull mu) ABSL_EXCLUSIVE_LOCK_FUNCTION(mu)
: MutexLock(*mu) {}
@@ -620,6 +631,8 @@
this->mu_.LockWhen(cond);
}
+ [[deprecated("Use the constructor that takes a reference instead")]]
+ ABSL_REFACTOR_INLINE
explicit MutexLock(Mutex* absl_nonnull mu, const Condition& cond)
ABSL_EXCLUSIVE_LOCK_FUNCTION(mu)
: MutexLock(*mu, cond) {}
@@ -647,6 +660,8 @@
mu.lock_shared();
}
+ [[deprecated("Use the constructor that takes a reference instead")]]
+ ABSL_REFACTOR_INLINE
explicit ReaderMutexLock(Mutex* absl_nonnull mu) ABSL_SHARED_LOCK_FUNCTION(mu)
: ReaderMutexLock(*mu) {}
@@ -656,6 +671,8 @@
mu.ReaderLockWhen(cond);
}
+ [[deprecated("Use the constructor that takes a reference instead")]]
+ ABSL_REFACTOR_INLINE
explicit ReaderMutexLock(Mutex* absl_nonnull mu, const Condition& cond)
ABSL_SHARED_LOCK_FUNCTION(mu)
: ReaderMutexLock(*mu, cond) {}
@@ -683,6 +700,8 @@
mu.lock();
}
+ [[deprecated("Use the constructor that takes a reference instead")]]
+ ABSL_REFACTOR_INLINE
explicit WriterMutexLock(Mutex* absl_nonnull mu)
ABSL_EXCLUSIVE_LOCK_FUNCTION(mu)
: WriterMutexLock(*mu) {}
@@ -694,6 +713,8 @@
mu.WriterLockWhen(cond);
}
+ [[deprecated("Use the constructor that takes a reference instead")]]
+ ABSL_REFACTOR_INLINE
explicit WriterMutexLock(Mutex* absl_nonnull mu, const Condition& cond)
ABSL_EXCLUSIVE_LOCK_FUNCTION(mu)
: WriterMutexLock(*mu, cond) {}
@@ -1097,6 +1118,8 @@
this->mu_->lock();
}
+ [[deprecated("Use the constructor that takes a reference instead")]]
+ ABSL_REFACTOR_INLINE
explicit ReleasableMutexLock(Mutex* absl_nonnull mu)
ABSL_EXCLUSIVE_LOCK_FUNCTION(mu)
: ReleasableMutexLock(*mu) {}
@@ -1108,6 +1131,8 @@
this->mu_->LockWhen(cond);
}
+ [[deprecated("Use the constructor that takes a reference instead")]]
+ ABSL_REFACTOR_INLINE
explicit ReleasableMutexLock(Mutex* absl_nonnull mu, const Condition& cond)
ABSL_EXCLUSIVE_LOCK_FUNCTION(mu)
: ReleasableMutexLock(*mu, cond) {}
diff --git a/ci/linux_arm_clang-latest_libcxx_bazel.sh b/ci/linux_arm_clang-latest_libcxx_bazel.sh
index 631a8bd..5ad9fcc 100755
--- a/ci/linux_arm_clang-latest_libcxx_bazel.sh
+++ b/ci/linux_arm_clang-latest_libcxx_bazel.sh
@@ -88,6 +88,7 @@
--features=external_include_paths \
--keep_going \
--linkopt=-stdlib=libc++ \
+ --per_file_copt=external/.*@-w \
--show_timestamps \
--test_env=\"GTEST_INSTALL_FAILURE_SIGNAL_HANDLER=1\" \
--test_env=\"TZDIR=/abseil-cpp/absl/time/internal/cctz/testdata/zoneinfo\" \
diff --git a/ci/linux_clang-latest_libcxx_asan_bazel.sh b/ci/linux_clang-latest_libcxx_asan_bazel.sh
index cea10ff..1200ef0 100755
--- a/ci/linux_clang-latest_libcxx_asan_bazel.sh
+++ b/ci/linux_clang-latest_libcxx_asan_bazel.sh
@@ -93,6 +93,7 @@
--keep_going \
--linkopt=\"-fsanitize=address\" \
--linkopt=\"-fsanitize-link-c++-runtime\" \
+ --per_file_copt=external/.*@-w \
--show_timestamps \
--test_env=\"ASAN_SYMBOLIZER_PATH=/opt/llvm/clang/bin/llvm-symbolizer\" \
--test_env=\"TZDIR=/abseil-cpp/absl/time/internal/cctz/testdata/zoneinfo\" \
diff --git a/ci/linux_clang-latest_libcxx_bazel.sh b/ci/linux_clang-latest_libcxx_bazel.sh
index 5c51d15..74af10c 100755
--- a/ci/linux_clang-latest_libcxx_bazel.sh
+++ b/ci/linux_clang-latest_libcxx_bazel.sh
@@ -89,6 +89,7 @@
--enable_bzlmod=true \
--features=external_include_paths \
--keep_going \
+ --per_file_copt=external/.*@-w \
--show_timestamps \
--test_env=\"GTEST_INSTALL_FAILURE_SIGNAL_HANDLER=1\" \
--test_env=\"TZDIR=/abseil-cpp/absl/time/internal/cctz/testdata/zoneinfo\" \
diff --git a/ci/linux_clang-latest_libcxx_tsan_bazel.sh b/ci/linux_clang-latest_libcxx_tsan_bazel.sh
index c9ea22d..8634e8d 100755
--- a/ci/linux_clang-latest_libcxx_tsan_bazel.sh
+++ b/ci/linux_clang-latest_libcxx_tsan_bazel.sh
@@ -87,6 +87,7 @@
--features=external_include_paths \
--keep_going \
--linkopt=\"-fsanitize=thread\" \
+ --per_file_copt=external/.*@-w \
--show_timestamps \
--test_env=\"TSAN_SYMBOLIZER_PATH=/opt/llvm/clang/bin/llvm-symbolizer\" \
--test_env=\"TZDIR=/abseil-cpp/absl/time/internal/cctz/testdata/zoneinfo\" \
diff --git a/ci/linux_clang-latest_libstdcxx_bazel.sh b/ci/linux_clang-latest_libstdcxx_bazel.sh
index a1620e0..3175e41 100755
--- a/ci/linux_clang-latest_libstdcxx_bazel.sh
+++ b/ci/linux_clang-latest_libstdcxx_bazel.sh
@@ -85,6 +85,7 @@
--features=external_include_paths \
--keep_going \
--linkopt=\"--gcc-toolchain=/usr/local\" \
+ --per_file_copt=external/.*@-w \
--show_timestamps \
--test_env=\"GTEST_INSTALL_FAILURE_SIGNAL_HANDLER=1\" \
--test_env=\"TZDIR=/abseil-cpp/absl/time/internal/cctz/testdata/zoneinfo\" \
diff --git a/ci/linux_gcc-floor_libstdcxx_bazel.sh b/ci/linux_gcc-floor_libstdcxx_bazel.sh
index b683b60..0ee412d 100755
--- a/ci/linux_gcc-floor_libstdcxx_bazel.sh
+++ b/ci/linux_gcc-floor_libstdcxx_bazel.sh
@@ -81,6 +81,7 @@
--define=\"absl=1\" \
--features=external_include_paths \
--keep_going \
+ --per_file_copt=external/.*@-w \
--show_timestamps \
--test_env=\"GTEST_INSTALL_FAILURE_SIGNAL_HANDLER=1\" \
--test_env=\"TZDIR=/abseil-cpp/absl/time/internal/cctz/testdata/zoneinfo\" \
diff --git a/ci/linux_gcc-latest_libstdcxx_bazel.sh b/ci/linux_gcc-latest_libstdcxx_bazel.sh
index b092c1d..6e9b5ec 100755
--- a/ci/linux_gcc-latest_libstdcxx_bazel.sh
+++ b/ci/linux_gcc-latest_libstdcxx_bazel.sh
@@ -87,6 +87,7 @@
--enable_bzlmod=true \
--features=external_include_paths \
--keep_going \
+ --per_file_copt=external/.*@-w \
--show_timestamps \
--test_env=\"GTEST_INSTALL_FAILURE_SIGNAL_HANDLER=1\" \
--test_env=\"TZDIR=/abseil-cpp/absl/time/internal/cctz/testdata/zoneinfo\" \
diff --git a/ci/macos_xcode_bazel.sh b/ci/macos_xcode_bazel.sh
index 4e73847..a09b405 100755
--- a/ci/macos_xcode_bazel.sh
+++ b/ci/macos_xcode_bazel.sh
@@ -61,6 +61,7 @@
--enable_bzlmod=true \
--features=external_include_paths \
--keep_going \
+ --per_file_copt=external/.*@-w \
--show_timestamps \
--test_env="TZDIR=${ABSEIL_ROOT}/absl/time/internal/cctz/testdata/zoneinfo" \
--test_output=errors \
diff --git a/ci/windows_clangcl_bazel.bat b/ci/windows_clangcl_bazel.bat
index 26fd5af..94d27aa 100755
--- a/ci/windows_clangcl_bazel.bat
+++ b/ci/windows_clangcl_bazel.bat
@@ -59,6 +59,7 @@
--extra_execution_platforms=//:x64_windows-clang-cl ^
--extra_toolchains=@local_config_cc//:cc-toolchain-x64_windows-clang-cl ^
--keep_going ^
+ --per_file_copt=external/.*@/w ^
--test_env="GTEST_INSTALL_FAILURE_SIGNAL_HANDLER=1" ^
--test_env=TZDIR="%CD%\absl\time\internal\cctz\testdata\zoneinfo" ^
--test_output=errors ^
diff --git a/ci/windows_msvc_bazel.bat b/ci/windows_msvc_bazel.bat
index bbb57b4..6318ff1 100755
--- a/ci/windows_msvc_bazel.bat
+++ b/ci/windows_msvc_bazel.bat
@@ -50,6 +50,7 @@
--define=absl=1 ^
--enable_bzlmod=true ^
--keep_going ^
+ --per_file_copt=external/.*@/w ^
--test_env="GTEST_INSTALL_FAILURE_SIGNAL_HANDLER=1" ^
--test_env=TZDIR="%CD%\absl\time\internal\cctz\testdata\zoneinfo" ^
--test_output=errors ^