context_list.cc
Go to the documentation of this file.
1 /*
2  *
3  * Copyright 2018 gRPC authors.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  */
18 
20 
22 
23 #include <stdint.h>
24 
26 
27 namespace {
28 void (*write_timestamps_callback_g)(void*, grpc_core::Timestamps*,
29  grpc_error_handle error) = nullptr;
30 void* (*get_copied_context_fn_g)(void*) = nullptr;
31 } // namespace
32 
33 namespace grpc_core {
35  if (get_copied_context_fn_g == nullptr ||
36  write_timestamps_callback_g == nullptr) {
37  return;
38  }
39  /* Create a new element in the list and add it at the front */
40  ContextList* elem = new ContextList();
41  elem->trace_context_ = get_copied_context_fn_g(s->context);
42  elem->byte_offset_ = s->byte_counter;
43  elem->next_ = *head;
44  *head = elem;
45 }
46 
48  ContextList* head = static_cast<ContextList*>(arg);
49  ContextList* to_be_freed;
50  while (head != nullptr) {
51  if (write_timestamps_callback_g) {
52  if (ts) {
53  ts->byte_offset = static_cast<uint32_t>(head->byte_offset_);
54  }
55  write_timestamps_callback_g(head->trace_context_, ts, error);
56  }
57  to_be_freed = head;
58  head = head->next_;
59  delete to_be_freed;
60  }
61 }
62 
64  void (*fn)(void*, Timestamps*, grpc_error_handle error)) {
65  write_timestamps_callback_g = fn;
66 }
67 
69  get_copied_context_fn_g = fn;
70 }
71 } /* namespace grpc_core */
grpc_core::ContextList::trace_context_
void * trace_context_
Definition: context_list.h:44
internal.h
grpc_core
Definition: call_metric_recorder.h:31
elem
Timer elem
Definition: event_engine/iomgr_event_engine/timer_heap_test.cc:109
error
grpc_error_handle error
Definition: retry_filter.cc:499
grpc_core::ContextList::Append
static void Append(ContextList **head, grpc_chttp2_stream *s)
Definition: context_list.cc:34
grpc_core::ContextList
Definition: context_list.h:32
grpc_core::ContextList::Execute
static void Execute(void *arg, Timestamps *ts, grpc_error_handle error)
Definition: context_list.cc:47
grpc_core::Timestamps
Definition: buffer_list.h:90
grpc_core::ContextList::next_
ContextList * next_
Definition: context_list.h:45
grpc_chttp2_stream
Definition: src/core/ext/transport/chttp2/transport/internal.h:456
uint32_t
unsigned int uint32_t
Definition: stdint-msvc2008.h:80
generate-asm-lcov.fn
fn
Definition: generate-asm-lcov.py:146
arg
Definition: cmdline.cc:40
stdint.h
grpc_core::grpc_http2_set_write_timestamps_callback
void grpc_http2_set_write_timestamps_callback(void(*fn)(void *, Timestamps *, grpc_error_handle error))
Definition: context_list.cc:63
grpc_core::Timestamps::byte_offset
uint32_t byte_offset
Definition: buffer_list.h:96
arg
struct arg arg
context_list.h
grpc_core::grpc_http2_set_fn_get_copied_context
void grpc_http2_set_fn_get_copied_context(void *(*fn)(void *))
Definition: context_list.cc:68
grpc_error
Definition: error_internal.h:42
grpc_core::ContextList::byte_offset_
size_t byte_offset_
Definition: context_list.h:46
port_platform.h


grpc
Author(s):
autogenerated on Thu Mar 13 2025 02:58:55