Merge pull request #23223 from grpc/vjpai-patch-1-1

Avoid a use of ReleasableMutexLock
pull/23230/head
Vijay Pai 5 years ago committed by GitHub
commit a2a1ca3281
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 55
      src/cpp/server/server_context.cc

@ -174,31 +174,32 @@ void ServerContextBase::CompletionOp::FillOps(::grpc::internal::Call* call) {
} }
bool ServerContextBase::CompletionOp::FinalizeResult(void** tag, bool* status) { bool ServerContextBase::CompletionOp::FinalizeResult(void** tag, bool* status) {
bool ret = false; // Decide whether to call the cancel callback within the lock
grpc_core::ReleasableMutexLock lock(&mu_); bool call_cancel;
if (done_intercepting_) {
/* We are done intercepting. */
if (has_tag_) {
*tag = tag_;
ret = true;
}
Unref();
return ret;
}
finalized_ = true;
// If for some reason the incoming status is false, mark that as a {
// cancellation. grpc_core::MutexLock lock(&mu_);
// TODO(vjpai): does this ever happen? if (done_intercepting_) {
if (!*status) { // We are done intercepting.
cancelled_ = 1; bool has_tag = has_tag_;
} if (has_tag) {
*tag = tag_;
}
Unref();
return has_tag;
}
finalized_ = true;
// Decide whether to call the cancel callback before releasing the lock // If for some reason the incoming status is false, mark that as a
bool call_cancel = (cancelled_ != 0); // cancellation.
// TODO(vjpai): does this ever happen?
if (!*status) {
cancelled_ = 1;
}
// Release the lock since we may call a callback and interceptors now. call_cancel = (cancelled_ != 0);
lock.Unlock(); // Release the lock since we may call a callback and interceptors.
}
if (call_cancel && callback_controller_ != nullptr) { if (call_cancel && callback_controller_ != nullptr) {
callback_controller_->MaybeCallOnCancel(); callback_controller_->MaybeCallOnCancel();
@ -207,15 +208,15 @@ bool ServerContextBase::CompletionOp::FinalizeResult(void** tag, bool* status) {
interceptor_methods_.AddInterceptionHookPoint( interceptor_methods_.AddInterceptionHookPoint(
::grpc::experimental::InterceptionHookPoints::POST_RECV_CLOSE); ::grpc::experimental::InterceptionHookPoints::POST_RECV_CLOSE);
if (interceptor_methods_.RunInterceptors()) { if (interceptor_methods_.RunInterceptors()) {
/* No interceptors were run */ // No interceptors were run
if (has_tag_) { bool has_tag = has_tag_;
if (has_tag) {
*tag = tag_; *tag = tag_;
ret = true;
} }
Unref(); Unref();
return ret; return has_tag;
} }
/* There are interceptors to be run. Return false for now */ // There are interceptors to be run. Return false for now.
return false; return false;
} }

Loading…
Cancel
Save