Skip to content

Commit

Permalink
Add abseil thread annotations to grpcpp/sync (grpc#25560)
Browse files Browse the repository at this point in the history
* Add abseil annotation to grpcpp/sync
* Bump alpine linux to 3.11 from 3.9
  • Loading branch information
veblush authored Mar 3, 2021
1 parent 26e4c14 commit f862a22
Show file tree
Hide file tree
Showing 12 changed files with 70 additions and 33 deletions.
7 changes: 7 additions & 0 deletions BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,7 @@ grpc_cc_library(
name = "grpc++_public_hdrs",
hdrs = GRPCXX_PUBLIC_HDRS,
external_deps = [
"absl/synchronization",
"protobuf_headers",
],
)
Expand All @@ -376,6 +377,7 @@ grpc_cc_library(
"src/cpp/server/secure_server_credentials.h",
],
external_deps = [
"absl/synchronization",
"protobuf_headers",
],
language = "c++",
Expand Down Expand Up @@ -515,6 +517,9 @@ grpc_cc_library(
hdrs = [
"include/grpcpp/impl/codegen/sync.h",
],
external_deps = [
"absl/synchronization",
],
language = "c++",
deps = [
"gpr_codegen",
Expand Down Expand Up @@ -2303,6 +2308,7 @@ grpc_cc_library(
srcs = GRPCXX_SRCS,
hdrs = GRPCXX_HDRS,
external_deps = [
"absl/synchronization",
"protobuf_headers",
],
language = "c++",
Expand All @@ -2320,6 +2326,7 @@ grpc_cc_library(
srcs = GRPCXX_SRCS,
hdrs = GRPCXX_HDRS,
external_deps = [
"absl/synchronization",
"protobuf_headers",
],
language = "c++",
Expand Down
1 change: 1 addition & 0 deletions BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -1513,6 +1513,7 @@ config("grpc_config") {
":gpr",
":address_sorting",
":upb",
":absl/synchronization:synchronization",
]

public_configs = [
Expand Down
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2784,6 +2784,7 @@ target_link_libraries(grpc++
gpr
address_sorting
upb
absl::synchronization
)

foreach(_hdr
Expand Down Expand Up @@ -3446,6 +3447,7 @@ target_link_libraries(grpc++_unsecure
gpr
address_sorting
upb
absl::synchronization
)

foreach(_hdr
Expand Down
2 changes: 2 additions & 0 deletions build_autogenerated.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2377,6 +2377,7 @@ libs:
- gpr
- address_sorting
- upb
- absl/synchronization:synchronization
baselib: true
- name: grpc++_alts
build: all
Expand Down Expand Up @@ -2728,6 +2729,7 @@ libs:
- gpr
- address_sorting
- upb
- absl/synchronization:synchronization
baselib: true
secure: false
- name: grpc_plugin_support
Expand Down
2 changes: 2 additions & 0 deletions grpc.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -1399,6 +1399,7 @@
'gpr',
'address_sorting',
'upb',
'absl/synchronization:synchronization',
],
'sources': [
'src/cpp/client/channel_cc.cc',
Expand Down Expand Up @@ -1555,6 +1556,7 @@
'gpr',
'address_sorting',
'upb',
'absl/synchronization:synchronization',
],
'sources': [
'src/cpp/client/channel_cc.cc',
Expand Down
31 changes: 19 additions & 12 deletions include/grpcpp/impl/codegen/sync.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@

#include <grpcpp/impl/codegen/core_codegen_interface.h>

#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.
Expand All @@ -57,16 +55,20 @@ 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_); }

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 {
Expand All @@ -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;
Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 ${'\\'}
Expand All @@ -32,21 +32,21 @@
make ${'\\'}
perl ${'\\'}
strace ${'\\'}
python-dev ${'\\'}
py-pip ${'\\'}
py-yaml ${'\\'}
python2-dev ${'\\'}
py2-pip ${'\\'}
unzip ${'\\'}
wget ${'\\'}
zip

# 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.
Expand Down
8 changes: 8 additions & 0 deletions test/distrib/cpp/run_distrib_test_cmake_module_install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,21 @@ 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"
cmake \
-DCMAKE_BUILD_TYPE=Release \
-DgRPC_INSTALL=ON \
-DgRPC_BUILD_TESTS=OFF \
-DgRPC_ABSL_PROVIDER=package \
-DgRPC_SSL_PROVIDER=package \
../..
make -j4 install
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,21 @@ 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"
cmake \
-DCMAKE_BUILD_TYPE=Release \
-DgRPC_INSTALL=ON \
-DgRPC_BUILD_TESTS=OFF \
-DgRPC_ABSL_PROVIDER=package \
-DgRPC_SSL_PROVIDER=package \
../..
make -j4 install
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
12 changes: 6 additions & 6 deletions tools/dockerfile/test/cxx_alpine_x64/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand All @@ -30,20 +30,20 @@ RUN apk update && apk add \
make \
perl \
strace \
python-dev \
py-pip \
py-yaml \
python2-dev \
py2-pip \
unzip \
wget \
zip

# 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
Expand Down
10 changes: 5 additions & 5 deletions tools/dockerfile/test/python_alpine_x64/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand All @@ -30,19 +30,19 @@ RUN apk update && apk add \
make \
perl \
strace \
python-dev \
py-pip \
python2-dev \
py2-pip \
unzip \
wget \
zip

# 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

Expand Down

0 comments on commit f862a22

Please sign in to comment.