]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
indexer: worker-pool - Use connection_list
authorAki Tuomi <aki.tuomi@open-xchange.com>
Thu, 6 May 2021 07:56:40 +0000 (10:56 +0300)
committerTimo Sirainen <timo.sirainen@open-xchange.com>
Mon, 14 Jun 2021 14:56:40 +0000 (17:56 +0300)
src/indexer/worker-pool.c

index 9c140fb587145f69338d460bd4a57b10dc95c5e0..c102364c673343807ed8c0368774c765b1982664 100644 (file)
@@ -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;
 }