Skip to content

Commit

Permalink
upstream: move counters update inside protected section
Browse files Browse the repository at this point in the history
Signed-off-by: Eduardo Silva <[email protected]>
  • Loading branch information
edsiper committed Jan 8, 2021
1 parent 086639c commit 2cc50ba
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/flb_upstream.c
Original file line number Diff line number Diff line change
Expand Up @@ -248,8 +248,6 @@ static int destroy_conn(struct flb_upstream_conn *u_conn)
flb_socket_close(u_conn->fd);
}

u->n_connections--;

if (u->thread_safe == FLB_TRUE) {
pthread_mutex_lock(&u->mutex_lists);
}
Expand All @@ -260,6 +258,8 @@ static int destroy_conn(struct flb_upstream_conn *u_conn)
/* Add node to destroy queue */
mk_list_add(&u_conn->_head, &u->destroy_queue);

u->n_connections--;

if (u->thread_safe == FLB_TRUE) {
pthread_mutex_unlock(&u->mutex_lists);
}
Expand Down Expand Up @@ -327,13 +327,13 @@ static struct flb_upstream_conn *create_conn(struct flb_upstream *u)
/* Link new connection to the busy queue */
mk_list_add(&conn->_head, &u->busy_queue);

/* Increase counter */
u->n_connections++;

if (u->thread_safe == FLB_TRUE) {
pthread_mutex_unlock(&u->mutex_lists);
}

/* Increase counter */
u->n_connections++;

/* Start connection */
ret = flb_io_net_connect(conn, coro);
if (ret == -1) {
Expand Down Expand Up @@ -508,7 +508,7 @@ int flb_upstream_conn_release(struct flb_upstream_conn *conn)
}

mk_list_del(&conn->_head);
mk_list_add(&conn->_head, &conn->u->av_queue);
mk_list_add(&conn->_head, &u->av_queue);

if (u->thread_safe == FLB_TRUE) {
pthread_mutex_unlock(&u->mutex_lists);
Expand Down

0 comments on commit 2cc50ba

Please sign in to comment.