From 98a436bb27ea0b4b764988374017413083a2551a Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Tue, 29 Jun 2010 15:40:55 -0500 Subject: [PATCH] add switch_cache_db_dismiss_db_handle --- src/include/switch_core.h | 4 +++- src/switch_core_sqldb.c | 31 ++++++++++++++++++++++++++----- 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/src/include/switch_core.h b/src/include/switch_core.h index 9db7385cce..86335593c6 100644 --- a/src/include/switch_core.h +++ b/src/include/switch_core.h @@ -2012,7 +2012,8 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_preprocess_session(switch_core_sessio #define CACHE_DB_LEN 256 typedef enum { - CDF_INUSE = (1 << 0) + CDF_INUSE = (1 << 0), + CDF_PRUNE = (1 << 1) } cache_db_flag_t; typedef enum { @@ -2075,6 +2076,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_preprocess_session(switch_core_sessio return type_str; } +SWITCH_DECLARE(void) switch_cache_db_dismiss_db_handle(switch_cache_db_handle_t ** dbh); SWITCH_DECLARE(void) switch_cache_db_release_db_handle(switch_cache_db_handle_t ** dbh); SWITCH_DECLARE(void) switch_cache_db_destroy_db_handle(switch_cache_db_handle_t ** dbh); SWITCH_DECLARE(switch_status_t) _switch_cache_db_get_db_handle(switch_cache_db_handle_t ** dbh, diff --git a/src/switch_core_sqldb.c b/src/switch_core_sqldb.c index 71cfd416a9..2ce23de97f 100644 --- a/src/switch_core_sqldb.c +++ b/src/switch_core_sqldb.c @@ -103,7 +103,7 @@ static void sql_close(time_t prune) diff = (time_t) prune - dbh->last_used; } - if (prune > 0 && diff < SQL_CACHE_TIMEOUT) { + if (prune > 0 && diff < SQL_CACHE_TIMEOUT && !switch_test_flag(dbh, CDF_PRUNE)) { continue; } @@ -161,6 +161,22 @@ SWITCH_DECLARE(void) switch_cache_db_release_db_handle(switch_cache_db_handle_t } +SWITCH_DECLARE(void) switch_cache_db_dismiss_db_handle(switch_cache_db_handle_t ** dbh) +{ + if (dbh && *dbh) { + + if ((*dbh)->type == SCDB_TYPE_CORE_DB) { + switch_set_flag((*dbh), CDF_PRUNE); + } else { + switch_clear_flag((*dbh), CDF_INUSE); + } + + switch_mutex_unlock((*dbh)->mutex); + *dbh = NULL; + } +} + + SWITCH_DECLARE(void) switch_cache_db_destroy_db_handle(switch_cache_db_handle_t ** dbh) { if (dbh && *dbh) { @@ -208,9 +224,13 @@ SWITCH_DECLARE(void) switch_cache_db_detach(void) if ((dbh = (switch_cache_db_handle_t *) val)) { if (switch_mutex_trylock(dbh->mutex) == SWITCH_STATUS_SUCCESS) { if (strstr(dbh->name, thread_str)) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG10, - "Detach cached DB handle %s [%s]\n", thread_str, switch_cache_db_type_name(dbh->type)); - switch_clear_flag(dbh, CDF_INUSE); + if (dbh->type == SCDB_TYPE_CORE_DB) { + switch_set_flag(dbh, CDF_PRUNE); + } else { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG10, + "Detach cached DB handle %s [%s]\n", thread_str, switch_cache_db_type_name(dbh->type)); + switch_clear_flag(dbh, CDF_INUSE); + } } switch_mutex_unlock(dbh->mutex); } @@ -281,7 +301,8 @@ SWITCH_DECLARE(switch_status_t) _switch_cache_db_get_db_handle(switch_cache_db_h if ((new_dbh = (switch_cache_db_handle_t *) val)) { if (hash == new_dbh->hash && !strncasecmp(new_dbh->name, db_str, strlen(db_str)) && - !switch_test_flag(new_dbh, CDF_INUSE) && switch_mutex_trylock(new_dbh->mutex) == SWITCH_STATUS_SUCCESS) { + !switch_test_flag(new_dbh, CDF_INUSE) && !switch_test_flag(new_dbh, CDF_PRUNE) + && switch_mutex_trylock(new_dbh->mutex) == SWITCH_STATUS_SUCCESS) { switch_set_flag(new_dbh, CDF_INUSE); switch_set_string(new_dbh->name, thread_str); new_dbh->hash = switch_ci_hashfunc_default(db_str, &hlen);