Skip to content

Commit

Permalink
Hoist remaining locks after tests of fr_io_client ht (CIDs below)
Browse files Browse the repository at this point in the history
CIDS: 1551706, 1551703, 1551699
  • Loading branch information
jejones3141 committed Jan 22, 2024
1 parent f71b1f6 commit cd65799
Showing 1 changed file with 12 additions and 16 deletions.
28 changes: 12 additions & 16 deletions src/lib/io/master.c
Original file line number Diff line number Diff line change
Expand Up @@ -431,17 +431,17 @@ static int count_connections(UNUSED uint8_t const *key, UNUSED size_t keylen, vo
fr_io_client_t *client = talloc_get_type_abort(data, fr_io_client_t);
int connections;

/*
* This client has no connections, skip the mutex lock.
*/
if (!client->ht) return 0;
pthread_mutex_lock(&client->mutex);

fr_assert(client->use_connected);
if (!client->ht) {
pthread_mutex_unlock(&client->mutex);
return 0;
}

pthread_mutex_lock(&client->mutex);
connections = fr_hash_table_num_elements(client->ht);
pthread_mutex_unlock(&client->mutex);

fr_assert(client->use_connected);
*((uint32_t *) ctx) += connections;

return 0;
Expand Down Expand Up @@ -1993,11 +1993,9 @@ static void client_expiry_timer(fr_event_list_t *el, fr_time_t now, void *uctx)
if (connection) {
fr_io_client_t *parent = connection->parent;

if (parent->ht) {
pthread_mutex_lock(&parent->mutex);
(void) fr_hash_table_delete(parent->ht, connection);
pthread_mutex_unlock(&parent->mutex);
}
pthread_mutex_lock(&parent->mutex);
if (parent->ht) (void) fr_hash_table_delete(parent->ht, connection);
pthread_mutex_unlock(&parent->mutex);

/*
* Mark the connection as dead, and tell
Expand Down Expand Up @@ -2607,11 +2605,9 @@ static int mod_close(fr_listen_t *li)
* Remove connection from parent hash table
*/
parent = connection->parent;
if (parent->ht) {
pthread_mutex_lock(&parent->mutex);
(void) fr_hash_table_delete(parent->ht, connection);
pthread_mutex_unlock(&parent->mutex);
}
pthread_mutex_lock(&parent->mutex);
if (parent->ht) (void) fr_hash_table_delete(parent->ht, connection);
pthread_mutex_unlock(&parent->mutex);

/*
* Clean up listener
Expand Down

0 comments on commit cd65799

Please sign in to comment.