Skip to content

Commit 3ef299b

Browse files
committed
final pass of the code
1 parent 4a9d506 commit 3ef299b

2 files changed

Lines changed: 23 additions & 18 deletions

File tree

include/aws/http/private/http2_stream_manager_impl.h

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,10 @@ struct aws_h2_sm_connection {
4444

4545
enum aws_h2_sm_connection_state_type state;
4646

47-
/* Node for tracking in the sm_connections list */
47+
/**
48+
* Node for tracking in the all_held_connections list,
49+
* NOTE: lock required to alter the state of the list.
50+
*/
4851
struct aws_linked_list_node node;
4952
};
5053

@@ -140,21 +143,21 @@ struct aws_http2_stream_manager {
140143
enum aws_h2_sm_state_type state;
141144

142145
/**
143-
* A set of all connections that meet all requirement to use. Don't own the connection.
146+
* A set of all connections that meet all requirement to use. Doesn't own the connection.
144147
*
145148
* Note: there will be connections not in this set, but hold by the stream manager, which can be tracked by the
146-
* streams created on it. Set of `struct aws_h2_sm_connection *`
149+
* all_held_connections. Set of `struct aws_h2_sm_connection *`
147150
*/
148151
struct aws_random_access_set ideal_available_set;
149152
/**
150-
* A set of all available connections that exceed the soft limits set by users. . Don't own the connection.
153+
* A set of all available connections that exceed the soft limits set by users. Doesn't own the connection.
151154
*
152155
* Note: there will be connections not in this set, but hold by the stream manager, which can be tracked by the
153-
* streams created. Set of `struct aws_h2_sm_connection *`
156+
* all_held_connections. Set of `struct aws_h2_sm_connection *`
154157
*/
155158
struct aws_random_access_set nonideal_available_set;
156-
/* We don't mantain set for connections that is full or "dead" (Cannot make any new streams). We have streams
157-
* opening from the connection tracking them */
159+
/* We don't mantain set for connections that is full or "dead" (Cannot make any new streams). We have
160+
* all_held_connections tracking them */
158161

159162
/**
160163
* The set of all incomplete stream acquisition requests (haven't decide what connection to make the request
@@ -168,7 +171,7 @@ struct aws_http2_stream_manager {
168171
* it back.
169172
* list of `struct aws_h2_sm_connection*`
170173
*/
171-
struct aws_linked_list sm_connections;
174+
struct aws_linked_list all_held_connections;
172175

173176
/**
174177
* The number of connections acquired from connection manager and not released yet.

source/http2_stream_manager.c

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -589,9 +589,10 @@ static void s_sm_connection_release_connection(struct aws_h2_sm_connection *sm_c
589589
AWS_ASSERT(aws_channel_thread_is_callers_thread(aws_http_connection_get_channel(sm_connection->connection)));
590590

591591
s_lock_synced_data(sm_connection->stream_manager);
592-
/* Remove this connection from the connection tracking list */
592+
/* Remove this connection from the connection tracking list within the lock as altering the list in synced_data. */
593593
aws_linked_list_remove(&sm_connection->node);
594594
s_unlock_synced_data(sm_connection->stream_manager);
595+
595596
int error = aws_http_connection_manager_release_connection(
596597
sm_connection->stream_manager->connection_manager, sm_connection->connection);
597598
AWS_ASSERT(!error);
@@ -669,8 +670,8 @@ static void s_sm_on_connection_acquired(struct aws_http_connection *connection,
669670
should_release_connection = true;
670671
} else {
671672
struct aws_h2_sm_connection *sm_connection = s_sm_connection_new(stream_manager, connection);
672-
/* Add this connection to the sm_connections tracking list */
673-
aws_linked_list_push_back(&stream_manager->synced_data.sm_connections, &sm_connection->node);
673+
/* Add this connection to the all_held_connections tracking list */
674+
aws_linked_list_push_back(&stream_manager->synced_data.all_held_connections, &sm_connection->node);
674675
bool added = false;
675676
re_error |=
676677
aws_random_access_set_add(&stream_manager->synced_data.ideal_available_set, sm_connection, &added);
@@ -1087,8 +1088,12 @@ static void s_stream_manager_start_destroy(void *user_data) {
10871088
AWS_ASSERT(stream_manager->synced_data.internal_refcount_stats[AWS_SMCT_PENDING_ACQUISITION] == 0);
10881089

10891090
/* Iterate through all connections and clean up any that remain */
1090-
struct aws_linked_list_node *node = aws_linked_list_begin(&stream_manager->synced_data.sm_connections);
1091-
const struct aws_linked_list_node *end_node = aws_linked_list_end(&stream_manager->synced_data.sm_connections);
1091+
struct aws_linked_list_node *node = aws_linked_list_begin(&stream_manager->synced_data.all_held_connections);
1092+
1093+
/* No lock needed when stream manager started destroying process. Since there should have no other threads still
1094+
* working. */
1095+
const struct aws_linked_list_node *end_node =
1096+
aws_linked_list_end(&stream_manager->synced_data.all_held_connections);
10921097
while (node != end_node) {
10931098
struct aws_h2_sm_connection *sm_connection = AWS_CONTAINER_OF(node, struct aws_h2_sm_connection, node);
10941099
/* Move to next node before potentially destroying current connection */
@@ -1104,16 +1109,13 @@ static void s_stream_manager_start_destroy(void *user_data) {
11041109
--stream_manager->synced_data.holding_connections_count;
11051110
}
11061111

1107-
s_lock_synced_data(sm_connection->stream_manager);
11081112
/* Remove this connection from the connection tracking list */
11091113
aws_linked_list_remove(&sm_connection->node);
1110-
s_unlock_synced_data(sm_connection->stream_manager);
1111-
11121114
aws_ref_count_release(&sm_connection->ref_count);
11131115
}
11141116

11151117
/* All connections should be cleaned up now */
1116-
AWS_ASSERT(aws_linked_list_empty(&stream_manager->synced_data.sm_connections));
1118+
AWS_ASSERT(aws_linked_list_empty(&stream_manager->synced_data.all_held_connections));
11171119
AWS_ASSERT(stream_manager->synced_data.holding_connections_count == 0);
11181120

11191121
AWS_ASSERT(stream_manager->connection_manager);
@@ -1160,7 +1162,7 @@ struct aws_http2_stream_manager *aws_http2_stream_manager_new(
11601162
aws_mem_calloc(allocator, 1, sizeof(struct aws_http2_stream_manager));
11611163
stream_manager->allocator = allocator;
11621164
aws_linked_list_init(&stream_manager->synced_data.pending_stream_acquisitions);
1163-
aws_linked_list_init(&stream_manager->synced_data.sm_connections);
1165+
aws_linked_list_init(&stream_manager->synced_data.all_held_connections);
11641166

11651167
if (aws_mutex_init(&stream_manager->synced_data.lock)) {
11661168
goto on_error;

0 commit comments

Comments
 (0)