[tracker/libtracker-sparql: 4/5] libtracker-direct: Support multiple direct connection objects
- From: Jürg Billeter <juergbi src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/libtracker-sparql: 4/5] libtracker-direct: Support multiple direct connection objects
- Date: Thu, 19 May 2011 08:24:41 +0000 (UTC)
commit 75dc6627a0443f5c0294b555795e593889587806
Author: Jürg Billeter <j bitron ch>
Date: Thu May 19 09:34:28 2011 +0200
libtracker-direct: Support multiple direct connection objects
If Tracker.Sparql.Connection.get is called after singleton is set to
null in dispose and before backend object is finalized, multiple direct
connection objects may exist at the same time.
The first instance initializes libtracker-data, the last instance shuts
it down.
src/libtracker-direct/tracker-direct.vala | 44 +++++++++++++++++------------
1 files changed, 26 insertions(+), 18 deletions(-)
---
diff --git a/src/libtracker-direct/tracker-direct.vala b/src/libtracker-direct/tracker-direct.vala
index 49808e2..3ad7dce 100644
--- a/src/libtracker-direct/tracker-direct.vala
+++ b/src/libtracker-direct/tracker-direct.vala
@@ -18,35 +18,43 @@
*/
public class Tracker.Direct.Connection : Tracker.Sparql.Connection {
- // only single connection is currently supported per process
- static bool initialized;
+ static int use_count;
public Connection () throws Sparql.Error, IOError, DBusError {
- if (initialized) {
-
- }
+ DBManager.lock ();
- uint select_cache_size = 100;
- string env_cache_size = Environment.get_variable ("TRACKER_SPARQL_CACHE_SIZE");
+ try {
+ if (use_count == 0) {
+ uint select_cache_size = 100;
+ string env_cache_size = Environment.get_variable ("TRACKER_SPARQL_CACHE_SIZE");
- if (env_cache_size != null) {
- select_cache_size = int.parse (env_cache_size);
- }
+ if (env_cache_size != null) {
+ select_cache_size = int.parse (env_cache_size);
+ }
- try {
- Data.Manager.init (DBManagerFlags.READONLY, null, null, false, select_cache_size, 0, null, null);
- } catch (DBInterfaceError e) {
+ Data.Manager.init (DBManagerFlags.READONLY, null, null, false, select_cache_size, 0, null, null);
+ }
+
+ use_count++;
+ } catch (Error e) {
throw new Sparql.Error.INTERNAL (e.message);
+ } finally {
+ DBManager.unlock ();
}
-
- initialized = true;
}
~Connection () {
// Clean up connection
- if (initialized) {
- Data.Manager.shutdown ();
- initialized = false;
+ DBManager.lock ();
+
+ try {
+ use_count--;
+
+ if (use_count == 0) {
+ Data.Manager.shutdown ();
+ }
+ } finally {
+ DBManager.unlock ();
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]