stream_lists.cc
Go to the documentation of this file.
1 /*
2  *
3  * Copyright 2015 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 
21 #include <grpc/support/log.h>
22 
27 
29  switch (id) {
31  return "writable";
33  return "writing";
35  return "stalled_by_transport";
37  return "stalled_by_stream";
39  return "waiting_for_concurrency";
40  case STREAM_LIST_COUNT:
41  GPR_UNREACHABLE_CODE(return "unknown");
42  }
43  GPR_UNREACHABLE_CODE(return "unknown");
44 }
45 
46 grpc_core::TraceFlag grpc_trace_http2_stream_state(false, "http2_stream_state");
47 
48 /* core list management */
49 
52  return t->lists[id].head == nullptr;
53 }
54 
58  grpc_chttp2_stream* s = t->lists[id].head;
59  if (s) {
60  grpc_chttp2_stream* new_head = s->links[id].next;
61  GPR_ASSERT(s->included.is_set(id));
62  if (new_head) {
63  t->lists[id].head = new_head;
64  new_head->links[id].prev = nullptr;
65  } else {
66  t->lists[id].head = nullptr;
67  t->lists[id].tail = nullptr;
68  }
69  s->included.clear(id);
70  }
71  *stream = s;
73  gpr_log(GPR_INFO, "%p[%d][%s]: pop from %s", t, s->id,
74  t->is_client ? "cli" : "svr", stream_list_id_string(id));
75  }
76  return s != nullptr;
77 }
78 
81  GPR_ASSERT(s->included.is_set(id));
82  s->included.clear(id);
83  if (s->links[id].prev) {
84  s->links[id].prev->links[id].next = s->links[id].next;
85  } else {
86  GPR_ASSERT(t->lists[id].head == s);
87  t->lists[id].head = s->links[id].next;
88  }
89  if (s->links[id].next) {
90  s->links[id].next->links[id].prev = s->links[id].prev;
91  } else {
92  t->lists[id].tail = s->links[id].prev;
93  }
95  gpr_log(GPR_INFO, "%p[%d][%s]: remove from %s", t, s->id,
96  t->is_client ? "cli" : "svr", stream_list_id_string(id));
97  }
98 }
99 
103  if (s->included.is_set(id)) {
104  stream_list_remove(t, s, id);
105  return true;
106  } else {
107  return false;
108  }
109 }
110 
114  grpc_chttp2_stream* old_tail;
115  GPR_ASSERT(!s->included.is_set(id));
116  old_tail = t->lists[id].tail;
117  s->links[id].next = nullptr;
118  s->links[id].prev = old_tail;
119  if (old_tail) {
120  old_tail->links[id].next = s;
121  } else {
122  t->lists[id].head = s;
123  }
124  t->lists[id].tail = s;
125  s->included.set(id);
127  gpr_log(GPR_INFO, "%p[%d][%s]: add to %s", t, s->id,
128  t->is_client ? "cli" : "svr", stream_list_id_string(id));
129  }
130 }
131 
134  if (s->included.is_set(id)) {
135  return false;
136  }
137  stream_list_add_tail(t, s, id);
138  return true;
139 }
140 
141 /* wrappers for specializations */
142 
144  grpc_chttp2_stream* s) {
145  GPR_ASSERT(s->id != 0);
147 }
148 
150  grpc_chttp2_stream** s) {
152 }
153 
155  grpc_chttp2_stream* s) {
157 }
158 
160  grpc_chttp2_stream* s) {
162 }
163 
166 }
167 
169  grpc_chttp2_stream** s) {
171 }
172 
174  grpc_chttp2_stream* s) {
176 }
177 
179  grpc_chttp2_stream** s) {
181 }
182 
184  grpc_chttp2_stream* s) {
186 }
187 
189  grpc_chttp2_stream* s) {
191 }
192 
194  grpc_chttp2_stream** s) {
196 }
197 
199  grpc_chttp2_stream* s) {
201 }
202 
204  grpc_chttp2_stream* s) {
206 }
207 
209  grpc_chttp2_stream** s) {
211 }
212 
214  grpc_chttp2_stream* s) {
216 }
trace.h
GPR_INFO
#define GPR_INFO
Definition: include/grpc/impl/codegen/log.h:56
grpc_chttp2_list_add_writable_stream
bool grpc_chttp2_list_add_writable_stream(grpc_chttp2_transport *t, grpc_chttp2_stream *s)
Definition: stream_lists.cc:143
grpc_chttp2_list_pop_writing_stream
bool grpc_chttp2_list_pop_writing_stream(grpc_chttp2_transport *t, grpc_chttp2_stream **s)
Definition: stream_lists.cc:168
log.h
internal.h
grpc_chttp2_stream_list_id
grpc_chttp2_stream_list_id
Definition: src/core/ext/transport/chttp2/transport/internal.h:74
grpc_chttp2_list_remove_waiting_for_concurrency
void grpc_chttp2_list_remove_waiting_for_concurrency(grpc_chttp2_transport *t, grpc_chttp2_stream *s)
Definition: stream_lists.cc:183
GRPC_CHTTP2_LIST_STALLED_BY_TRANSPORT
@ GRPC_CHTTP2_LIST_STALLED_BY_TRANSPORT
Definition: src/core/ext/transport/chttp2/transport/internal.h:81
stream_list_add
static bool stream_list_add(grpc_chttp2_transport *t, grpc_chttp2_stream *s, grpc_chttp2_stream_list_id id)
Definition: stream_lists.cc:132
stream_list_pop
static bool stream_list_pop(grpc_chttp2_transport *t, grpc_chttp2_stream **stream, grpc_chttp2_stream_list_id id)
Definition: stream_lists.cc:55
GRPC_TRACE_FLAG_ENABLED
#define GRPC_TRACE_FLAG_ENABLED(f)
Definition: debug/trace.h:114
grpc_chttp2_stream
Definition: src/core/ext/transport/chttp2/transport/internal.h:456
grpc_chttp2_list_remove_writable_stream
bool grpc_chttp2_list_remove_writable_stream(grpc_chttp2_transport *t, grpc_chttp2_stream *s)
Definition: stream_lists.cc:154
stream_list_remove
static void stream_list_remove(grpc_chttp2_transport *t, grpc_chttp2_stream *s, grpc_chttp2_stream_list_id id)
Definition: stream_lists.cc:79
grpc_chttp2_list_remove_stalled_by_stream
bool grpc_chttp2_list_remove_stalled_by_stream(grpc_chttp2_transport *t, grpc_chttp2_stream *s)
Definition: stream_lists.cc:213
GPR_ASSERT
#define GPR_ASSERT(x)
Definition: include/grpc/impl/codegen/log.h:94
grpc_chttp2_list_pop_stalled_by_transport
bool grpc_chttp2_list_pop_stalled_by_transport(grpc_chttp2_transport *t, grpc_chttp2_stream **s)
Definition: stream_lists.cc:193
gpr_log
GPRAPI void gpr_log(const char *file, int line, gpr_log_severity severity, const char *format,...) GPR_PRINT_FORMAT_CHECK(4
grpc_chttp2_list_have_writing_streams
bool grpc_chttp2_list_have_writing_streams(grpc_chttp2_transport *t)
Definition: stream_lists.cc:164
grpc_trace_http2_stream_state
grpc_core::TraceFlag grpc_trace_http2_stream_state(false, "http2_stream_state")
grpc_chttp2_list_add_waiting_for_concurrency
void grpc_chttp2_list_add_waiting_for_concurrency(grpc_chttp2_transport *t, grpc_chttp2_stream *s)
Definition: stream_lists.cc:173
stream_list_empty
static bool stream_list_empty(grpc_chttp2_transport *t, grpc_chttp2_stream_list_id id)
Definition: stream_lists.cc:50
grpc_chttp2_stream::links
grpc_chttp2_stream_link links[STREAM_LIST_COUNT]
Definition: src/core/ext/transport/chttp2/transport/internal.h:474
GPR_UNREACHABLE_CODE
#define GPR_UNREACHABLE_CODE(STATEMENT)
Definition: impl/codegen/port_platform.h:652
stream_list_id_string
static const char * stream_list_id_string(grpc_chttp2_stream_list_id id)
Definition: stream_lists.cc:28
GRPC_CHTTP2_LIST_WRITING
@ GRPC_CHTTP2_LIST_WRITING
Definition: src/core/ext/transport/chttp2/transport/internal.h:78
grpc_chttp2_list_add_stalled_by_stream
void grpc_chttp2_list_add_stalled_by_stream(grpc_chttp2_transport *t, grpc_chttp2_stream *s)
Definition: stream_lists.cc:203
grpc_chttp2_list_pop_writable_stream
bool grpc_chttp2_list_pop_writable_stream(grpc_chttp2_transport *t, grpc_chttp2_stream **s)
Definition: stream_lists.cc:149
grpc_chttp2_list_add_writing_stream
bool grpc_chttp2_list_add_writing_stream(grpc_chttp2_transport *t, grpc_chttp2_stream *s)
Definition: stream_lists.cc:159
grpc_core::TraceFlag
Definition: debug/trace.h:63
frame.h
grpc_chttp2_list_pop_stalled_by_stream
bool grpc_chttp2_list_pop_stalled_by_stream(grpc_chttp2_transport *t, grpc_chttp2_stream **s)
Definition: stream_lists.cc:208
stream_list_add_tail
static void stream_list_add_tail(grpc_chttp2_transport *t, grpc_chttp2_stream *s, grpc_chttp2_stream_list_id id)
Definition: stream_lists.cc:111
GRPC_CHTTP2_LIST_STALLED_BY_STREAM
@ GRPC_CHTTP2_LIST_STALLED_BY_STREAM
Definition: src/core/ext/transport/chttp2/transport/internal.h:82
grpc_chttp2_transport
Definition: src/core/ext/transport/chttp2/transport/internal.h:238
grpc_chttp2_list_pop_waiting_for_concurrency
bool grpc_chttp2_list_pop_waiting_for_concurrency(grpc_chttp2_transport *t, grpc_chttp2_stream **s)
Definition: stream_lists.cc:178
stream_list_maybe_remove
static bool stream_list_maybe_remove(grpc_chttp2_transport *t, grpc_chttp2_stream *s, grpc_chttp2_stream_list_id id)
Definition: stream_lists.cc:100
GRPC_CHTTP2_LIST_WAITING_FOR_CONCURRENCY
@ GRPC_CHTTP2_LIST_WAITING_FOR_CONCURRENCY
Definition: src/core/ext/transport/chttp2/transport/internal.h:85
grpc_chttp2_list_remove_stalled_by_transport
void grpc_chttp2_list_remove_stalled_by_transport(grpc_chttp2_transport *t, grpc_chttp2_stream *s)
Definition: stream_lists.cc:198
grpc_chttp2_list_add_stalled_by_transport
void grpc_chttp2_list_add_stalled_by_transport(grpc_chttp2_transport *t, grpc_chttp2_stream *s)
Definition: stream_lists.cc:188
STREAM_LIST_COUNT
@ STREAM_LIST_COUNT
Definition: src/core/ext/transport/chttp2/transport/internal.h:86
bitset.h
id
uint32_t id
Definition: flow_control_fuzzer.cc:70
GRPC_CHTTP2_LIST_WRITABLE
@ GRPC_CHTTP2_LIST_WRITABLE
Definition: src/core/ext/transport/chttp2/transport/internal.h:77
port_platform.h
stream
voidpf stream
Definition: bloaty/third_party/zlib/contrib/minizip/ioapi.h:136


grpc
Author(s):
autogenerated on Fri May 16 2025 03:00:20