diff options
author | 2017-10-13 16:07:13 -0700 | |
---|---|---|
committer | 2017-10-18 17:12:19 -0700 | |
commit | 0ee7574732a06e8cace4e099a678f4bd5dbff679 (patch) | |
tree | e43d5de442fdcc3d39cd5af687f319fa39612d3f /src/cpp/common/channel_filter.h | |
parent | 6bf5f833efe2cb9e2ecc14358dd9699cd5d05263 (diff) |
Removing instances of exec_ctx being passed around in functions in
src/core. exec_ctx is now a thread_local pointer of type ExecCtx instead of
grpc_exec_ctx which is initialized whenever ExecCtx is instantiated. ExecCtx
also keeps track of the previous exec_ctx so that nesting of exec_ctx is
allowed. This means that there is only one exec_ctx being used at any
time. Also, grpc_exec_ctx_finish is called in the destructor of the
object, and the previous exec_ctx is restored to avoid breaking current
functionality. The code still explicitly calls grpc_exec_ctx_finish
because removing all such instances causes the code to break.
Diffstat (limited to 'src/cpp/common/channel_filter.h')
-rw-r--r-- | src/cpp/common/channel_filter.h | 62 |
1 files changed, 25 insertions, 37 deletions
diff --git a/src/cpp/common/channel_filter.h b/src/cpp/common/channel_filter.h index c1aeb3f724..3adaae9d4b 100644 --- a/src/cpp/common/channel_filter.h +++ b/src/cpp/common/channel_filter.h @@ -56,8 +56,7 @@ class MetadataBatch { /// Adds metadata and returns the newly allocated storage. /// The caller takes ownership of the result, which must exist for the /// lifetime of the gRPC call. - grpc_linked_mdelem *AddMetadata(grpc_exec_ctx *exec_ctx, const string &key, - const string &value); + grpc_linked_mdelem *AddMetadata(const string &key, const string &value); class const_iterator : public std::iterator<std::bidirectional_iterator_tag, const grpc_mdelem> { @@ -225,18 +224,17 @@ class ChannelData { // TODO(roth): Come up with a more C++-like API for the channel element. /// Initializes the channel data. - virtual grpc_error *Init(grpc_exec_ctx *exec_ctx, grpc_channel_element *elem, + virtual grpc_error *Init(grpc_channel_element *elem, grpc_channel_element_args *args) { return GRPC_ERROR_NONE; } // Called before destruction. - virtual void Destroy(grpc_exec_ctx *exec_ctx, grpc_channel_element *elem) {} + virtual void Destroy(grpc_channel_element *elem) {} - virtual void StartTransportOp(grpc_exec_ctx *exec_ctx, - grpc_channel_element *elem, TransportOp *op); + virtual void StartTransportOp(grpc_channel_element *elem, TransportOp *op); - virtual void GetInfo(grpc_exec_ctx *exec_ctx, grpc_channel_element *elem, + virtual void GetInfo(grpc_channel_element *elem, const grpc_channel_info *channel_info); }; @@ -249,24 +247,22 @@ class CallData { // TODO(roth): Come up with a more C++-like API for the call element. /// Initializes the call data. - virtual grpc_error *Init(grpc_exec_ctx *exec_ctx, grpc_call_element *elem, + virtual grpc_error *Init(grpc_call_element *elem, const grpc_call_element_args *args) { return GRPC_ERROR_NONE; } // Called before destruction. - virtual void Destroy(grpc_exec_ctx *exec_ctx, grpc_call_element *elem, + virtual void Destroy(grpc_call_element *elem, const grpc_call_final_info *final_info, grpc_closure *then_call_closure) {} /// Starts a new stream operation. - virtual void StartTransportStreamOpBatch(grpc_exec_ctx *exec_ctx, - grpc_call_element *elem, + virtual void StartTransportStreamOpBatch(grpc_call_element *elem, TransportStreamOpBatch *op); /// Sets a pollset or pollset set. - virtual void SetPollsetOrPollsetSet(grpc_exec_ctx *exec_ctx, - grpc_call_element *elem, + virtual void SetPollsetOrPollsetSet(grpc_call_element *elem, grpc_polling_entity *pollent); }; @@ -280,71 +276,63 @@ class ChannelFilter final { public: static const size_t channel_data_size = sizeof(ChannelDataType); - static grpc_error *InitChannelElement(grpc_exec_ctx *exec_ctx, - grpc_channel_element *elem, + static grpc_error *InitChannelElement(grpc_channel_element *elem, grpc_channel_element_args *args) { // Construct the object in the already-allocated memory. ChannelDataType *channel_data = new (elem->channel_data) ChannelDataType(); - return channel_data->Init(exec_ctx, elem, args); + return channel_data->Init(elem, args); } - static void DestroyChannelElement(grpc_exec_ctx *exec_ctx, - grpc_channel_element *elem) { + static void DestroyChannelElement(grpc_channel_element *elem) { ChannelDataType *channel_data = reinterpret_cast<ChannelDataType *>(elem->channel_data); - channel_data->Destroy(exec_ctx, elem); + channel_data->Destroy(elem); channel_data->~ChannelDataType(); } - static void StartTransportOp(grpc_exec_ctx *exec_ctx, - grpc_channel_element *elem, + static void StartTransportOp(grpc_channel_element *elem, grpc_transport_op *op) { ChannelDataType *channel_data = reinterpret_cast<ChannelDataType *>(elem->channel_data); TransportOp op_wrapper(op); - channel_data->StartTransportOp(exec_ctx, elem, &op_wrapper); + channel_data->StartTransportOp(elem, &op_wrapper); } - static void GetChannelInfo(grpc_exec_ctx *exec_ctx, - grpc_channel_element *elem, + static void GetChannelInfo(grpc_channel_element *elem, const grpc_channel_info *channel_info) { ChannelDataType *channel_data = reinterpret_cast<ChannelDataType *>(elem->channel_data); - channel_data->GetInfo(exec_ctx, elem, channel_info); + channel_data->GetInfo(elem, channel_info); } static const size_t call_data_size = sizeof(CallDataType); - static grpc_error *InitCallElement(grpc_exec_ctx *exec_ctx, - grpc_call_element *elem, + static grpc_error *InitCallElement(grpc_call_element *elem, const grpc_call_element_args *args) { // Construct the object in the already-allocated memory. CallDataType *call_data = new (elem->call_data) CallDataType(); - return call_data->Init(exec_ctx, elem, args); + return call_data->Init(elem, args); } - static void DestroyCallElement(grpc_exec_ctx *exec_ctx, - grpc_call_element *elem, + static void DestroyCallElement(grpc_call_element *elem, const grpc_call_final_info *final_info, grpc_closure *then_call_closure) { CallDataType *call_data = reinterpret_cast<CallDataType *>(elem->call_data); - call_data->Destroy(exec_ctx, elem, final_info, then_call_closure); + call_data->Destroy(elem, final_info, then_call_closure); call_data->~CallDataType(); } - static void StartTransportStreamOpBatch(grpc_exec_ctx *exec_ctx, - grpc_call_element *elem, + static void StartTransportStreamOpBatch(grpc_call_element *elem, grpc_transport_stream_op_batch *op) { CallDataType *call_data = reinterpret_cast<CallDataType *>(elem->call_data); TransportStreamOpBatch op_wrapper(op); - call_data->StartTransportStreamOpBatch(exec_ctx, elem, &op_wrapper); + call_data->StartTransportStreamOpBatch(elem, &op_wrapper); } - static void SetPollsetOrPollsetSet(grpc_exec_ctx *exec_ctx, - grpc_call_element *elem, + static void SetPollsetOrPollsetSet(grpc_call_element *elem, grpc_polling_entity *pollent) { CallDataType *call_data = reinterpret_cast<CallDataType *>(elem->call_data); - call_data->SetPollsetOrPollsetSet(exec_ctx, elem, pollent); + call_data->SetPollsetOrPollsetSet(elem, pollent); } }; |