diff --git a/src/cpp/server/external_connection_acceptor_impl.cc b/src/cpp/server/external_connection_acceptor_impl.cc index 7f0e2dcfe93..e03d3c6cc2c 100644 --- a/src/cpp/server/external_connection_acceptor_impl.cc +++ b/src/cpp/server/external_connection_acceptor_impl.cc @@ -52,7 +52,7 @@ ExternalConnectionAcceptorImpl::ExternalConnectionAcceptorImpl( std::unique_ptr ExternalConnectionAcceptorImpl::GetAcceptor() { - std::lock_guard lock(mu_); + grpc_core::MutexLock lock(&mu_); GPR_ASSERT(!has_acceptor_); has_acceptor_ = true; return std::unique_ptr( @@ -61,7 +61,7 @@ ExternalConnectionAcceptorImpl::GetAcceptor() { void ExternalConnectionAcceptorImpl::HandleNewConnection( experimental::ExternalConnectionAcceptor::NewConnectionParameters* p) { - std::lock_guard lock(mu_); + grpc_core::MutexLock lock(&mu_); if (shutdown_ || !started_) { // TODO(yangg) clean up. gpr_log( @@ -76,12 +76,12 @@ void ExternalConnectionAcceptorImpl::HandleNewConnection( } void ExternalConnectionAcceptorImpl::Shutdown() { - std::lock_guard lock(mu_); + grpc_core::MutexLock lock(&mu_); shutdown_ = true; } void ExternalConnectionAcceptorImpl::Start() { - std::lock_guard lock(mu_); + grpc_core::MutexLock lock(&mu_); GPR_ASSERT(!started_); GPR_ASSERT(has_acceptor_); GPR_ASSERT(!shutdown_); diff --git a/src/cpp/server/external_connection_acceptor_impl.h b/src/cpp/server/external_connection_acceptor_impl.h index b5bd935c784..a5459509a81 100644 --- a/src/cpp/server/external_connection_acceptor_impl.h +++ b/src/cpp/server/external_connection_acceptor_impl.h @@ -20,7 +20,6 @@ #define SRC_CPP_SERVER_EXTERNAL_CONNECTION_ACCEPTOR_IMPL_H_ #include -#include #include #include @@ -28,6 +27,7 @@ #include #include +#include "src/core/lib/gprpp/sync.h" #include "src/core/lib/iomgr/tcp_server.h" namespace grpc { @@ -60,7 +60,7 @@ class ExternalConnectionAcceptorImpl const grpc::string name_; std::shared_ptr creds_; grpc_core::TcpServerFdHandler* handler_ = nullptr; // not owned - std::mutex mu_; + grpc_core::Mutex mu_; bool has_acceptor_ = false; bool started_ = false; bool shutdown_ = false; diff --git a/tools/run_tests/sanity/cpp_banned_constructs.sh b/tools/run_tests/sanity/cpp_banned_constructs.sh new file mode 100755 index 00000000000..55cf252d827 --- /dev/null +++ b/tools/run_tests/sanity/cpp_banned_constructs.sh @@ -0,0 +1,31 @@ +#!/bin/sh +# Copyright 2019 gRPC authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +set -e + +cd "$(dirname "$0")/../../.." + +# +# Prevent the use of synchronization and threading constructs from std:: since +# the code should be using grpc_core::Mutex, grpc::internal::Mutex, +# grpc_core::Thread, etc. +# + +egrep -Irn \ + 'std::(mutex|condition_variable|lock_guard|unique_lock|thread)' \ + include/grpc include/grpcpp src/core src/cpp | \ + egrep -v include/grpcpp/impl/codegen/sync.h | \ + diff - /dev/null + diff --git a/tools/run_tests/sanity/sanity_tests.yaml b/tools/run_tests/sanity/sanity_tests.yaml index a994aae1330..93aa516f2d6 100644 --- a/tools/run_tests/sanity/sanity_tests.yaml +++ b/tools/run_tests/sanity/sanity_tests.yaml @@ -13,6 +13,7 @@ - script: tools/run_tests/sanity/check_tracer_sanity.py - script: tools/run_tests/sanity/core_banned_functions.py - script: tools/run_tests/sanity/core_untyped_structs.sh +- script: tools/run_tests/sanity/cpp_banned_constructs.sh - script: tools/buildgen/generate_projects.sh -j 3 cpu_cost: 3 - script: tools/distrib/check_copyright.py