diff --git a/include/grpcpp/server.h b/include/grpcpp/server.h index d90f28dc1ce..7f367dc5988 100644 --- a/include/grpcpp/server.h +++ b/include/grpcpp/server.h @@ -58,13 +58,13 @@ class ExternalConnectionAcceptorImpl; /// \a Server instances. class Server : public ServerInterface, private GrpcLibraryCodegen { public: - ~Server() override; + ~Server() ABSL_LOCKS_EXCLUDED(mu_) override; /// Block until the server shuts down. /// /// \warning The server must be either shutting down or some other thread must /// call \a Shutdown for this function to ever return. - void Wait() override; + void Wait() ABSL_LOCKS_EXCLUDED(mu_) override; /// Global callbacks are a set of hooks that are called when server /// events occur. \a SetGlobalCallbacks method is used to register @@ -286,13 +286,14 @@ class Server : public ServerInterface, private GrpcLibraryCodegen { void PerformOpsOnCall(internal::CallOpSetInterface* ops, internal::Call* call) override; - void ShutdownInternal(gpr_timespec deadline) override; + void ShutdownInternal(gpr_timespec deadline) + ABSL_LOCKS_EXCLUDED(mu_) override; int max_receive_message_size() const override { return max_receive_message_size_; } - CompletionQueue* CallbackCQ() override; + CompletionQueue* CallbackCQ() ABSL_LOCKS_EXCLUDED(mu_) override; ServerInitializer* initializer(); @@ -300,8 +301,8 @@ class Server : public ServerInterface, private GrpcLibraryCodegen { // the ref count are the running state of the server (take a ref at start and // drop it at shutdown) and each running callback RPC. void Ref(); - void UnrefWithPossibleNotify() /* LOCKS_EXCLUDED(mu_) */; - void UnrefAndWaitLocked() /* EXCLUSIVE_LOCKS_REQUIRED(mu_) */; + void UnrefWithPossibleNotify() ABSL_LOCKS_EXCLUDED(mu_); + void UnrefAndWaitLocked() ABSL_EXCLUSIVE_LOCKS_REQUIRED(mu_); std::vector> acceptors_; @@ -335,10 +336,11 @@ class Server : public ServerInterface, private GrpcLibraryCodegen { // Server status internal::Mutex mu_; bool started_; - bool shutdown_; - bool shutdown_notified_; // Was notify called on the shutdown_cv_ + bool shutdown_ ABSL_GUARDED_BY(mu_); + bool shutdown_notified_ + ABSL_GUARDED_BY(mu_); // Was notify called on the shutdown_cv_ internal::CondVar shutdown_done_cv_; - bool shutdown_done_ = false; + bool shutdown_done_ ABSL_GUARDED_BY(mu_) = false; std::atomic_int shutdown_refs_outstanding_{1}; internal::CondVar shutdown_cv_; @@ -378,7 +380,7 @@ class Server : public ServerInterface, private GrpcLibraryCodegen { // with this server (if any). It is set on the first call to CallbackCQ(). // It is _not owned_ by the server; ownership belongs with its internal // shutdown callback tag (invoked when the CQ is fully shutdown). - CompletionQueue* callback_cq_ /* GUARDED_BY(mu_) */ = nullptr; + CompletionQueue* callback_cq_ ABSL_GUARDED_BY(mu_) = nullptr; // List of CQs passed in by user that must be Shutdown only after Server is // Shutdown. Even though this is only used with NDEBUG, instantiate it in all diff --git a/src/cpp/server/server_cc.cc b/src/cpp/server/server_cc.cc index e7859c7a953..2844bfa5137 100644 --- a/src/cpp/server/server_cc.cc +++ b/src/cpp/server/server_cc.cc @@ -1104,8 +1104,9 @@ void Server::UnrefAndWaitLocked() { shutdown_done_ = true; return; // no need to wait on CV since done condition already set } - grpc::internal::WaitUntil(&shutdown_done_cv_, &mu_, - [this] { return shutdown_done_; }); + grpc::internal::WaitUntil( + &shutdown_done_cv_, &mu_, + [this]() ABSL_EXCLUSIVE_LOCKS_REQUIRED(mu_) { return shutdown_done_; }); } void Server::Start(grpc::ServerCompletionQueue** cqs, size_t num_cqs) {