[tracker/tracker-0.10] libtracker-sparql: Use separate thread for sync init if necessary
- From: Martyn James Russell <mr src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/tracker-0.10] libtracker-sparql: Use separate thread for sync init if necessary
- Date: Thu, 7 Apr 2011 13:47:38 +0000 (UTC)
commit 62c9affdb21953d89a739932c5b1847f817a585b
Author: Jürg Billeter <j bitron ch>
Date: Thu Apr 7 12:35:47 2011 +0200
libtracker-sparql: Use separate thread for sync init if necessary
tracker_locale_init must run with the thread-default context set to the
global default context. As pushing a new thread-default context
requires the current thread to be the owner of the passed context, we
cannot always push the global default context as a thread-default
context.
This commit uses a threadpool job in the case that sync initialization
is requestesd with the thread-default context not set to the global
default context.
src/libtracker-sparql-backend/tracker-backend.vala | 29 ++++++++++++++++++-
1 files changed, 27 insertions(+), 2 deletions(-)
---
diff --git a/src/libtracker-sparql-backend/tracker-backend.vala b/src/libtracker-sparql-backend/tracker-backend.vala
index d68b2c6..18bb9a3 100644
--- a/src/libtracker-sparql-backend/tracker-backend.vala
+++ b/src/libtracker-sparql-backend/tracker-backend.vala
@@ -199,7 +199,7 @@ class Tracker.Sparql.Backend : Connection {
static bool log_initialized;
static StaticMutex door;
- public static new Connection get_internal (bool is_direct_only = false, Cancellable? cancellable = null) throws Sparql.Error, IOError, DBusError, SpawnError {
+ static new Connection get (bool is_direct_only = false, Cancellable? cancellable = null) throws Sparql.Error, IOError, DBusError, SpawnError {
door.lock ();
// assign to owned variable to ensure it doesn't get freed between unlock and return
@@ -230,6 +230,31 @@ class Tracker.Sparql.Backend : Connection {
return singleton;
}
+ public static new Connection get_internal (bool is_direct_only = false, Cancellable? cancellable = null) throws Sparql.Error, IOError, DBusError, SpawnError {
+ if (MainContext.get_thread_default () == null) {
+ // ok to initialize without extra thread
+ return get (is_direct_only, cancellable);
+ }
+
+ // run with separate main context to be able to wait for async method
+ var context = new MainContext ();
+ var loop = new MainLoop (context);
+ AsyncResult async_result = null;
+
+ context.push_thread_default ();
+
+ get_internal_async.begin (is_direct_only, cancellable, (obj, res) => {
+ async_result = res;
+ loop.quit ();
+ });
+
+ loop.run ();
+
+ context.pop_thread_default ();
+
+ return get_internal_async.end (async_result);
+ }
+
public async static new Connection get_internal_async (bool is_direct_only = false, Cancellable? cancellable = null) throws Sparql.Error, IOError, DBusError, SpawnError {
// fast path: avoid extra thread if connection is already available
if (door.trylock ()) {
@@ -254,7 +279,7 @@ class Tracker.Sparql.Backend : Connection {
g_io_scheduler_push_job (job => {
try {
- result = get_internal (is_direct_only, cancellable);
+ result = get (is_direct_only, cancellable);
} catch (IOError e_io) {
io_error = e_io;
} catch (Sparql.Error e_spql) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]