[tracker] libtracker-data: Add explicit calls to grab/release an stmt
- From: Carlos Garnacho <carlosg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker] libtracker-data: Add explicit calls to grab/release an stmt
- Date: Sun, 20 Nov 2016 16:08:17 +0000 (UTC)
commit 0d6502a3ea307a0d40c6ffabbf92ddddbd069401
Author: Carlos Garnacho <carlosg gnome org>
Date: Sun Nov 6 14:29:35 2016 +0100
libtracker-data: Add explicit calls to grab/release an stmt
An stmt can just be grabbed once at a time, and will ref both
the stmt and its DB interface for as long as the stmt is grabbed.
After releasing both refs will be dropped (and stmt_is_used set
back to FALSE), so it will be ensured that a database connection
lives as long as there are active cursors grabbing an statement.
src/libtracker-data/tracker-db-interface-sqlite.c | 31 +++++++++++++++-----
1 files changed, 23 insertions(+), 8 deletions(-)
---
diff --git a/src/libtracker-data/tracker-db-interface-sqlite.c
b/src/libtracker-data/tracker-db-interface-sqlite.c
index e6eef85..744cb2d 100644
--- a/src/libtracker-data/tracker-db-interface-sqlite.c
+++ b/src/libtracker-data/tracker-db-interface-sqlite.c
@@ -2392,6 +2392,27 @@ tracker_db_statement_sqlite_new (TrackerDBInterface *db_interface,
return stmt;
}
+static TrackerDBStatement *
+tracker_db_statement_sqlite_grab (TrackerDBStatement *stmt)
+{
+ g_assert (!stmt->stmt_is_used);
+ stmt->stmt_is_used = TRUE;
+ g_object_ref (stmt->db_interface);
+ return g_object_ref (stmt);
+}
+
+static void
+tracker_db_statement_sqlite_release (TrackerDBStatement *stmt)
+{
+ TrackerDBInterface *iface = stmt->db_interface;
+
+ g_assert (stmt->stmt_is_used);
+ stmt->stmt_is_used = FALSE;
+ tracker_db_statement_sqlite_reset (stmt);
+ g_object_unref (stmt);
+ g_object_unref (iface);
+}
+
static void
tracker_db_cursor_close (TrackerDBCursor *cursor)
{
@@ -2408,12 +2429,7 @@ tracker_db_cursor_close (TrackerDBCursor *cursor)
g_atomic_int_add (&iface->n_active_cursors, -1);
tracker_db_interface_lock (iface);
-
- cursor->ref_stmt->stmt_is_used = FALSE;
- tracker_db_statement_sqlite_reset (cursor->ref_stmt);
- g_object_unref (cursor->ref_stmt);
- cursor->ref_stmt = NULL;
-
+ g_clear_pointer (&cursor->ref_stmt, tracker_db_statement_sqlite_release);
tracker_db_interface_unlock (iface);
}
@@ -2538,8 +2554,7 @@ tracker_db_cursor_sqlite_new (TrackerDBStatement *ref_stmt,
cursor->finished = FALSE;
cursor->stmt = ref_stmt->stmt;
- ref_stmt->stmt_is_used = TRUE;
- cursor->ref_stmt = g_object_ref (ref_stmt);
+ cursor->ref_stmt = tracker_db_statement_sqlite_grab (ref_stmt);
if (types) {
gint i;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]