bcb4e51a409d94ae670de96afb8483a4f7855294Stephan Bosch/* Copyright (c) 2004-2018 Dovecot authors, see the included COPYING file */
b3e4b3e7585f644a4d95293ca7bca19bcbf70c50Timo Sirainen struct sql_db *prev, *next; /* These are set while refcount=0 */
b3e4b3e7585f644a4d95293ca7bca19bcbf70c50Timo Sirainen unsigned int unused_count, max_unused_connections;
b3e4b3e7585f644a4d95293ca7bca19bcbf70c50Timo Sirainenstatic MODULE_CONTEXT_DEFINE_INIT(sql_db_cache_module, &sql_db_module_register);
b3e4b3e7585f644a4d95293ca7bca19bcbf70c50Timo Sirainenstatic void sql_db_cache_db_deinit(struct sql_db *db)
b3e4b3e7585f644a4d95293ca7bca19bcbf70c50Timo Sirainen struct sql_db_cache_context *ctx = SQL_DB_CACHE_CONTEXT(db);
b3e4b3e7585f644a4d95293ca7bca19bcbf70c50Timo Sirainen head_ctx = SQL_DB_CACHE_CONTEXT(ctx->cache->unused_head);
b3e4b3e7585f644a4d95293ca7bca19bcbf70c50Timo Sirainenstatic void sql_db_cache_unlink(struct sql_db_cache_context *ctx)
b3e4b3e7585f644a4d95293ca7bca19bcbf70c50Timo Sirainen struct sql_db_cache_context *prev_ctx, *next_ctx;
51bfd4fbaf2b2148f8229f6a1650f28b61794effTimo Sirainenstatic void sql_db_cache_free_tail(struct sql_db_cache *cache)
51bfd4fbaf2b2148f8229f6a1650f28b61794effTimo Sirainenstatic void sql_db_cache_drop_oldest(struct sql_db_cache *cache)
51bfd4fbaf2b2148f8229f6a1650f28b61794effTimo Sirainen while (cache->unused_count >= cache->max_unused_connections)
b3e4b3e7585f644a4d95293ca7bca19bcbf70c50Timo Sirainen const char *db_driver, const char *connect_string)
b3e4b3e7585f644a4d95293ca7bca19bcbf70c50Timo Sirainen key = i_strdup_printf("%s\t%s", db_driver, connect_string);
b3e4b3e7585f644a4d95293ca7bca19bcbf70c50Timo Sirainen MODULE_CONTEXT_SET(db, sql_db_cache_module, ctx);
b3e4b3e7585f644a4d95293ca7bca19bcbf70c50Timo Sirainenstruct sql_db_cache *sql_db_cache_init(unsigned int max_unused_connections)
678d0463849ba777106eb7875f27db07a5d8e3dfTimo Sirainen hash_table_create(&cache->dbs, default_pool, 0, str_hash, strcmp);
b3e4b3e7585f644a4d95293ca7bca19bcbf70c50Timo Sirainen cache->max_unused_connections = max_unused_connections;