From: Aki Tuomi Date: Thu, 6 May 2021 07:56:40 +0000 (+0300) Subject: indexer: worker-pool - Use connection_list X-Git-Tag: 2.3.16~49 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=57317458ceb68e1e6361933b9d38be27a0296499;p=thirdparty%2Fdovecot%2Fcore.git indexer: worker-pool - Use connection_list --- diff --git a/src/indexer/worker-pool.c b/src/indexer/worker-pool.c index 9c140fb587..c102364c67 100644 --- a/src/indexer/worker-pool.c +++ b/src/indexer/worker-pool.c @@ -3,29 +3,24 @@ #include "lib.h" #include "ioloop.h" #include "llist.h" +#include "connection.h" #include "master-service.h" #include "worker-connection.h" #include "worker-pool.h" #define MAX_WORKER_IDLE_SECS (60*5) -struct worker_connection_list { - struct worker_connection_list *prev, *next; - - struct connection *conn; -}; - struct worker_pool { char *socket_path; indexer_status_callback_t *callback; unsigned int connection_count; - struct worker_connection_list *busy_list; + struct connection_list connection_list; }; static void worker_connection_list_free(struct worker_pool *pool, - struct worker_connection_list *list); + struct connection *list); struct worker_pool * worker_pool_init(const char *socket_path, indexer_status_callback_t *callback) @@ -44,10 +39,10 @@ void worker_pool_deinit(struct worker_pool **_pool) *_pool = NULL; - while (pool->busy_list != NULL) { - struct worker_connection_list *list = pool->busy_list; + while (pool->connection_list.connections != NULL) { + struct connection *list = pool->connection_list.connections; - DLLIST_REMOVE(&pool->busy_list, list); + DLLIST_REMOVE(&pool->connection_list.connections, list); worker_connection_list_free(pool, list); } @@ -57,7 +52,7 @@ void worker_pool_deinit(struct worker_pool **_pool) bool worker_pool_have_busy_connections(struct worker_pool *pool) { - return pool->busy_list != NULL; + return pool->connection_list.connections != NULL; } static int worker_pool_add_connection(struct worker_pool *pool, @@ -78,25 +73,24 @@ static int worker_pool_add_connection(struct worker_pool *pool, static void worker_connection_list_free(struct worker_pool *pool, - struct worker_connection_list *list) + struct connection *list) { i_assert(pool->connection_count > 0); pool->connection_count--; - worker_connection_destroy(&list->conn); - i_free(list); + worker_connection_destroy(&list); } static unsigned int worker_pool_find_max_connections(struct worker_pool *pool) { - struct worker_connection_list *list; + struct connection *list; unsigned int limit; - if (pool->busy_list == NULL) + if (pool->connection_list.connections == NULL) return 1; - for (list = pool->busy_list; list != NULL; list = list->next) { - if (worker_connection_get_process_limit(list->conn, &limit)) + for (list = pool->connection_list.connections; list != NULL; list = list->next) { + if (worker_connection_get_process_limit(list, &limit)) return limit; } /* we have at least one connection that has already been created, @@ -107,7 +101,6 @@ static unsigned int worker_pool_find_max_connections(struct worker_pool *pool) bool worker_pool_get_connection(struct worker_pool *pool, struct connection **conn_r) { - struct worker_connection_list *list; unsigned int max_connections; max_connections = worker_pool_find_max_connections(pool); @@ -115,9 +108,7 @@ bool worker_pool_get_connection(struct worker_pool *pool, return FALSE; if (worker_pool_add_connection(pool, conn_r) < 0) return FALSE; - list = i_new(struct worker_connection_list, 1); - list->conn = *conn_r; - DLLIST_PREPEND(&pool->busy_list, list); + DLLIST_PREPEND(&pool->connection_list.connections, *conn_r); return TRUE; } @@ -125,16 +116,16 @@ bool worker_pool_get_connection(struct worker_pool *pool, void worker_pool_release_connection(struct worker_pool *pool, struct connection *conn) { - struct worker_connection_list *list; + struct connection *list; pool->connection_count--; - for (list = pool->busy_list; list != NULL; list = list->next) { - if (list->conn == conn) + for (list = pool->connection_list.connections; list != NULL; list = list->next) { + if (list == conn) break; } i_assert(list != NULL); - DLLIST_REMOVE(&pool->busy_list, list); + DLLIST_REMOVE(&pool->connection_list.connections, list); worker_connection_destroy(&conn); } @@ -143,13 +134,13 @@ struct connection * worker_pool_find_username_connection(struct worker_pool *pool, const char *username) { - struct worker_connection_list *list; + struct connection *list; const char *worker_user; - for (list = pool->busy_list; list != NULL; list = list->next) { - worker_user = worker_connection_get_username(list->conn); + for (list = pool->connection_list.connections; list != NULL; list = list->next) { + worker_user = worker_connection_get_username(list); if (worker_user != NULL && strcmp(worker_user, username) == 0) - return list->conn; + return list; } return NULL; }