From f862a2259f0816b9f7b86980d4ab27cc773d590a Mon Sep 17 00:00:00 2001 From: Esun Kim Date: Wed, 3 Mar 2021 08:39:20 -0800 Subject: [PATCH] Add abseil thread annotations to grpcpp/sync (#25560) * Add abseil annotation to grpcpp/sync * Bump alpine linux to 3.11 from 3.9 --- BUILD | 7 +++++ BUILD.gn | 1 + CMakeLists.txt | 2 ++ build_autogenerated.yaml | 2 ++ grpc.gyp | 2 ++ include/grpcpp/impl/codegen/sync.h | 31 ++++++++++++------- .../test/cxx_alpine_x64/Dockerfile.template | 16 +++++----- .../run_distrib_test_cmake_module_install.sh | 8 +++++ ...rib_test_cmake_module_install_pkgconfig.sh | 8 +++++ .../python_dev_alpine3.7_x64/Dockerfile | 4 +-- .../dockerfile/test/cxx_alpine_x64/Dockerfile | 12 +++---- .../test/python_alpine_x64/Dockerfile | 10 +++--- 12 files changed, 70 insertions(+), 33 deletions(-) diff --git a/BUILD b/BUILD index 778b365ff04e2..a9ed766c520a0 100644 --- a/BUILD +++ b/BUILD @@ -350,6 +350,7 @@ grpc_cc_library( name = "grpc++_public_hdrs", hdrs = GRPCXX_PUBLIC_HDRS, external_deps = [ + "absl/synchronization", "protobuf_headers", ], ) @@ -376,6 +377,7 @@ grpc_cc_library( "src/cpp/server/secure_server_credentials.h", ], external_deps = [ + "absl/synchronization", "protobuf_headers", ], language = "c++", @@ -515,6 +517,9 @@ grpc_cc_library( hdrs = [ "include/grpcpp/impl/codegen/sync.h", ], + external_deps = [ + "absl/synchronization", + ], language = "c++", deps = [ "gpr_codegen", @@ -2303,6 +2308,7 @@ grpc_cc_library( srcs = GRPCXX_SRCS, hdrs = GRPCXX_HDRS, external_deps = [ + "absl/synchronization", "protobuf_headers", ], language = "c++", @@ -2320,6 +2326,7 @@ grpc_cc_library( srcs = GRPCXX_SRCS, hdrs = GRPCXX_HDRS, external_deps = [ + "absl/synchronization", "protobuf_headers", ], language = "c++", diff --git a/BUILD.gn b/BUILD.gn index ddaeda866440b..89ab85273fde6 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -1513,6 +1513,7 @@ config("grpc_config") { ":gpr", ":address_sorting", ":upb", + ":absl/synchronization:synchronization", ] public_configs = [ diff --git a/CMakeLists.txt b/CMakeLists.txt index 650d9a9976e50..2f64c475146bb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2784,6 +2784,7 @@ target_link_libraries(grpc++ gpr address_sorting upb + absl::synchronization ) foreach(_hdr @@ -3446,6 +3447,7 @@ target_link_libraries(grpc++_unsecure gpr address_sorting upb + absl::synchronization ) foreach(_hdr diff --git a/build_autogenerated.yaml b/build_autogenerated.yaml index 715b9cc5bb4e9..2e7c4fa7d48b0 100644 --- a/build_autogenerated.yaml +++ b/build_autogenerated.yaml @@ -2377,6 +2377,7 @@ libs: - gpr - address_sorting - upb + - absl/synchronization:synchronization baselib: true - name: grpc++_alts build: all @@ -2728,6 +2729,7 @@ libs: - gpr - address_sorting - upb + - absl/synchronization:synchronization baselib: true secure: false - name: grpc_plugin_support diff --git a/grpc.gyp b/grpc.gyp index 15b2d727c384b..70a6e72ff214b 100644 --- a/grpc.gyp +++ b/grpc.gyp @@ -1399,6 +1399,7 @@ 'gpr', 'address_sorting', 'upb', + 'absl/synchronization:synchronization', ], 'sources': [ 'src/cpp/client/channel_cc.cc', @@ -1555,6 +1556,7 @@ 'gpr', 'address_sorting', 'upb', + 'absl/synchronization:synchronization', ], 'sources': [ 'src/cpp/client/channel_cc.cc', diff --git a/include/grpcpp/impl/codegen/sync.h b/include/grpcpp/impl/codegen/sync.h index 3731a4eba5775..0c4effe4b0d0c 100644 --- a/include/grpcpp/impl/codegen/sync.h +++ b/include/grpcpp/impl/codegen/sync.h @@ -32,9 +32,7 @@ #include -#ifdef GRPCPP_ABSEIL_SYNC #include "absl/synchronization/mutex.h" -#endif // The core library is not accessible in C++ codegen headers, and vice versa. // Thus, we need to have duplicate headers with similar functionality. @@ -57,7 +55,7 @@ using CondVar = absl::CondVar; #else -class Mutex { +class ABSL_LOCKABLE Mutex { public: Mutex() { g_core_codegen_interface->gpr_mu_init(&mu_); } ~Mutex() { g_core_codegen_interface->gpr_mu_destroy(&mu_); } @@ -65,8 +63,12 @@ class Mutex { Mutex(const Mutex&) = delete; Mutex& operator=(const Mutex&) = delete; - void Lock() { g_core_codegen_interface->gpr_mu_lock(&mu_); } - void Unlock() { g_core_codegen_interface->gpr_mu_unlock(&mu_); } + void Lock() ABSL_EXCLUSIVE_LOCK_FUNCTION() { + g_core_codegen_interface->gpr_mu_lock(&mu_); + } + void Unlock() ABSL_UNLOCK_FUNCTION() { + g_core_codegen_interface->gpr_mu_unlock(&mu_); + } private: union { @@ -80,10 +82,12 @@ class Mutex { friend class CondVar; }; -class MutexLock { +class ABSL_SCOPED_LOCKABLE MutexLock { public: - explicit MutexLock(Mutex* mu) : mu_(mu) { mu_->Lock(); } - ~MutexLock() { mu_->Unlock(); } + explicit MutexLock(Mutex* mu) ABSL_EXCLUSIVE_LOCK_FUNCTION(mu) : mu_(mu) { + mu_->Lock(); + } + ~MutexLock() ABSL_UNLOCK_FUNCTION() { mu_->Unlock(); } MutexLock(const MutexLock&) = delete; MutexLock& operator=(const MutexLock&) = delete; @@ -92,17 +96,20 @@ class MutexLock { Mutex* const mu_; }; -class ReleasableMutexLock { +class ABSL_SCOPED_LOCKABLE ReleasableMutexLock { public: - explicit ReleasableMutexLock(Mutex* mu) : mu_(mu) { mu_->Lock(); } - ~ReleasableMutexLock() { + explicit ReleasableMutexLock(Mutex* mu) ABSL_EXCLUSIVE_LOCK_FUNCTION(mu) + : mu_(mu) { + mu_->Lock(); + } + ~ReleasableMutexLock() ABSL_UNLOCK_FUNCTION() { if (!released_) mu_->Unlock(); } ReleasableMutexLock(const ReleasableMutexLock&) = delete; ReleasableMutexLock& operator=(const ReleasableMutexLock&) = delete; - void Release() { + void Release() ABSL_UNLOCK_FUNCTION() { GPR_DEBUG_ASSERT(!released_); released_ = true; mu_->Unlock(); diff --git a/templates/tools/dockerfile/test/cxx_alpine_x64/Dockerfile.template b/templates/tools/dockerfile/test/cxx_alpine_x64/Dockerfile.template index ffa416960fe2e..966d94b6db428 100644 --- a/templates/tools/dockerfile/test/cxx_alpine_x64/Dockerfile.template +++ b/templates/tools/dockerfile/test/cxx_alpine_x64/Dockerfile.template @@ -14,7 +14,7 @@ # See the License for the specific language governing permissions and # limitations under the License. - FROM alpine:3.9 + FROM alpine:3.11 # Install Git and basic packages. RUN apk update && apk add ${'\\'} @@ -32,9 +32,8 @@ make ${'\\'} perl ${'\\'} strace ${'\\'} - python-dev ${'\\'} - py-pip ${'\\'} - py-yaml ${'\\'} + python2-dev ${'\\'} + py2-pip ${'\\'} unzip ${'\\'} wget ${'\\'} zip @@ -42,11 +41,12 @@ # Install Python packages from PyPI RUN pip install --upgrade pip==19.3.1 RUN pip install virtualenv - RUN pip install futures==2.2.0 enum34==1.0.4 protobuf==3.5.0.post1 six==1.15.0 twisted==17.5.0 - + RUN pip install futures==2.2.0 enum34==1.0.4 protobuf==3.5.2.post1 six==1.15.0 twisted==17.5.0 + RUN pip install --upgrade --ignore-installed PyYAML==5.4.1 --user + # Google Cloud platform API libraries - RUN pip install --upgrade google-api-python-client - + RUN pip install --upgrade google-auth==1.24.0 google-api-python-client==1.12.8 oauth2client==4.1.0 + <%include file="../../run_tests_addons.include"/> # Define the default command. diff --git a/test/distrib/cpp/run_distrib_test_cmake_module_install.sh b/test/distrib/cpp/run_distrib_test_cmake_module_install.sh index 96e63b187a66c..b669b993eb00b 100755 --- a/test/distrib/cpp/run_distrib_test_cmake_module_install.sh +++ b/test/distrib/cpp/run_distrib_test_cmake_module_install.sh @@ -26,6 +26,13 @@ wget -q -O cmake-linux.sh https://github.com/Kitware/CMake/releases/download/v3. sh cmake-linux.sh -- --skip-license --prefix=/usr rm cmake-linux.sh +# Install absl (absl won't be installed down below) +mkdir -p "third_party/abseil-cpp/cmake/build" +pushd "third_party/abseil-cpp/cmake/build" +cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_POSITION_INDEPENDENT_CODE=TRUE ../.. +make -j4 install +popd + # Install gRPC and its dependencies mkdir -p "cmake/build" pushd "cmake/build" @@ -33,6 +40,7 @@ cmake \ -DCMAKE_BUILD_TYPE=Release \ -DgRPC_INSTALL=ON \ -DgRPC_BUILD_TESTS=OFF \ + -DgRPC_ABSL_PROVIDER=package \ -DgRPC_SSL_PROVIDER=package \ ../.. make -j4 install diff --git a/test/distrib/cpp/run_distrib_test_cmake_module_install_pkgconfig.sh b/test/distrib/cpp/run_distrib_test_cmake_module_install_pkgconfig.sh index ab61f1696217d..fd08da63a2acf 100755 --- a/test/distrib/cpp/run_distrib_test_cmake_module_install_pkgconfig.sh +++ b/test/distrib/cpp/run_distrib_test_cmake_module_install_pkgconfig.sh @@ -26,6 +26,13 @@ wget -q -O cmake-linux.sh https://github.com/Kitware/CMake/releases/download/v3. sh cmake-linux.sh -- --skip-license --prefix=/usr rm cmake-linux.sh +# Install absl (absl won't be installed down below) +mkdir -p "third_party/abseil-cpp/cmake/build" +pushd "third_party/abseil-cpp/cmake/build" +cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_POSITION_INDEPENDENT_CODE=TRUE ../.. +make -j4 install +popd + # Install gRPC and its dependencies mkdir -p "cmake/build" pushd "cmake/build" @@ -33,6 +40,7 @@ cmake \ -DCMAKE_BUILD_TYPE=Release \ -DgRPC_INSTALL=ON \ -DgRPC_BUILD_TESTS=OFF \ + -DgRPC_ABSL_PROVIDER=package \ -DgRPC_SSL_PROVIDER=package \ ../.. make -j4 install diff --git a/tools/dockerfile/distribtest/python_dev_alpine3.7_x64/Dockerfile b/tools/dockerfile/distribtest/python_dev_alpine3.7_x64/Dockerfile index a208ae05204bf..b51cad937b2a8 100644 --- a/tools/dockerfile/distribtest/python_dev_alpine3.7_x64/Dockerfile +++ b/tools/dockerfile/distribtest/python_dev_alpine3.7_x64/Dockerfile @@ -12,9 +12,9 @@ # See the License for the specific language governing permissions and # limitations under the License. -FROM alpine:3.9 +FROM alpine:3.11 -RUN apk add --update build-base linux-headers python python-dev py-pip +RUN apk add --update build-base linux-headers python python2-dev py2-pip RUN pip install --upgrade pip==19.3.1 diff --git a/tools/dockerfile/test/cxx_alpine_x64/Dockerfile b/tools/dockerfile/test/cxx_alpine_x64/Dockerfile index cfff38eec5cfd..7bd7eede493f7 100644 --- a/tools/dockerfile/test/cxx_alpine_x64/Dockerfile +++ b/tools/dockerfile/test/cxx_alpine_x64/Dockerfile @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -FROM alpine:3.9 +FROM alpine:3.11 # Install Git and basic packages. RUN apk update && apk add \ @@ -30,9 +30,8 @@ RUN apk update && apk add \ make \ perl \ strace \ - python-dev \ - py-pip \ - py-yaml \ + python2-dev \ + py2-pip \ unzip \ wget \ zip @@ -40,10 +39,11 @@ RUN apk update && apk add \ # Install Python packages from PyPI RUN pip install --upgrade pip==19.3.1 RUN pip install virtualenv -RUN pip install futures==2.2.0 enum34==1.0.4 protobuf==3.5.0.post1 six==1.15.0 twisted==17.5.0 +RUN pip install futures==2.2.0 enum34==1.0.4 protobuf==3.5.2.post1 six==1.15.0 twisted==17.5.0 +RUN pip install --upgrade --ignore-installed PyYAML==5.4.1 --user # Google Cloud platform API libraries -RUN pip install --upgrade google-api-python-client +RUN pip install --upgrade google-auth==1.24.0 google-api-python-client==1.12.8 oauth2client==4.1.0 RUN mkdir /var/local/jenkins diff --git a/tools/dockerfile/test/python_alpine_x64/Dockerfile b/tools/dockerfile/test/python_alpine_x64/Dockerfile index b36b1343f147a..bf5f07a03b7ab 100644 --- a/tools/dockerfile/test/python_alpine_x64/Dockerfile +++ b/tools/dockerfile/test/python_alpine_x64/Dockerfile @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -FROM alpine:3.9 +FROM alpine:3.11 # Install Git and basic packages. RUN apk update && apk add \ @@ -30,8 +30,8 @@ RUN apk update && apk add \ make \ perl \ strace \ - python-dev \ - py-pip \ + python2-dev \ + py2-pip \ unzip \ wget \ zip @@ -39,10 +39,10 @@ RUN apk update && apk add \ # Install Python packages from PyPI RUN pip install --upgrade pip==19.3.1 RUN pip install virtualenv -RUN pip install futures==2.2.0 enum34==1.0.4 protobuf==3.5.0.post1 six==1.15.0 +RUN pip install futures==2.2.0 enum34==1.0.4 protobuf==3.5.2.post1 six==1.15.0 # Google Cloud platform API libraries -RUN pip install --upgrade google-api-python-client oauth2client +RUN pip install --upgrade google-auth==1.24.0 google-api-python-client==1.12.8 oauth2client==4.1.0 RUN mkdir -p /var/local/jenkins