Lines Matching refs:pool

8 #include "worker-pool.h"
28 worker_connection_list_free(struct worker_pool *pool,
34 struct worker_pool *pool;
36 pool = i_new(struct worker_pool, 1);
37 pool->socket_path = i_strdup(socket_path);
38 pool->callback = callback;
39 return pool;
44 struct worker_pool *pool = *_pool;
48 while (pool->busy_list != NULL) {
49 struct worker_connection_list *list = pool->busy_list;
51 DLLIST_REMOVE(&pool->busy_list, list);
52 worker_connection_list_free(pool, list);
55 while (pool->idle_list != NULL) {
56 struct worker_connection_list *list = pool->idle_list;
58 DLLIST_REMOVE(&pool->idle_list, list);
59 worker_connection_list_free(pool, list);
62 i_free(pool->socket_path);
63 i_free(pool);
66 bool worker_pool_have_busy_connections(struct worker_pool *pool)
68 return pool->busy_list != NULL;
71 static int worker_pool_add_connection(struct worker_pool *pool)
76 conn = worker_connection_create(pool->socket_path, pool->callback);
82 i_assert(pool->idle_list == NULL);
87 pool->idle_list = list;
88 pool->connection_count++;
93 worker_connection_list_free(struct worker_pool *pool,
96 i_assert(pool->connection_count > 0);
97 pool->connection_count--;
103 static unsigned int worker_pool_find_max_connections(struct worker_pool *pool)
108 i_assert(pool->idle_list == NULL);
110 if (pool->busy_list == NULL)
113 for (list = pool->busy_list; list != NULL; list = list->next) {
122 bool worker_pool_get_connection(struct worker_pool *pool,
128 while (pool->idle_list != NULL &&
129 !worker_connection_is_connected(pool->idle_list->conn)) {
130 list = pool->idle_list;
131 DLLIST_REMOVE(&pool->idle_list, list);
132 worker_connection_list_free(pool, list);
135 if (pool->idle_list == NULL) {
136 max_connections = worker_pool_find_max_connections(pool);
137 if (pool->connection_count >= max_connections)
139 if (worker_pool_add_connection(pool) < 0)
141 i_assert(pool->idle_list != NULL);
143 list = pool->idle_list;
144 DLLIST_REMOVE(&pool->idle_list, list);
145 DLLIST_PREPEND(&pool->busy_list, list);
151 static void worker_pool_kill_idle_connections(struct worker_pool *pool)
157 for (list = pool->idle_list; list != NULL; list = next) {
160 DLLIST_REMOVE(&pool->idle_list, list);
161 worker_connection_list_free(pool, list);
166 void worker_pool_release_connection(struct worker_pool *pool,
176 for (list = pool->busy_list; list != NULL; list = list->next) {
182 DLLIST_REMOVE(&pool->busy_list, list);
185 worker_connection_list_free(pool, list);
187 DLLIST_PREPEND(&pool->idle_list, list);
190 worker_pool_kill_idle_connections(pool);
195 worker_pool_find_username_connection(struct worker_pool *pool,
201 for (list = pool->busy_list; list != NULL; list = list->next) {