From b6f7b354f2c4e3c6f434283aff45881ec8933df8 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Tue, 4 Dec 2007 23:03:05 +0000 Subject: [PATCH] add retry on lock to core sql func git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@6505 d0543943-73ff-0310-b7d9-9358b9ac24b2 --- src/switch_core_db.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/switch_core_db.c b/src/switch_core_db.c index 6c5a822f1d..6ecee68c25 100644 --- a/src/switch_core_db.c +++ b/src/switch_core_db.c @@ -79,7 +79,22 @@ SWITCH_DECLARE(const char *) switch_core_db_errmsg(switch_core_db_t *db) SWITCH_DECLARE(int) switch_core_db_exec(switch_core_db_t *db, const char *sql, switch_core_db_callback_func_t callback, void *data, char **errmsg) { - return sqlite3_exec(db, sql, callback, data, errmsg); + int ret; + int sane = 100; + + while(--sane > 0) { + ret = sqlite3_exec(db, sql, callback, data, errmsg); + + if (ret == SQLITE_BUSY || ret == SQLITE_LOCKED) { + switch_safe_free(*errmsg); + switch_yield(1000); + continue; + } else { + break; + } + } + + return ret; } SWITCH_DECLARE(int) switch_core_db_finalize(switch_core_db_stmt_t *pStmt)