From: Hwankyu Jhun Date: Fri, 7 Apr 2017 10:26:21 +0000 (+0900) Subject: Add widget db busy handler X-Git-Tag: submit/tizen/20170512.073248~3 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=399bb558eccfca384363db84fcdaead7ed859e78;p=platform%2Fcore%2Fappfw%2Fwidget-service.git Add widget db busy handler While some process is writing on the widget db, the widget parser plugin fails query with SQLITE_BUSY error. This patch is to fix this issue. Change-Id: I4ed4782656bf6585c3bf6d7389405e23010dcbd2 Signed-off-by: Hwankyu Jhun --- diff --git a/parser/widget_plugin_parser_internal.c b/parser/widget_plugin_parser_internal.c index dc424eb..0ac5335 100644 --- a/parser/widget_plugin_parser_internal.c +++ b/parser/widget_plugin_parser_internal.c @@ -26,6 +26,9 @@ #include "widget_plugin_parser_internal.h" +#define BUSY_WAITING_USEC 50000 /* 0.05 sec */ +#define BUSY_WAITING_MAX 20 /* wait for max 1 sec */ + void _free_support_size(gpointer data) { struct support_size *size = (struct support_size *)data; @@ -104,6 +107,17 @@ static const char *_get_db_path(uid_t uid) return path; } +static int __db_busy_handler(void *data, int count) +{ + if (count < BUSY_WAITING_MAX) { + usleep(BUSY_WAITING_USEC); + return 1; + } + + /* sqlite3_prepare_v2 will return SQLITE_BUSY */ + return 0; +} + sqlite3 *_open_db(uid_t uid, bool readonly) { int ret; @@ -125,6 +139,14 @@ sqlite3 *_open_db(uid_t uid, bool readonly) return NULL; } + ret = sqlite3_busy_handler(db, __db_busy_handler, NULL); + if (ret != SQLITE_OK) { + LOGE("Failed to register busy handler: %s", + sqlite3_errmsg(db)); + sqlite3_close_v2(db); + return NULL; + } + /* turn on foreign keys */ if (sqlite3_exec(db, "PRAGMA foreign_keys = ON", NULL, NULL, NULL)) { sqlite3_close_v2(db);