[context] Move `Call` context to arena context (#36775)
Closes #36775
COPYBARA_INTEGRATE_REVIEW=https://github.com/grpc/grpc/pull/36775 from ctiller:ctx1 3ca1d76da10a4076b37e63bb50e5789a076e254d
PiperOrigin-RevId: 639173227
diff --git a/src/core/client_channel/client_channel_filter.cc b/src/core/client_channel/client_channel_filter.cc
index 5eceb72..9f935dc 100644
--- a/src/core/client_channel/client_channel_filter.cc
+++ b/src/core/client_channel/client_channel_filter.cc
@@ -269,8 +269,7 @@
void ResetDeadline(Duration timeout) override {
const Timestamp per_method_deadline =
Timestamp::FromCycleCounterRoundUp(call_start_time_) + timeout;
- static_cast<Call*>(call_context_[GRPC_CONTEXT_CALL].value)
- ->UpdateDeadline(per_method_deadline);
+ arena_->GetContext<Call>()->UpdateDeadline(per_method_deadline);
}
void CreateDynamicCall();
@@ -3320,10 +3319,7 @@
grpc_status_code code;
std::string message;
grpc_error_get_status(
- error,
- static_cast<Call*>(self->call_context()[GRPC_CONTEXT_CALL].value)
- ->deadline(),
- &code, &message,
+ error, self->arena()->GetContext<Call>()->deadline(), &code, &message,
/*http_error=*/nullptr, /*error_string=*/nullptr);
status = absl::Status(static_cast<absl::StatusCode>(code), message);
} else {
@@ -3462,8 +3458,7 @@
CHECK_NE(path, nullptr);
SubchannelCall::Args call_args = {
connected_subchannel()->Ref(), pollent_, path->Ref(), /*start_time=*/0,
- static_cast<Call*>(call_context()[GRPC_CONTEXT_CALL].value)->deadline(),
- arena(),
+ arena()->GetContext<Call>()->deadline(), arena(),
// TODO(roth): When we implement hedging support, we will probably
// need to use a separate call context for each subchannel call.
call_context(), call_combiner_};
diff --git a/src/core/lib/channel/context.h b/src/core/lib/channel/context.h
index 632c6b5..6432efb 100644
--- a/src/core/lib/channel/context.h
+++ b/src/core/lib/channel/context.h
@@ -29,9 +29,6 @@
/// This enum represents the indexes into the array, where each index
/// contains a different type of value.
typedef enum {
- /// grpc_call* associated with this context.
- GRPC_CONTEXT_CALL = 0,
-
/// Holds a pointer to ServiceConfigCallData associated with this call.
GRPC_CONTEXT_SERVICE_CONFIG_CALL_DATA,
@@ -48,7 +45,6 @@
};
namespace grpc_core {
-class Call;
class ServiceConfigCallData;
// Bind the legacy context array into the new style structure
@@ -63,11 +59,6 @@
struct OldStyleContext;
template <>
-struct OldStyleContext<Call> {
- static constexpr grpc_context_index kIndex = GRPC_CONTEXT_CALL;
-};
-
-template <>
struct OldStyleContext<ServiceConfigCallData> {
static constexpr grpc_context_index kIndex =
GRPC_CONTEXT_SERVICE_CONFIG_CALL_DATA;
diff --git a/src/core/lib/surface/call.cc b/src/core/lib/surface/call.cc
index 8c8bc45..00f424b 100644
--- a/src/core/lib/surface/call.cc
+++ b/src/core/lib/surface/call.cc
@@ -602,7 +602,7 @@
args.send_deadline, args.channel->Ref()),
cq_(args.cq),
stream_op_payload_(context_) {
- context_[GRPC_CONTEXT_CALL].value = this;
+ GetArena()->SetContext<Call>(this);
}
static void ReleaseCall(void* call, grpc_error_handle);
@@ -1917,7 +1917,7 @@
if (args.cq != nullptr) {
GRPC_CQ_INTERNAL_REF(args.cq, "bind");
}
- context_[GRPC_CONTEXT_CALL].value = this;
+ GetArena()->SetContext<Call>(this);
}
~BasicPromiseBasedCall() override {
@@ -3173,8 +3173,7 @@
client_initial_metadata_stored_(std::move(client_initial_metadata)),
cq_(cq),
server_(server) {
- call_handler_.legacy_context()[GRPC_CONTEXT_CALL].value =
- static_cast<Call*>(this);
+ call_handler_.arena()->SetContext<Call>(this);
global_stats().IncrementServerCallsCreated();
}
diff --git a/src/core/lib/surface/call.h b/src/core/lib/surface/call.h
index 917881f..12c214c 100644
--- a/src/core/lib/surface/call.h
+++ b/src/core/lib/surface/call.h
@@ -246,6 +246,11 @@
gpr_cycle_counter start_time_ = gpr_get_cycle_counter();
};
+template <>
+struct ArenaContextType<Call> {
+ static void Destroy(Call*) {}
+};
+
class BasicPromiseBasedCall;
class ServerPromiseBasedCall;